View Single Post
  #13  
Old 12-26-2012, 06:22 AM
Ed999 Ed999 is offline
Senior Member
 
Join Date: Feb 2009
Posts: 115
Ed999 is on a distinguished road
Default

Download from BBC iPlayer - TV Show - Javascript method -- Limelight Stream


The following code is the contents of a .bat batch file for downloading a BBC tv live stream from a LIMELIGHT server.

Copy-and-paste the code into a file called (for example) BBCtv_Live_Limelight.bat

Code:
@echo off

::  *** MediaSelector ID ***
    SET ID=bbc_one_london
::  SET ID=bbc_two_england
::  SET ID=bbc_three
::  SET ID=bbc_four

::  *** Stream Bitrate ***
::  SET bitrate=56
::  SET bitrate=176
::  SET bitrate=396
::  SET bitrate=480
    SET bitrate=796
::  SET bitrate=1500

::  *** Supplier ***
    SET supplier=limelight


::  *** Port ***
    SET port=1935

::  *** RTMPDump v2.4 (RTMPDump v2.1d doesn't work) ***
    SET rtmpdump=C:\\Program Files (x86)\\rtmpdump\\rtmpdump.exe

::  *** SWF File ***
    SET swf=http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf

::  *** File Name ***
    SET currDate=%date:/=-%
    SET currTime=%time::=-%

::  *** Safety Tests ***
    IF EXIST "%temp%\*.bat" DEL "%temp%\*.bat"
    IF EXIST "%temp%\*.htm" DEL "%temp%\*.htm"


::  *** Create a HTML file : LIMELIGHT stream ***

ECHO ^<html^>                                                                                             >> %temp%\temp.htm
ECHO ^<head^>                                                                                             >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO ^<title^>Parse BBC iPlayer XML File - Javascript Method^</title^>                                    >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO ^<!-- Downloading from a BBC iPlayer page --^>                                                       >> %temp%\temp.htm
ECHO ^<!-- This parses the elements in a MediaSelector xml page --^>                                      >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO ^<SCRIPT^>                                                                                           >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO // Target XML file's URL address [MediaSelector URL]                                                 >> %temp%\temp.htm
ECHO var url = "http://www.bbc.co.uk/mediaselector/4/mtis/stream/%ID%";                                   >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO var xmlDoc;                                                                                          >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO window.open('','_self'); // This prevents the browser window prompting before closing                >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO function loadXML()                                                                                   >> %temp%\temp.htm
ECHO {                                                                                                    >> %temp%\temp.htm
ECHO    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");                                                   >> %temp%\temp.htm
ECHO    xmlDoc.async = false;                                                                             >> %temp%\temp.htm
ECHO    xmlDoc.onreadystatechange = readXML;                                                              >> %temp%\temp.htm
ECHO    xmlDoc.load(url);                                                                                 >> %temp%\temp.htm
ECHO }                                                                                                    >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO function readXML()                                                                                   >> %temp%\temp.htm
ECHO {                                                                                                    >> %temp%\temp.htm
ECHO    if ( xmlDoc.readyState==4 ) {                                                                     >> %temp%\temp.htm
ECHO    // This function is called on statechange                                                         >> %temp%\temp.htm
ECHO    // When the state reaches 4, this function reads the xml document                                 >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO    // Create a Text File                                                                             >> %temp%\temp.htm
ECHO    var fso = new ActiveXObject("Scripting.FileSystemObject");                                        >> %temp%\temp.htm
ECHO    var fh  = fso.CreateTextFile("C:\\MediaSelector.bat",true);                                       >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO    // LEVEL 1 TAGS  [Primary tags]                                                                   >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO    // Specify the Level 1 tag to loop through                                                        >> %temp%\temp.htm
ECHO    var a = xmlDoc.getElementsByTagName("media");                                                     >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO    // Loop instruction                                                                               >> %temp%\temp.htm
ECHO    for (i=0;i^<a.length;i++) {                                                                       >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO        // Specify a target element within the Level 1 tag                                            >> %temp%\temp.htm
ECHO        // Specified element must exist in ALL the Level 1 tags                                       >> %temp%\temp.htm
ECHO        element1 = a[i].attributes.getNamedItem("kind").nodeValue; // create array         [Line 50]  >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO        // Conditional Filter                                                                         >> %temp%\temp.htm
ECHO        // Pass only those tags that contain video data                                               >> %temp%\temp.htm
ECHO        if ( element1=="video" ) {                                                                    >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO        // Test value of chosen element                                                               >> %temp%\temp.htm
ECHO        // alert( "Kind = " + element1 );                                                             >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO            // Conditional Filter                                                                     >> %temp%\temp.htm
ECHO            // Pass only the tag that contains the desired bitrate                                    >> %temp%\temp.htm
ECHO            element2 = a[i].attributes.getNamedItem("bitrate").nodeValue; // create array             >> %temp%\temp.htm
ECHO            if ( element2==%bitrate% ) {                                                              >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO            // NOTE: The element "bitrate" can't be used as the primary filter at line 50,            >> %temp%\temp.htm
ECHO            //       because it's an element that does NOT exist in all primary level tags            >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO            // Test value of chosen element                                                           >> %temp%\temp.htm
ECHO            // alert( "Bitrate = " + element2 );                                                      >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm

/Continued below...
Reply With Quote