2008-01-02, 04:15
OK, here's my quick-n-dirty script which takes a programme ID or iPlayer page and works out the RTMP stream URL from it. Designed to be run from the command line, first argument is your programme URL:
I'll port that to Python and get it running on XBMC once I know I can play the URL that comes out the other end. I have nothing which can play or record RTMP (under linux) right now so I don't know if the URLs will just work. I'll dust off my XP machine tomorrow and give Orbit or similar a run in the OS it was designed for
Code:
#!/usr/bin/php
<?php
/*
BBC iPlayer RTMP feed URL generator
Pass URL or programme page, iplayer page or just programme ID, prints out RTMP feed URL.
*/
// e.g. http://www.bbc.co.uk/iplayer/page/item/b008mfcn.shtml
// Media selector base
define( "MS_BASE", "http://www.bbc.co.uk/mediaselector/3/stream/check/iplayer?pid=" );
define( "PLAYER_BASE", "http://www.bbc.co.uk/iplayer/page/item/" );
if( !preg_match( "/([a-z0-9]{8})(\.shtml)?$/", $argv[1], $m ) ) die( "That doesn't look like a valid programme to me\n" );
$pid = $m[1];
// Refer back to the actual page to see if there are multiple versions of the content
echo "Getting iPlayer page at ".PLAYER_BASE.$pid.".shtml...\n";
$page = file_get_contents( PLAYER_BASE.$pid.".shtml" );
if( preg_match( "/pid : '([^']+)',/", $page, $m ) ){
$pid = $m[1];
echo "Set version PID as ".$pid."\n";
}
// Get media selector info
echo "Getting data from ".MS_BASE.$pid."...\n";
$ms_data = file_get_contents( MS_BASE.$pid );
$aVars = array( "token", "identifier", "server" );
// Get all the vars from the media selector XML
foreach( $aVars as $var ){
if( preg_match( "/<".$var.">([^<]+)<\/".$var.">/", $ms_data, $m ) ){
$$var = $m[1];
echo $var.": ".$$var."\n";
}
}
$auth = 'auth=' . $token . '&aifp=v001&slist=' . $identifier;
// Get the ident
/*
echo "Getting IP address from ident info from http://".$server."/fcs/ident...\n";
$ident = file_get_contents( "http://".$server."/fcs/ident" );
echo $ident."\n\n";
if( preg_match( "/<ip>([^<]+)<\/ip>/", $ident, $m ) ){
$ip = $m[1];
echo "IP: ".$ip."\n";
}
*/
// For some reason the above takes ages, and this doesn't seem to vary, so hard code for the moment...
$ip = "217.243.192.45";
// RTMP and port 1935 are defaults of the actual application
$url = "rtmp://".$ip.':1935/ondemand?_fcs_vhost='.$server."&".$auth;
echo "\nStream URL:\n".$url."\n";
?>
I'll port that to Python and get it running on XBMC once I know I can play the URL that comes out the other end. I have nothing which can play or record RTMP (under linux) right now so I don't know if the URLs will just work. I'll dust off my XP machine tomorrow and give Orbit or similar a run in the OS it was designed for