В этом разделе вы можете проголосовать за идеи по открытым проектам. Вы всегда можете предложить свою идею, перейдя на страницу проекта.
<<< НазадСм. главную страницу.
Сценарий, который забирает и парсит dlna контент
$host="192.168.1.31";
$port=32469;
//$controlURL='/X_MS_MediaReceiverRegistrar/9e1becde-4773-ac02-af35-c6f715bf87db/control.xml';
$controlURL='/ContentDirectory/9e1becde-4773-ac02-af35-c6f715bf87db/control.xml';
$ObjectID = "c104054e5a4c8c3c046e"; //GetValue();
$BrowseFlag = "BrowseDirectChildren"; //GetValue();
$Filter = "*"; //GetValue();
$StartingIndex = "0"; //GetValue();
$RequestedCount = "100"; //GetValue();
$SortCriteria = "+dc:title"; //GetValue();
$xml='<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><ObjectID>'.$ObjectID.'</ObjectID><BrowseFlag>'.$BrowseFlag.'</BrowseFlag><Filter>'.$Filter.'</Filter><StartingIndex>'.$StartingIndex.'</StartingIndex><RequestedCount>'.$RequestedCount.'</RequestedCount><SortCriteria>'.$SortCriteria.'</SortCriteria></u:Browse></s:Body></s:Envelope>
';
$asnw=sendpacket($host,$port,$controlURL,'Browse', $xml);
$asnw=substr($asnw,0,strrpos($asnw,'>'));
echo $asnw."<br>";
echo "--------------------------------<br>";
$p = xml_parser_create();
xml_parse_into_struct($p, $asnw, $vals, $index);
xml_parser_free($p);
//print_r($index);
//echo "\nМассив Vals\n";
print_r($vals);
//"Envelope": { "Body": { "BrowseResponse
//echo $vals;
foreach ($vals as $value)
{
// echo "<br>----<br>";
//print_r($value).PHP_EOL;
if (($value[tag]=='ITEM' and $value[type]=='open'))
{echo "<br>this new film<br>";
$filmid=$value[attributes][ID];
$server=$value[attributes][PARENTID];
echo "server:".$server."<br>";
echo "filmid:".$filmid."<br>";
echo "filmname:".$filname."<br>";
echo "creator:".$creator."<br>";
echo "actor:".$actor."<br>";
echo "genre:".$genre."<br>";
echo "albummarturi:".$albummarturi."<br>";
echo "description:".$description."<br>";
echo "longdesc:".$longdesc."<br>";
echo "icon:".$icon."<br>";
echo "class:".$class."<br>";
echo "fn:".$fn."<br>";
echo "br:".$br."<br>";
echo "res:".$res."<br>";
echo "duration:".$duration."<br>";
echo "size:".$size."<br>";
echo "protocol:".$protocol."<br>";
echo "date:".$date."<br>";
if ($fn<>''){
addClassObject('dnla_content',$filmid);
sg($filmid.".filmname",$filname);
sg($filmid.".server",$server);
sg($filmid.".filname",$filname);
sg($filmid.".creator",substr($creator,1));
sg($filmid.".actor",substr($actor,1));
sg($filmid.".genre",substr($genre,1));
sg($filmid.".albummarturi",$albummarturi);
sg($filmid.".description",$description);
sg($filmid.".longdesc",$longdesc);
sg($filmid.".icon",$icon);
sg($filmid.".class",$class);
sg($filmid.".filename",$fn);
sg($filmid.".bitrate",$br);
sg($filmid.".resolution",$res);
sg($filmid.".duration",$duration);
sg($filmid.".size",$size);
sg($filmid.".protocol",$protocol);
sg($filmid.".date",$date);
SQLUpdate('objects', array("ID"=>get_id($filmid), "DESCRIPTION"=>$filname));
}
$server="";
$filmid="";
$filname="";
$creator="";
$actor="";
$genre="";
$albummarturi="";
$description="";
$longdesc="";
$icon="";
$class="";
$fn="";
$br="";
$res="";
$duration="";
$size="";
$protocol="";
$date="";
}
if ($value[tag]=='DC:CREATOR') { $creator.=','.$value[value];}
if ($value[tag]=='UPNP:GENRE') { $genre.=','.$value[value];}
if ($value[tag]=='DC:TITLE') { $filname=$value[value]; }
if ($value[tag]=='UPNP:ACTOR') { $actor.=','.$value[value];}
if ($value[tag]=='UPNP:ALBUMARTURI') { $albummarturi.=$value[value];}
if ($value[tag]=='DC:DESCRIPTION') { $description.=$value[value];}
if ($value[tag]=='UPNP:LONGDESCRIPTION') { $longdesc.=$value[value];}
if ($value[tag]=='UPNP:ICON') { $icon.=$value[value];}
if ($value[tag]=='UPNP:CLASS') { $class.=$value[value];}
if ($value[tag]=='DC:DATE') { $date.=$value[value];}
if ($value[tag]=='RES') { $fn=$value[value];
$br=$value[attributes][BITRATE];
$res=$value[attributes][RESOLUTION];
$duration=$value[attributes][DURATION];
$size=$value[attributes][SIZE];
$protocol=$value[attributes][PROTOCOLINFO];
}
echo "<br>value:".$value[value]."<br>";
echo "attributes:".$value[attributes][ID]."<br>";
echo "tag:".$value[tag]."<br>";
echo "type:".$value[type]."<br>";
}
//['s:Envelope']['s:Body']['u:BrowseResponse']['TotalMatches'];
function get_id($prop)
{
$sql='SELECT id FROM objects
WHERE TITLE ="'.$prop.'"';
$rec = SQLSelect($sql);
return $rec[0][id];
}
////////////////////////////////
function sendpacket($host,$port,$AVTransport, $command, $xml){
///browse
$body=$xml;
$headers = 'POST '.$AVTransport.' HTTP/1.1
Soapaction: "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"
CONTENT-TYPE: text/xml; charset="utf-8"
HOST: '.$host.':'.$port;
$content=$headers . '
Content-Length: '. strlen($body) .'
'. $body;
//echo $content;
//echo $host.":". $port;
$fp = fsockopen($host, $port , $errno, $errstr, 10);
if (!$fp)
{echo "Error opening socket: ".$errstr." (".$errno.")<br>";} else
{
$ret = "";
$buffer = "";
// fputs ($fp, $content);
// while (!feof($fp)) {
// $buffer = fgets($fp,128);
// echo "\n;" . $buffer . ";\n";
// $ret.= $buffer;
fwrite($fp, $content);
//while (!feof($fp)) {
//$buffer = fgets($fp,128);
//echo fgets($fp, 128);
//$ret.= $buffer;
//$buffer = stream_get_contents($fp, -1);
fputs ($fp, $content_ContentDirectory_Browse);
$buffer = stream_get_contents($fp, -1);
fclose($fp);
}
// echo $buffer;
$vars = explode("\r\n\r\n", $buffer); //Header abtrennen
// $vars = explode("\r\n", $buffer); //Header abtrennen
$header = $vars[0]; //Header
$message = $vars[1]; //Message
//print_r($vars);
// $handle = fopen('ContentDirectory_Browse.xml', "w"); //XML schreiben
// fwrite($handle, $message);
return $message;
}
class DIDLitem {
protected $node=NULL;
function __construct($node) { $this->node = $node; }
// function album_art($url) { addNodeWithText($this->node, 'upnp:albumArtURI', $url)
// // ->setAttribute('profileID','PNG_TN');
// ->setAttribute('profileID','JPEG_TN');
// return $this;
// }
function icon($url) { addNodeWithText($this->node, 'upnp:icon', $url); return $this; }
function creator($value) { addNodeWithText($this->node, 'dc:creator', $value); return $this; }
function genre($value) { addNodeWithText($this->node, 'upnp:genre', $value); return $this; }
function artist($value, $role=NULL) {
$n = addNodeWithText($this->node, 'upnp:artist', $value);
if ($role!==NULL) $n->setAttribute('role', $role);
return $this; }
function author($value) { addNodeWithText($this->node, 'upnp:author', $value); return $this; }
function album($value) { addNodeWithText($this->node, 'upnp:album', $value); return $this; }
function track($value) { addNodeWithText($this->node, 'upnp:originalTrackNumber', $value); return $this; }
function actor($value) { addNodeWithText($this->node, 'upnp:actor', $value); return $this; }
function director($value) { addNodeWithText($this->node, 'upnp:director', $value); return $this; }
function date($value) { addNodeWithText($this->node, 'dc:date', $value); return $this; }
function searchclass($value) { addNodeWithText($this->node, 'upnp:searchClass', $value)->setAttribute('includeDerived', '1'); return $this; }
function longDescription($value) { addNodeWithText($this->node, 'upnp:longDescription', $value); return $this; }
function description($value) { addNodeWithText($this->node, 'dc:description', $value); return $this; }
function language($value) { addNodeWithText($this->node, 'dc:language', $value); return $this; }
function resource($url, $optattr=array())
{
$optattr = array_merge(array('protocolInfo'=>':::'), $optattr);
$ndRes = $this->node->ownerDocument->createElement('res');
$ndRes->setAttribute('protocolInfo', $optattr['protocolInfo']);
if (array_key_exists('filesize', $optattr)) $ndRes->setAttribute('size', $optattr['filesize']);
if (array_key_exists('duration', $optattr)) $ndRes->setAttribute('duration', $optattr['duration']);
if (array_key_exists('bitrate', $optattr)) $ndRes->setAttribute('bitrate', $optattr['bitrate']);
if (array_key_exists('resolution', $optattr)) $ndRes->setAttribute('resolution', $optattr['resolution']);
// $ndRes->setAttribute('bitrate', ""+(3780)); //kbps
// // $ndRes->setAttribute('sampleFrequency', "48000");
// // $ndRes->setAttribute('nrAudioChannels', "6");
// $ndRes->setAttribute('resolution', "1280x720");
$ndRes_text = $this->node->ownerDocument->createTextNode($url);
$ndRes->appendChild($ndRes_text);
$this->node->appendChild($ndRes);
return $this;
}
}
function parseSimpleXML($xmldata)
{
$childNames = array();
$children = array();
if( $xmldata->count() !== 0 )
{
foreach( $xmldata->children() AS $child )
{
$name = $child->getName();
if( !isset($childNames[$name]) )
{
$childNames[$name] = 0;
}
$childNames[$name]++;
$children[$name][] = $this->parseSimpleXML($child);
}
}
$returndata = new XMLNode();
if( $xmldata->attributes()->count() > 0 )
{
$returndata->{'@attributes'} = new XMLAttribute();
foreach( $xmldata->attributes() AS $name => $attrib )
{
$returndata->{'@attributes'}->{$name} = (string)$attrib;
}
}
if( count($childNames) > 0 )
{
foreach( $childNames AS $name => $count )
{
if( $count === 1 )
{
$returndata->{$name} = $children[$name][0];
}
else
{
$returndata->{$name} = new XMLMultiNode();
$counter = 0;
foreach( $children[$name] AS $data )
{
$returndata->{$name}->{$counter} = $data;
$counter++;
}
}
}
}
else
{
if( (string)$xmldata !== '' )
{
$returndata->{'@innerXML'} = (string)$xmldata;
}
}
return $returndata;
}