Batch file using rtmpdump 1.4 or 1.5 and wget for downloading TV Shows from ABC iView (by sge)
Code:
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
::Change to 1.5 if you have problems
SET RTMPVER=1.4
SET USEPROXY=OFF
::Much better than other methods of downloading though.
::Connects to ABC servers to retrieve a authentication token (which is part of the streams URI)
::Select a channel, then retrieves possible episodes from it.
::Follow the prompts and it should download.
CLS
ECHO.
ECHO ABC iView Downloader by sge
ECHO This script simplifies the process of downloading streams off ABC iView.
ECHO.
ECHO Removing any existing temp files... old authentication tokens... old channel list...
ECHO.
:Start
If exist authenticationtoken.xml del authenticationtoken.xml
If exist channel.xml del channel.xml
SET TOKEN=
SET HOST=
SET ISP=
SET FREE=
SET DOWNLOADER=
SET Choice=
SET DLPATH=
SET TEMPFILENAME=
SET FILENAME=
set LINE=
set LINEOFSHOW=
set SHOW=
set ANSWER=
:RetrieveToken
ECHO.
::No more IP geoblocking now even our friends from overseas can download videos/watch ABC iView. Just enter a proxy in Australia. Uses a Akamai token, but it makes no difference here.
::There isn't much point, but someone will use it.... I bet there is a aussie expat somewhere, that need their fix of Gardening Australia and will thank me :P)
if /i {%USEPROXY%}=={ON} (
ECHO BEWARE OF POTENTIAL PROXY
set http_proxy=114.127.246.36:8080
)
ECHO Using wget to retrieve an XML file from ABC's servers...
ECHO.
::wget.exe -O authenticationtoken.xml http://www2b.abc.net.au/iView/Services/iViewHandshaker.asmx/isp
::Fixed IP.
wget.exe -O authenticationtoken.xml http://202.125.43.119/iview.asmx/isp
ECHO.
ECHO Parsing XML... Retrieving Authentication Token...
for /f "tokens=3 delims=<>" %%a in ('type authenticationtoken.xml ^| find "<token>"') do set TOKEN=%%a
for /f "tokens=3 delims=<>" %%a in ('type authenticationtoken.xml ^| find "<host>"') do set HOST=%%a
for /f "tokens=3 delims=<>" %%a in ('type authenticationtoken.xml ^| find "<isp>"') do set ISP=%%a
for /f "tokens=3 delims=<>" %%a in ('type authenticationtoken.xml ^| find "<free>"') do set FREE=%%a
if /i {%HOST%}=={Akamai} (set DOWNLOADER=alt)
ECHO.
ECHO Authentication token recived from ABC: "%TOKEN%"
ECHO You are using iView host: "%host%" through ISP: "%ISP%"
ECHO.
if /i {%FREE%}=={no} (
ECHO iView is NOT unmetered on your connection. Beware.
)
if /i {%DOWNLOADER%}=={alt} goto :AkamaiToken
IF NOT {%DOWNLOADER%}=={alt} goto :RegularToken
:AkamaiToken
ECHO.
ECHO Your host: %host% uses a different style authentication token.
ECHO You need to do another step.
ECHO.
ECHO Attempting to parse Akamai authentication token...
ECHO.
for /f "usebackq tokens=3 delims=<>" %%a in (`type authenticationtoken.xml ^| find "<token>"`) do echo %%a>token.tmp
for /f "usebackq tokens=1,3 delims=&;" %%a in (`more token.tmp`) do set token=%%a^&%%b
del /q token.tmp
ECHO Parsed authentication token: "%token%"
ECHO.
pause
goto :ChannelPick
:RegularToken
ECHO Your host: "%host%" with authentication: "%TOKEN%" uses the regular downloading command.
ECHO.
pause
goto :ChannelPick
:ChannelPick
CLS
ECHO Which channel do you wish to browse:
ECHO.
ECHO A. Catchup (Recent ABC TV)
ECHO.
ECHO B. News
ECHO.
ECHO C. Arts
ECHO.
ECHO D. Shop (Preview ABC shows)
ECHO.
ECHO E. Docs
ECHO.
ECHO F. The Australia Network (English educational materials)
ECHO.
ECHO G. New Stuff (Recent Kids Shows)
ECHO.
ECHO H. Kazam (Action animation for all ages)
ECHO.
ECHO I. Faves (Great Australian drama series)
ECHO.
ECHO Z. Manually enter path
ECHO.
ECHO.
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
IF /I '%Choice%'=='A' SET URL=http://www.abc.net.au/playback/xml/input/catchup.xml
IF /I '%Choice%'=='B' SET URL=http://www.abc.net.au/playback/xml/input/news.xml
IF /I '%Choice%'=='C' SET URL=http://www.abc.net.au/playback/xml/input/arts.xml
IF /I '%Choice%'=='D' SET URL=http://www.abc.net.au/iview/xml/shop.xml
IF /I '%Choice%'=='E' SET URL=http://www.abc.net.au/playback/xml/input/docs.xml
IF /I '%Choice%'=='F' SET URL=http://www.abc.net.au/playback/xml/input/australianetwork.xml
IF /I '%Choice%'=='G' SET URL=http://www.abc.net.au/playback/xml/input/newstuff.xml
IF /I '%Choice%'=='H' SET URL=http://www.abc.net.au/playback/xml/input/kazam.xml
IF /I '%Choice%'=='I' SET URL=http://www.abc.net.au/playback/xml/input/faves.xml
IF /I '%Choice%'=='Z' GOTO ManualDLPATH
ECHO.
ECHO.
If exist PossibleShowsTEMP del PossibleShowsTEMP
wget.exe -O channel.xml %URL%
ECHO.
ECHO.
ECHO Possible Shows to download are:
ECHO.
::Parsing channel.xml... Echoing shows on screen in format "LINE. SHOW"... Outputting batch friendly show list...
for /f "tokens=3 delims=<>" %%a in ('type channel.xml ^| find "<url>"') do (
set /A LINE=!LINE! + 1
echo !line!. %%a
echo [!LINE!]%%a[/!LINE!] >> PossibleShowsTEMP
)
if /i {%CHOICE%}=={Z} goto :ManualDLPATH
IF NOT {%CHOICE%}=={Z} goto :AutoDLPATH
:ManualDLPATH
ECHO.
ECHO Manually enter download path
ECHO.
ECHO You must get the paths from iView XML (links in the batch file) or from PossibleShowsTEMP
ECHO.
set /p DLPATH=Enter path to download. For Example: catch_up/chaser_09_03_01 (WITHOUT the .flv part):
ECHO.
ECHO You entered: "%DLPATH%"
ECHO.
:ChooseOutput
set /p FILENAME=Enter Filename to Output:
ECHO You typed: "%FILENAME%"
ECHO.
pause
goto :WhichDownloader
:AutoDLPATH
ECHO.
set /p LINEOFSHOW=Which show do you wish to download (Enter number ONLY)
for /f "tokens=2 delims=[]." %%a in ('type PossibleShowsTEMP ^| find "[%LINEOFSHOW%]"') do set DLPATH=%%a
ECHO.
ECHO Episode Found: %DLPATH%
ECHO.
::Gets a filename from the download path
set TEMPFILENAME=%DLPATH%.flv
for /f "tokens=2 delims=/" %%I in ('echo %TEMPFILENAME% ^| find "/"') do (
set FILENAME=%%I
)
ECHO Output Filename: %FILENAME%
ECHO.
pause
:WhichDownloader
if /i {%DOWNLOADER%}=={alt} goto :AlternativeDownloadCommand
IF NOT {%DOWNLOADER%}=={alt} goto :RegularDownloadCommand
:AlternativeDownloadCommand
CLS
ECHO You are using the alternative downloader:
ECHO.
ECHO Ok, you will be requesting "%DLPATH%" using the authentication token "%TOKEN%" from ABC iView servers and saving the stream with the filename "%FILENAME%" using the alternative download command with RTMPdump%RTMPver%.
ECHO.
pause
ECHO.
rtmpdump-WIN32-%RTMPVER%.exe -r rtmp://cp53909.edgefcs.net////flash/playback/_definst_/%DLPATH% -t rtmp://cp53909.edgefcs.net/ondemand?auth="%TOKEN%" -o "%FILENAME%"
goto EndMessage
:RegularDownloadCommand
CLS
ECHO You are using the regular downloader:
ECHO.
ECHO Ok, you will be requesting "%DLPATH%" using the authentication token "%TOKEN%"
ECHO from ABC iView servers and saving the stream with the filename "%FILENAME%"
ECHO Using the regular download command with RTMPdump%RTMPver%.
ECHO.
pause
ECHO.
rtmpdump-WIN32-%RTMPVER%.exe -r rtmp://203.18.195.10/ondemand?auth="%TOKEN%" -y %DLPATH% -o "%FILENAME%"
goto :EndMessage
:EndMessage
ECHO If all went well, "%DLPATH%.flv" should have been downloaded as "%FILENAME%"
ECHO It can be played with VLC
ECHO You must force 16:9 aspect or it looks squished
ECHO.
ECHO If the download didn't begin, try another stream.
ECHO.
SET /P ANSWER=Do you wish to download another file? (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :Start)
if /i {%ANSWER%}=={yes} (goto :Start)
goto :CleanUp
:CleanUp
ECHO.
ECHO Removing temp files...
If exist authenticationtoken.xml del authenticationtoken.xml
If exist channel.xml del channel.xml
ECHO.
ECHO Done! Quitting...
pause
http://forums.whirlpool.net.au/forum-replies.cfm?t=1212283