View Single Post
  #11  
Old 12-26-2012, 06:05 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


Here is a revised script for downloading the Akamai live tv streams from the BBC.

This is a modified version of the batch file script posted above in this thread, modified to take account of recent changes on the BBC website.

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


Code:
@echo off

::  *** Select Channel ***            [ MediaSelector ID ]

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


::  *** Select Bitrate ***            [ MediaSelector Bitrate ]

::  SET bitrate=56
::  SET bitrate=176
::  SET bitrate=396
::  SET bitrate=480
    SET bitrate=796
::  SET bitrate=1500


::  *** Select Supplier ***           [ MediaSelector Supplier ]           !! This script ONLY works for an AKAMAI server !!

    SET supplier=akamai


::  *** Media Selector pages ***

::  http://www.bbc.co.uk/mediaselector/4/mtis/stream/bbc_one_london
::  http://www.bbc.co.uk/mediaselector/4/mtis/stream/bbc_two_england
::  http://www.bbc.co.uk/mediaselector/4/mtis/stream/bbc_three
::  http://www.bbc.co.uk/mediaselector/4/mtis/stream/bbc_four



::  *** 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 : AKAMAI ***

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 within this IF condition                                      >> %temp%\temp.htm
ECHO        // alert( "Video = " + element1 );                                                            >> %temp%\temp.htm
ECHO.                                                                                                     >> %temp%\temp.htm
/Continued below...
Reply With Quote