Task owner: directman, Екатеринбург - Россия
Developer: nick7zmail, Екатеринбург - Россия
Current state:
Successfully done (archive)
Победил!!!!
Сценарий запрос M-SEARCH обновления данных устройств Upnp
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$timeout=2;
$msg = 'M-SEARCH * HTTP/1.1' . "\r\n";
$msg .= 'HOST: 239.255.255.250:1900' . "\r\n";
$msg .= 'MAN: "ssdp:discover"' . "\r\n";
$msg .= "MX: 3\r\n";
$msg .= "ST: upnp:rootdevice\r\n";
$msg .= '' . "\r\n";
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
socket_sendto($socket, $msg, strlen($msg), 0, '239.255.255.250', 1900);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
$response = array();
do {
$buf = null;
@socket_recvfrom($socket, $buf, 1024, MSG_WAITALL, $from, $port);
if (!is_null($buf)) {
//echo $buf."<br>";
$response[] = discoveryReponse2Array($buf);
}
} while (!is_null($buf));
socket_close($socket);
//echo "<br>------------------<br>";
//print_r($response);
//echo "<br>------------------<br>";
//echo "<br>------------------<br>";
foreach ($response as $obj)
{
$LOCATION="";
$usn=$obj[USN];
$CACHECONTROL=$obj['CACHE-CONTROL'];
$DATE=$obj[DATE];
$LOCATION=$obj[LOCATION];
$SERVER=$obj[SERVER];
$ST=$obj[ST];
$NLS=$obj['01-NLS'];
$boot=$obj['BOOTID.UPNP.ORG'];
$conf=$obj['CONFIGID.UPNP.ORG'];
$xuser=$obj['X-USER-AGENT'];
$ext=$obj[EXT];
$opt=$obj[OPT];
$obj=explode (":",$usn);
// print_r($obj);
$objn=$obj[1];
// $objn=$LOCATION;
//echo '<br>$objn:'.$objn.'<br>';
addClassObject('dnla',$objn);
sg($objn.".USN",$usn);
sg($objn.".CACHECONTROL",$CACHECONTROL);
sg($objn.".LOCATION",$LOCATION);
sg($objn.".SERVER",$SERVER);
sg($objn.".NLS",$NLS);
sg($objn.".EXT",$ext);
sg($objn.".OPT",$opt);
sg($objn.".BOOTIDUPNPORG",$boot);
sg($objn.".CONFIGIDUPNPORG",$conf);
sg($objn.".XUSERAGENT",$xuser);
sg($objn.".DATE",$DATE);
sg($objn.".ST",$ST);
sg($objn.".timestamp",time());
//SQLUpdate('objects', array("ID"=>$this->id, "DESCRIPTION"=>$SERVER);
//echo "id:".get_id($objn);
//SQLUpdate('objects', array("ID"=>get_id($objn), "DESCRIPTION"=>$LOCATION));
//if ($prop=='0' ) echo 'name:'.$NAME."<br>";
//скачиваем LOCATION
$url=$LOCATION;
$answ=file_get_contents($url);
sg($objn.".LOCATIONXML",$answ);
// echo $answ."<br>";
//$xml = new SimpleXMLElement($answ);
$xml = new DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->loadXML( $answ );
//print_r($xml);
$books = $xml->getElementsByTagName('friendlyName');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
sg($objn.".friendlyName",$book->nodeValue);
}
$books = $xml->getElementsByTagName('manufacturer');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
sg($objn.".manufacturer",$book->nodeValue);
}
$books = $xml->getElementsByTagName('manufacturerURL');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
sg($objn.".manufacturerURL",$book->nodeValue); }
$books = $xml->getElementsByTagName('manufacturerURL');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
sg($objn.".manufacturerURL",$book->nodeValue); }
$books = $xml->getElementsByTagName('controlURL');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
//sg($objn.".controlURL",substr($LOCATION,0,-1).$book->nodeValue);
sg($objn.".controlURL",$book->nodeValue);
}
$url=gg($objn.".controlURL");
$answ=file_get_contents($url);
sg($objn.".controlURLXML",$answ);
//if (filter_var($url, FILTER_VALIDATE_URL) ) {$answ=file_get_contents($url); sg($objn.".controlURLXML",$answ); }
SQLUpdate('objects', array("ID"=>get_id($objn), "DESCRIPTION"=>gg($objn.".friendlyName")." ".gg($objn.".LOCATION")."\n".$DATE));
echo "<br>";
//foreach ($node as $val)
//{echo $val."<>";}
//$url=gg($objn.".SCPDURL");
//if ($url<>"") {$answ=file_get_contents($url);} else {$answ="";}
//sg($objn.".SCPDURL_XML",$answ);
//$url=gg($objn.".CONTROL_URL");
//if ($url<>"") {$answ=file_get_contents($url);} else {$answ="";}
//sg($objn.".CONTROL_URL_XML",$answ);
//$url=gg($objn.".eventSubURL");
//if ($url<>"") {$answ=file_get_contents($url);} else {$answ="";}
//sg($objn.".eventSubURL_XML",$answ);
echo "**************<br>";
}
//////////////////////////////
//////////////////////////////
//////////////////////////////
//////////////////////////////
function discoveryReponse2Array($res)
{
$result = array();
$lines = explode("\n", trim($res));
if (trim($lines[0]) == 'HTTP/1.1 200 OK') {
array_shift($lines);
}
foreach ($lines as $line) {
$tmp = explode(':', trim($line));
$key = strtoupper(array_shift($tmp));
$value = (count($tmp) > 0 ? trim(join(':', $tmp)) : null);
$result[$key] = $value;
}
// return (Object)$result;
return $result;
}
function get_id($prop)
{
$sql='SELECT id FROM `objects` WHERE TITLE ="'.$prop.'"';
$rec = SQLSelect($sql);
return $rec[0][id];
} [/code][/spoiler]
Сценарий отправки файла на телевизор:
//вызов rs(dnlaplay, array('fn' =>$path);
$fn=$params['fn'];
if ($fn==""){$fn="http://192.168.1.31:32469/object/df4b8e517919aa1f643c/file.mkv";}
$luts=gg("9732d18b-48f1-7f50-2b02-463b0f37e9a7.timestamp");
$diff=(gmdate('i',trim(time()-$luts)));
$pattern = "|\b[0]+([1-9][\d]*)|is";
$diff2= preg_replace($pattern, "\\1", $diff);
echo "Информация была обновлена " .$diff2 . " минут назад.";
if ($diff2>60) { echo "Запускаю обновление данных!"; rs('dnlasearch');}
$url=gg('9732d18b-48f1-7f50-2b02-463b0f37e9a7.LOCATION');
//$host=explode(":",$url)[0].explode(":",$url)[1];
$host=str_replace('/','',explode(":",$url)[1]);
//$host="192.168.1.41";
$port=str_replace('/','',explode(":",$url)[2]);
$controlURL=gg('9732d18b-48f1-7f50-2b02-463b0f37e9a7.controlURL');
echo 'host:'.$host."<br>";
echo 'port:'.$port."<br>";
echo 'controlURL:'.$controlURL."<br>";
//command:
//SetAVTransportURI
//Stop
//Play
//AVTransport
///AVTransport/9732d18b-48f1-7f50-2b02-463b0f37e9a7/control.xml
echo 'Stop<br>';
//Stop
$xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Stop></s:Body></s:Envelope>
';
$asnw=sendpacket($host,$port,$controlURL,'Stop', $xml);
echo $asnw;
echo 'SetAVTransportURI<br>' ;
sleep(1);
//SetAVTransportURI
$xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>http://192.168.1.31:32469/object/df4b8e517919aa1f643c/file.mkv</CurrentURI><CurrentURIMetaData><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" xmlns:sec="http://www.sec.co.kr/" xmlns:pv="http://www.pv.com/pvns/"><item id="df4b8e517919aa1f643c" parentID="c104054e5a4c8c3c046e" restricted="1"><upnp:class>object.item.videoItem</upnp:class><dc:title>Aritmija Web Dl</dc:title><dc:creator>Unknown</dc:creator><upnp:artist>Unknown</upnp:artist><upnp:albumArtURI>http://192.168.1.31:32469/proxy/c9ccea0d9cf75f43c34b/albumart.jpg</upnp:albumArtURI><upnp:genre>Unknown</upnp:genre><res protocolInfo="http-get:*:video/x-matroska:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000" bitrate="692000" nrAudioChannels="6" size="4810724267" resolution="1920x1038" duration="1:55:52.000">'.$fn.'</res></item></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>
';
$asnw=sendpacket($host,$port,$controlURL,'SetAVTransportURI', $xml);
echo $asnw;
echo 'Play<br>';
sleep(1);
//Play
$xml= '<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>
';
$asnw=sendpacket($host,$port,$controlURL,'Play', $xml);
echo $asnw;
function sendpacket($host,$port,$AVTransport, $command, $xml){
///play
$body=$xml;
$headers = 'POST '.$AVTransport.' HTTP/1.1
Soapaction: "urn:schemas-upnp-org:service:AVTransport:1#'.$command.'"
CONTENT-TYPE: text/xml; charset="utf-8"
HOST: '.$host.':'.$port;
$content=$headers . '
Content-Length: '. strlen($body) .'
'. $body;
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;
// }
fclose($fp);
}
// echo "\n\nReturn:" . $ret . "!!\n";
fclose($fp);
return $ret;
}
Телик LG 47LA662 (NETCAST) - подключено в MD! Плюсуйте!
You can help with project improvement by sharing your ideas or by voting for ideas already added.