extremedigital wrote:Hi Parnas, this is exactly the kind of thing i am looking for.
All right, here is the code I've managed to write so far.
This is the proxy script; it's much similar in structure to other proxies you can find in the UMSP plugins directory: I've added support for HTTP redirection (
Location header) and modification of MIME types (
Content-type header). I called it
freeview-proxy.php, since my main purpose was to watch channels from the UK FreeView platform.
- Code: Select all
<?php
$rawURL = $_GET['itemurl'];
$parsedURL = parse_url($rawURL);
$itemHost = $parsedURL['host'];
$itemPath = $parsedURL['path'];
$itemPort = $parsedURL['port'];
_freeviewGet($itemHost, ($itemPath ? $itemPath : "/"), ($itemPort ? $itemPort : 80));
function _freeviewGet($prmHost, $prmPath, $prmPort) {
# print "host: ".$prmHost."\n";
# print "port: ".$prmPort."\n";
# print "path: ".$prmPath."\n";
$fp = fsockopen($prmHost, $prmPort, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET ". $prmPath ." HTTP/1.1" ."\r\n";
$out .= "User-Agent: Wget/1.12 (elf)" ."\r\n";
$out .= "Host: " . $prmHost . "\r\n";
$out .= "Cache-Control: no-cache" ."\r\n";
$out .= "Connection: Close"."\r\n"."\r\n";
fwrite($fp, $out);
$headerpassed = false;
while ($headerpassed == false) {
$line = fgets( $fp);
list($tag, $value) = explode(": ", $line, 2);
if (stristr($tag, 'Location')) {
$target_url = trim($value);
$url_data_string = http_build_query(array('itemurl' => $target_url));
header("Location: http://127.0.0.1/umsp/plugins/freeview-proxy.php?".$url_data_string."\r\n");
continue;
}
if (stristr($tag, 'Content-Type'))
{
if (strstr($value, '/octet-stream'))
header("Content-Type: video/h264"."\r\n");
else header($line);
continue;
}
header($line);
if ($line == "\r\n") {
$headerpassed = true;
}
}
fpassthru($fp);
fclose($fp);
}
}
?>
This is the main plug-in script; it's called
freeview.php and it's very simple: essentially what it does is populate an array of channels to be shown on screen.
- Code: Select all
<?php
function _pluginMain($prmQuery) {
$items = _pluginCreateChannelList();
return $items;
}
function _pluginCreateChannelList() {
$videoItems = array (
'BBC1' => 'http://cctv.ws/7/BBC1',
'BBC2' => 'http://cctv.ws/7/BBC2',
'ITV1' => 'http://cctv.ws/2/ITV1',
'Channel Four' => 'http://cctv.ws/5/ChannelFour',
'Five' => 'http://cctv.ws/0/s3byz/Five',
'BBC3' => 'http://cctv.ws/9/BBC3',
'BBC4' => 'http://cctv.ws/7/CBeebies/BBC4',
'ITV2' => 'http://cctv.ws/0/NhYpi4/ITV2',
'ITV3' => 'http://cctv.ws/0/ITV3',
'ITV4' => 'http://cctv.ws/3/rrU5j/ITV4',
'E4' => 'http://cctv.ws/5/E4Channel',
'More4' => 'http://cctv.ws/3/More4',
'CBS Reality' => 'http://cctv.ws/6/CBSReality',
'4Music' => 'http://cctv.ws/3/4Music',
'Zone Horror' => 'http://cctv.ws/1/ZoneHorror',
'Film4' => 'http://cctv.ws/1/3eZ1R1/Film4',
'Classic Movies2' => 'http://cctv.ws/4/classicmovies2',
'James Bond TV' => 'http://cctv.ws/2/JamesBondTV',
'QVC' => 'http://cctv.ws/2/qvcuk',
'Fashion TV' => 'http://cctv.ws/0/FashionTV',
'ClassicFM TV' => 'http://cctv.ws/6/cfmtv',
'History' => 'http://cctv.ws/9/1wbeA4/History',
'Discovery' => 'http://cctv.ws/9/DiscoveryChannel',
'Movies 1' => 'http://cctv.ws/7/somethingmovies1',
'Movies 2' => 'http://cctv.ws/9/somethingmovies2',
'Movies 3' => 'http://cctv.ws/1/somethingmovies3',
'Movies 4' => 'http://cctv.ws/2/ovies3',
'Eurosport' => 'http://cctv.ws/1/BritishEurosport',
'BBC News24' => 'http://cctv.ws/8/BBCNews',
'Sky News' => 'http://cctv.ws/2/SkyNews',
'BBC Parliament' => 'http://cctv.ws/5/bbcpar',
'Bloomberg TV' => 'http://cctv.ws/6/BloombergUK',
'Russia Today' => 'http://cctv.ws/9/RussiaToday',
'Scuzz' => 'http://cctv.ws/1/Scuzz',
'Flaunt' => 'http://cctv.ws/3/Flaunt',
'France 24' => 'http://cctv.ws/6/France24En',
'BBC1 (LQ)' => 'http://cctv.ws/6/BBC1LQ',
'BBC2 (LQ)' => 'http://cctv.ws/1/BBC2LQ',
'BBC3 (LQ)' => 'http://cctv.ws/5/BBC3lq',
'Channel Four (LQ)' => 'http://cctv.ws/3/C4LQ',
'E4 (LQ)' => 'http://cctv.ws/1/e4lQ',
'Five (LQ)' => 'http://cctv.ws/1/FivelQ',
'ITV1 (LQ)' => 'http://cctv.ws/3/ITV1LQ',
'ITV2 (LQ)' => 'http://cctv.ws/8/TV2lq/ITV2LQ',
'ITV3 (LQ)' => 'http://cctv.ws/4/ITV3LQ',
'CBS Reality (LQ)' => 'http://cctv.ws/4/CBSRealityLQ',
'BBC News24 (LQ)' => 'http://cctv.ws/3/BBCnewsLQ',
'Bloomberg (LQ)' => 'http://cctv.ws/8/BloombergLQ',
'CNN International' => 'http://cctv.ws/7/CNNint',
'CNN International (LQ)' => 'http://cctv.ws/5/xvtmX3/CNNlq',
);
foreach ($videoItems as $name => $url) {
$url_data = array('itemurl' => $url);
$url_data_string = http_build_query($url_data);
$retMediaItems[] = array (
'id' => 'umsp://plugins/freeview?' . $url,
'dc:title' => $name,
'upnp:class' => 'object.item.videoitem',
'res' => 'http://127.0.0.1/umsp/plugins/freeview-proxy.php?'.$url_data_string,
'protocolInfo' => 'http-get:*:*:*',
);
}
return $retMediaItems;
}
?>
Both of these must be put in the
/etc/umsp/plugins directory, that is read-only in the WDLXTV firmware. I get around this limitation using the "mount -o bind" command, to make that path temporarily point to a work area on the
/tmp writable file system.
Of course you also have to add a suitable entry in
/conf/umsp.php:
- Code: Select all
$myMediaItems[] = array(
'id' => 'umsp://plugins/freeview',
'parentID' => '0',
'restricted' => '1',
'dc:title' => 'FreeView UK',
'dc:creator' => 'myCreator',
'dc:date' => '2009-12-30',
'upnp:author' => 'myAuthor',
'upnp:artist' => 'myArtist',
'upnp:album' => 'myAlbum',
'upnp:genre' => 'myGenre',
'upnp:length' => '2:10:20',
'desc' => 'myDesc',
'upnp:class' => 'object.container',
'upnp:album_art'=> '',
'duration' => 'myDur3',
'size' => 'mySize3',
'bitrate' => 'myBitr',
'protocolInfo' => '*:*:*:*',
'resolution' => 'myReso',
'colorDepth' => 'myColor',
);
I've just found out an interesting behavior, anyway: if I stream a channel to a file on the USB storage using
- Code: Select all
wget -O <file>.ts http://xyz/
then I can watch the streaming in almost real-time on the WDTV just reading the file, without using UMSP, and without the infamous initial "3 minutes" delay. So the delay is not caused by the video data itself, but somehow by the way it's served to the WDTV video decoding engine ... I have to experiment a bit more with this.
Hope this is useful!
Greetings, Parnas