This is a method for downloading an iPlayer
TV stream using its MediaSelector url.
Just like a radio show, a tv show/stream has its own unique 8-digit ID number, which is contained in the MediaSelector URL for that stream. It is displayed - amongst other places - on the Playlist xml page associated with the particular stream. That 8-digit ID (identifier) can be used in the javascript code set out below.
See my other posts, above, for further details of the MediaSelector ID and how to find it.
The HTML code, below, is the content for the file
TV_Download.htm (a file which runs Javascript).
All you need do is change the 8-digit ID number highlighted in red for the actual MediaSelector 8-digit ID of the tv show you want to download.
If you alter the sections highlighted in blue, you can download instead a stream running at a different bitrate. Details of the available bitrates for each tv show are given in that show's MediaSelector page. Each tv show is offered by the BBC in half a dozen different bitrates, from 184 kbps to 1500 kbps.
You can also choose either a LIMELIGHT server or an AKAMAI server for some bitrates. There is not much difference in video or audio quality between the two types, at any given bitrate; but there may be a difference in file size.
If you open the .HTML file in Internet Explorer 8 or 9, and allow the javascript to run, it will create a .bat batch file at C:\MediaSelector.bat containing the download command. You then run that batch file to do the actual download. The tv show will, by default, download into your C:\ root directory.
You must copy the program
RTMPDUMP.EXE into the folder "C:\Program Files\rtmpdump" in order for this method to succeed.
Quote:
<html>
<head>
<title>Parse XML file in Internet Explorer</title>
<SCRIPT language="javascript">
// Target XML file's URL address [MediaSelector URL]
var url = "http://www.bbc.co.uk/mediaselector/4/mtis/stream/b01d5nj6";
var xmlDoc;
window.open('','_self'); // This prevents the browser window prompting before closing
function loadxml(){
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.onreadystatechange = readXML;
xmlDoc.load(url);
}
function readXML(){
if ( xmlDoc.readyState==4 ) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\MediaSelector.bat",true);
var a = xmlDoc.getElementsByTagName("media");
for (i=0;i<a.length;i++) {
element1 = a[i].attributes.getNamedItem("kind").nodeValue; // create array
if ( element1=="video" ) {
// Element "bitrate" only exists WITHIN element "video"
element2 = a[i].attributes.getNamedItem("bitrate").nodeValue; // create array
if ( element2==796 ) {
var b = a[i].childNodes;
for (j=0;j<b.length;j++) {
element3 = b[j].attributes.getNamedItem("supplier").nodeValue;
if ( element3=="limelight" ) {
// Write elements in selected Child tag to file
fh.WriteLine( '@echo off' );
fh.WriteLine( ':: Media tag #' + [i] + ', Child tag #' + [j] );
fh.WriteLine( '' );
fh.WriteLine( 'SET rtmpdump=C:\\Program Files\\rtmpdump\\rtmpdump.exe' );
fh.WriteLine( '' );
fh.WriteLine( 'SET server=' + b[j].attributes.getNamedItem("server").nodeValue );
fh.WriteLine( '' );
fh.WriteLine( 'SET application=' + b[j].attributes.getNamedItem("application").nodeValue );
fh.WriteLine( '' );
fh.WriteLine( 'SET identifier=' + b[j].attributes.getNamedItem("identifier").nodeValue );
fh.WriteLine( '' );
var str1 = b[j].attributes.getNamedItem("authString").nodeValue ;
fh.WriteLine( 'SET authString=' + str1.replace(/&/g,"^&") );
fh.WriteLine( '' );
fh.WriteLine( ':: *** Command Line : TV : 796 kbps ***' );
var str2 = b[j].attributes.getNamedItem("identifier").nodeValue ;
var str3 = str2.split("/");
fh.WriteLine( '"%rtmpdump%" --protocol 0 --host "%server%" -a "%application%?%authString%" ' +
'-y "%identifier%" -o "'+element2+'kbps '+element3+' '+str3[4]+'" --resume --timeout 15' );
}
}
}
}
}
}
}
</SCRIPT>
</head>
<body onload="loadxml();window.close();"> </body>
</html>
|