Here is a similar HTML file, the contents of
TV_live.htm, for recording a live tv stream. This needs rtmpdump version 2.4 (at C:\Program Files\RTMPDUMP).
This is valid only for the AKAMAI server (won't work with a LIMELIGHT stream).
It creates a .bat file in C:\ root which must be run to do the actual recording.
Code:
<html>
<head>
<title>Parse BBC iPlayer XML File - Javascript Method</title>
<!-- Downloading from a BBC iPlayer page -->
<!-- This parses the elements in a MediaSelector XML page -->
<SCRIPT>
// Target XML file's URL address [MediaSelector URL]
var url = "http://www.bbc.co.uk/mediaselector/4/mtis/stream/bbc_one_live_rtmp";
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) {
// This function is called on statechange
// When the state reaches 4 this function reads the xml document
// Create a Text File
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\MediaSelector.bat",true);
// LEVEL 1 TAGS [Primary tags]
// Specify the Level 1 tag to loop through
var a = xmlDoc.getElementsByTagName("media");
// Loop instruction
for (i=0;i<a.length;i++) {
// Specify a target element within the Level 1 tag
// Specified element must exist in ALL the Level 1 tags
element1 = a[i].attributes.getNamedItem("kind").nodeValue; // create array [Line 50]
// Conditional Filter
// Pass only those tags that contain video data
if ( element1=="video" ) {
// Conditional Filter [Bitrate]
// Pass only the tag that contains the desired bitrate
element2 = a[i].attributes.getNamedItem("bitrate").nodeValue; // create array
if ( element2==796 ) {
// NOTE: The element "bitrate" can't be used as the primary filter at line 50,
// because it's an element that does NOT exist in all primary level tags
// LEVEL 2 TAGS [Child tags]
// Loop through each Child tag
var b = a[i].childNodes;
// Loop instruction
for (j=0;j<b.length;j++) {
// Specify a target element within the Child tag
// Specified element must exist in ALL the Child tags
element3 = b[j].attributes.getNamedItem("supplier").nodeValue; // create array
// Conditional Filter [Supplier]
// Pass only the Child tag that contains the desired supplier
if ( element3=="akamai" ) {
// Write elements in selected Child tag to file
fh.WriteLine( '@echo off' );
fh.WriteLine( '' );
fh.WriteLine( 'SET rtmpdump=C:\\Program Files\\RTMPDUMP\\rtmpdump.exe' );
fh.WriteLine( '' );
fh.WriteLine( 'SET protocol=' + b[j].attributes.getNamedItem("protocol").nodeValue );
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 : AKAMAI ***' );
fh.WriteLine( '"%rtmpdump%" --live --verbose ' +
'-r "%protocol%://%server%:1935/%application%?%authString%" ' +
'-a "%application%?%authString%" -y "%identifier%?%authString%" ' +
'-W "http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf" ' +
'-o "bbc_one_live_rtmp '+element2+'kbps '+element3+'.flv" ' );
} } // Close Level 2
} } } // Close Level 1
}
}
</SCRIPT>
</head>
<body onload="loadXML();window.close()"> </body>
</html>