Advertisement
HuCann

iviewnapperlitemod

Mar 28th, 2011
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Subroutines for iViewNapperLite.
  2.  
  3. ' Global Variables
  4. dim serImgArray()
  5. dim epTitleArray()
  6. dim epListBoxArray()
  7. dim epDescArray()
  8. dim epVideoAssetArray()
  9. Dim arrSeriesList()
  10. docTitle = "iViewNapperLite 20110320 series"
  11. document.title = docTitle
  12.  
  13. '******************************
  14. '*     PC 20110329
  15. '*     Modification to
  16. '*        1.  Download episodes of series
  17. '*        2.  Auto resume of stored series and partials
  18. '*        3.  Log series/download commands
  19. '*
  20. '******************************
  21. '
  22. '
  23. 'If Changes to servers, look for
  24. ' URL for ABC authentication server
  25. '  URL = "http://tviview.abc.net.au/iview/auth/?v2"
  26. '  Hostworks and Akamai
  27. '      r = " -e -r rtmp://203.18.195.10/"
  28. '      t = " -t rtmp://cp53909.edgefcs.net/ondemand?auth=""" & token & """"
  29. '
  30. '  Version
  31. '  x = "rtmpdump-win32-2.2d.exe"
  32. '
  33. '  Logging commands
  34. '  strFile = ".\lastcmd.cmd"
  35.  
  36.  
  37.  
  38.  
  39.  
  40. ' Runs when window loads
  41. Sub Window_Onload
  42.   ' Resize Window
  43.  x = 784
  44.   y = 564
  45.   window.resizeTo x, y
  46.  
  47.   ' Centre Window
  48.  x = (window.screen.width - x) / 2
  49.   y = (window.screen.height - y) / 2
  50.   If x < 0 Then x = 0
  51.   If y < 0 Then y = 0
  52.   window.moveTo x, y
  53.  
  54. '----------------------------
  55. ' read Series short names into array
  56. '----------------------------
  57. Dim objFSO, objFolder, objShell, objTextFile, objFile
  58. Dim strDirectory, strFile, strText
  59.  
  60. strDirectory = "."
  61. strFile = "\seriesnames.txt"
  62. strText = shortname
  63.  
  64. ' Create the File System Object
  65. Set objFSO = CreateObject("Scripting.FileSystemObject")
  66.  
  67. set objFile = nothing
  68. set objFolder = nothing
  69.  
  70. ' OpenTextFile Method needs a Const value
  71. ' ForAppending = 8 ForReading = 1, ForWriting = 2
  72. Const ForReading = 1
  73.  
  74. Set objTextFile = objFSO.OpenTextFile (strDirectory & strFile, ForReading, True)
  75. sercount = 0
  76. Do Until objTextFile.AtEndOfStream
  77.         strNextLine = objTextFile.Readline
  78.         redim preserve arrSeriesList(sercount)
  79.     arrSeriesList(sercount) = strNextLine
  80.     sercount = sercount + 1
  81. Loop
  82.  
  83. objTextFile.Close
  84.  
  85. '----------------------------
  86.  
  87.  
  88.  
  89.   ' Get A-L JSON file
  90.  j1 = getURL("http://tviview.abc.net.au/iview/api2/?keyword=a-l")
  91.   j1 = left(j1, len(j1) - 1)
  92.  
  93.   ' Get M-Z JSON file
  94.  j2 = getURL("http://tviview.abc.net.au/iview/api2/?keyword=m-z")
  95.   j2 = right(j2, len(j2) - 1)
  96.  
  97.   ' Combine JSON files and Deserialize
  98.  set myJSON = JSON.parse(j1 & "," & j2)
  99.  
  100.   ' Process JSON and Populate Listbox
  101.  num = 0
  102.   for each show in myJSON
  103.     num = num + show.f.length
  104.   next
  105.  
  106.   document.title = docTitle & " json- " & num & " episodes"
  107.  
  108.   ' Populate arrays
  109.  redim serImgArray(num)
  110.   redim epTitleArray(num)
  111.   redim epListBoxArray(num)
  112.   redim epDescArray(num)
  113.   redim epVideoAssetArray(num)
  114.  
  115.  
  116.   ' Process each show
  117.  counter = 0
  118.   for each show in myJSON
  119.     ' Do not add shopdownload episodes
  120.    if not (InStr(lcase(show.e), "shopdownload") > 0) then
  121.       for each episode in show.f
  122.         serImgArray(counter) = show.d
  123.  
  124.         ' Video Asset
  125.        va = episode.n
  126.         epVideoAssetArray(counter) = va
  127.  
  128.         ' Episode Title
  129.         t2 = show.b & " -- " & episode.b
  130.         t2 = Replace(t2, "&amp;", "and")
  131.         t2 = Replace(t2, "/", "-")
  132.         t2 = Replace(t2, ":", " -")
  133.         t2 = Replace(t2, "?", "")
  134.         t2 = Replace(t2, "*", "-")
  135.         t2 = Replace(t2, chr(9), " ")
  136.         t2 = left(t2, 75)
  137.         epTitleArray(counter) = t2
  138.  
  139.     ' find episode title in series array and start download
  140.  
  141.  
  142.  
  143.  
  144.         ' File Size
  145.        sz = ""
  146.         on error resume next
  147.         sz = episode.i
  148.         on error goto 0
  149.         sz = IIf(sz = "", "UNKNOWN", sz + " MB")
  150.  
  151.         ' Duration
  152.         du = "0"
  153.         on error resume next
  154.         du = "0" & cstr(episode.j)
  155.         on error goto 0
  156.         du = cstr(Int(du / 60))
  157.         du = IIf(du = "0", "UNKNOWN", du + " min")
  158.         epListBoxArray(counter) = padright(t2, 75) & padright(padleft(du, 8), 9) & padleft
  159.  
  160. (sz, 8)
  161.  
  162.         ' Short Title
  163.        st = ""
  164.         on error resume next
  165.         st = episode.c
  166.         on error goto 0
  167.         st = Replace(st, "&amp;", "and")
  168.         st = st + IIf(len(st) > 0, " ", "")
  169.  
  170.         ' pubDate
  171.        pd = episode.f
  172.         pd = "(" & split(pd)(0) & ") "
  173.  
  174.         ' Description
  175.        ds = episode.d
  176.         ds = replace(ds, "&lt;", "<")
  177.         ds = replace(ds, "&gt;", ">")
  178.         ds = replace(ds, "&quot;", "'")
  179.         ds = replace(ds, chr(13), "")
  180.         ds = replace(ds, chr(10), "")
  181.         ds = trim(ds)
  182.  
  183.         ex = " [" & UCase(Right(va, 3)) & "] "
  184.         epDescArray(counter) = st & pd & ds & ex
  185.         counter = counter + 1
  186.  
  187.       next
  188.     end if
  189.   next
  190.   counter = counter - 1
  191.   redim preserve serImgArray(counter)
  192.   redim preserve epTitleArray(counter)
  193.   redim preserve epDescArray(counter)
  194.   document.title = docTitle & " sorting- " & counter & " episodes"
  195.  
  196.  
  197.  
  198.   ' Sort arrays alphabetically on episode titles
  199.  for i = UBound(epTitleArray) - 1 To 0 Step -1
  200.     for j = 0 to i
  201.       if epTitleArray(j) > epTitleArray(j + 1) then
  202.         ' Sort serImgArray
  203.        temp = serImgArray(j + 1)
  204.         serImgArray(j + 1) = serImgArray(j)
  205.         serImgArray(j) = temp
  206.         ' Sort epTitleArray
  207.        temp = epTitleArray(j + 1)
  208.         epTitleArray(j + 1) = epTitleArray(j)
  209.         epTitleArray(j) = temp
  210.         ' Sort epListBoxArray
  211.        temp = epListBoxArray(j + 1)
  212.         epListBoxArray(j + 1) = epListBoxArray(j)
  213.         epListBoxArray(j) = temp
  214.         ' Sort epDescArray
  215.        temp=epDescArray(j + 1)
  216.         epDescArray(j + 1) = epDescArray(j)
  217.         epDescArray(j) = temp
  218.         ' Sort epVideoAssetArray
  219.        temp=epVideoAssetArray(j + 1)
  220.         epVideoAssetArray(j + 1) = epVideoAssetArray(j)
  221.         epVideoAssetArray(j) = temp
  222.       end if
  223.     next
  224.   next
  225.  
  226.   document.title = docTitle & " loading - " & counter & " episodes: populating"
  227.  
  228.  ' Select first episode
  229.  document.getElementById("listbox").selectedIndex = 0
  230.   listbox_onclick(0)
  231.  
  232.   ' Populate listbox
  233.  for i = 0 To UBound(epTitleArray) - 1
  234.     dim opt
  235.     set opt = document.createelement("option")
  236.     opt.text = epListBoxArray(i)
  237.     listbox.add opt
  238.     set opt = nothing
  239.  
  240. '----------------------------
  241.    'match and get series
  242. '----------------------------
  243.  ser=InStr(epTitleArray(i),"Series") - 2 'has the word series in title?
  244.  if ser > 0 Then
  245.     For Each Series in arrSeriesList
  246.     if InStr(epTitleArray(i),Series) > 0 Then
  247.         ' select and get episode
  248.         document.getElementById("listbox").selectedIndex = i
  249.         listbox_onclick(0)
  250.         fetchEpisode
  251.     End If
  252.      next
  253.   End IF
  254.   next
  255.  
  256.   ' Select first episode
  257.  document.getElementById("listbox").selectedIndex = 0
  258.   document.getElementById("listbox").scrollTop = 0
  259.   listbox_onclick(0)
  260.  
  261.   document.title = docTitle & " - " & counter & " episodes"
  262.  
  263.  
  264.  
  265. End Sub
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. ' listbox on single click event
  275. Sub listbox_onclick(num)
  276.   if isNumeric(num) then
  277.     document.getElementById("textbox").value = epDescArray(num)
  278.     document.getElementById("picbox").src = serImgArray(num)
  279.   end if
  280. End Sub
  281.  
  282. ' listbox on change event
  283. Sub listbox_onchange
  284.   listbox_onclick(document.getElementById("listbox").selectedIndex)
  285. End Sub
  286.  
  287. ' picbox on double click event
  288. Sub picbox_ondblclick
  289.   fetchEpisode
  290. End Sub
  291.  
  292. ' Clears the listbox box
  293. Sub clear_listbox
  294.   document.getElementById("listbox").options.length = 0
  295. End Sub
  296.  
  297. Sub fetchEpisode
  298.   ' URL for ABC authentication server
  299.  URL = "http://tviview.abc.net.au/iview/auth/?v2"
  300.  
  301.   ' Extract token and other values
  302.  set xmlDoc=CreateObject("Microsoft.XMLDOM")
  303.   xmlDoc.async="false"
  304.   xmlDoc.load(URL)
  305.   token = xmlDoc.documentElement.selectSingleNode("/iview/token").text
  306.   host = xmlDoc.documentElement.selectSingleNode("/iview/host").text
  307.   free = xmlDoc.documentElement.selectSingleNode("/iview/free").text
  308.   set xmlDoc = Nothing
  309.  
  310.   ' Init some content server parameter variables
  311.  num = document.getElementById("listbox").selectedIndex
  312.   show = left(epVideoAssetArray(num), len(epVideoAssetArray(num)) - 4)
  313.   ext = Right(epVideoAssetArray(num), 3)
  314.  
  315.   ' Setup the content server parameters for host
  316.  x = "rtmpdump-win32-2.2d.exe"
  317.   o = " -o " & """" & epTitleArray(num) & "." & ext & """"
  318.   W = " -W ""http://www.abc.net.au/iview/images/iview.jpg"""
  319.   z = ""
  320.   Select Case Ucase(host)
  321.     Case  "HOSTWORKS"
  322.       r = " -e -r rtmp://203.18.195.10/"
  323.       asset = iif(ext="mp4", "&mp4:" & show, "")
  324.       a = " -a ondemand?auth=""" & token  & asset & """"
  325.       show = iif(ext = "mp4", "mp4:", "") & show
  326.       y = " -y " & """" & show & """"
  327.       cmd = x & r & a & y & o & W & z
  328.     Case "AKAMAI"
  329.       show = iif(ext = "mp4", show & "." & ext, show)
  330.       r = " -e -r rtmp://cp53909.edgefcs.net////flash/playback/_definst_/" & show
  331.       t = " -t rtmp://cp53909.edgefcs.net/ondemand?auth=""" & token & """"
  332.       cmd = x & r & t & o & W & z
  333.     Case Else
  334.       msgbox "Content server not listed."
  335.   End Select
  336.  
  337. ' save "in progress" series titles
  338.  ser=InStr(epTitleArray(num),"Series") - 2
  339.   if ser > 0 Then
  340.   'search series array for duplicates
  341.    k = 1
  342.     For Each Series in arrSeriesList
  343.     if InStr(epTitleArray(num),Series) > 0 Then k = 0 'found
  344.    Next
  345.     ' save new series for future
  346.    if k = 1 Then saveSeries(Left(epTitleArray(num),ser))
  347.    
  348.   End  If
  349.  
  350.  
  351.  
  352.   ' Spawn DOS shell and run app
  353.  Set wshShell = CreateObject("WScript.Shell")
  354.  
  355.   saveFetchCmd(cmd)
  356.  
  357.   wshShell.Run cmd
  358.  
  359.   Set wshShell = Nothing
  360.   Set xmlDoc = Nothing
  361. End Sub ' fetch
  362.  
  363.  
  364.  
  365. ' Immediate IF function.
  366. Function iif(tstStr, trueStr, falseStr)
  367.   if tstStr then
  368.     iif = trueStr
  369.   else
  370.     iif = falseStr
  371.   end if
  372. End Function
  373.  
  374. ' Padleft function.
  375. Function padleft(str, num)
  376.   padleft = space(num - len(str)) & str
  377. End Function
  378.  
  379. ' Padright function.
  380. Function padright(str, num)
  381.   padright = str & space(num - len(str))
  382. End Function
  383.  
  384. ' Gets the file from the internet.
  385. Function getURL(URL)
  386.   dim http
  387.   set http = CreateObject("Microsoft.XMLHTTP")
  388.   http.Open "GET", URL, false
  389.   http.Send
  390.   getURL = http.ResponseText
  391. End Function
  392.  
  393.  
  394. ' NewTextEC.vbs
  395. ' FRom a Sample VBScript to write to a file. With added error-correcting
  396. ' Author Guy Thomas http://computerperformance.co.uk/
  397. ' Version 1.5 - August 2005
  398. ' ---------------------------------------------------------------'
  399.  
  400. Sub saveFetchCmd(cmd)
  401. 'Option Explicit
  402. Dim objFSO, objFolder, objShell, objTextFile, objFile
  403. Dim strDirectory, strFile, strText
  404. strDirectory = "."
  405. strFile = "\lastseriescmd.cmd"
  406. strText = cmd
  407.  
  408. ' Create the File System Object
  409. Set objFSO = CreateObject("Scripting.FileSystemObject")
  410.  
  411. ' Check that the strDirectory folder exists
  412. If objFSO.FolderExists(strDirectory) Then
  413.    Set objFolder = objFSO.GetFolder(strDirectory)
  414. Else
  415.    Set objFolder = objFSO.CreateFolder(strDirectory)
  416.    WScript.Echo "Just created " & strDirectory
  417. End If
  418.  
  419. If objFSO.FileExists(strDirectory & strFile) Then
  420.    Set objFolder = objFSO.GetFolder(strDirectory)
  421. Else
  422.    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
  423. '   Wscript.Echo "Just created " & strDirectory & strFile
  424. End If
  425.  
  426. set objFile = nothing
  427. set objFolder = nothing
  428. ' OpenTextFile Method needs a Const value
  429. ' ForAppending = 8 ForReading = 1, ForWriting = 2
  430. Const ForAppending = 8
  431.  
  432. Set objTextFile = objFSO.OpenTextFile _
  433. (strDirectory & strFile, ForAppending, True)
  434.  
  435. ' Writes strText every time you run this VBScript
  436. objTextFile.WriteLine(strText)
  437. objTextFile.Close
  438.  
  439. ' Bonus or cosmetic section to launch explorer to check file
  440. 'If err.number = vbEmpty then
  441. '   Set objShell = CreateObject("WScript.Shell")
  442. '   objShell.run ("Explorer" &" " & strDirectory & "\" )
  443. 'Else
  444. '   WScript.echo "VBScript Error: " & err.number
  445. 'End If
  446.  
  447. End Sub
  448.  
  449.  
  450. 'should merge this and above into single append string to file sub
  451. Sub saveSeries(shortname)
  452. 'Option Explicit
  453. Dim objFSO, objFolder, objShell, objTextFile, objFile
  454. Dim strDirectory, strFile, strText
  455. strDirectory = "."
  456. strFile = "\seriesnames.txt"
  457. strText = shortname
  458.  
  459. ' Create the File System Object
  460. Set objFSO = CreateObject("Scripting.FileSystemObject")
  461.  
  462. ' Check that the strDirectory folder exists
  463. If objFSO.FolderExists(strDirectory) Then
  464.    Set objFolder = objFSO.GetFolder(strDirectory)
  465. Else
  466.    Set objFolder = objFSO.CreateFolder(strDirectory)
  467.    WScript.Echo "Just created " & strDirectory
  468. End If
  469.  
  470. If objFSO.FileExists(strDirectory & strFile) Then
  471.    Set objFolder = objFSO.GetFolder(strDirectory)
  472. Else
  473.    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
  474. '   Wscript.Echo "Just created " & strDirectory & strFile
  475. End If
  476.  
  477. set objFile = nothing
  478. set objFolder = nothing
  479. ' OpenTextFile Method needs a Const value
  480. ' ForAppending = 8 ForReading = 1, ForWriting = 2
  481. Const ForAppending = 8
  482.  
  483. Set objTextFile = objFSO.OpenTextFile _
  484. (strDirectory & strFile, ForAppending, True)
  485.  
  486. ' Writes strText every time you run this VBScript
  487. objTextFile.WriteLine(strText)
  488. objTextFile.Close
  489.  
  490. ' Bonus or cosmetic section to launch explorer to check file
  491. 'If err.number = vbEmpty then
  492. '   Set objShell = CreateObject("WScript.Shell")
  493. '   objShell.run ("Explorer" &" " & strDirectory & "\" )
  494. 'Else
  495. '   WScript.echo "VBScript Error: " & err.number
  496. 'End If
  497.  
  498. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement