diff iviewget.py @ 0:fa7ca67af8c9

Initial commit of a python program to fetch iview streams using flvstreamer.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 20 Aug 2009 16:48:16 +0930
parents
children 6edc508e0775
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iviewget.py	Thu Aug 20 16:48:16 2009 +0930
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+
+import iview
+import subprocess
+import sys
+import time
+
+outpath = '.'
+outext = 'flv16x9'
+flvstreamerpath = '/home/darius/projects/flvstreamer/flvstreamer_x86'
+
+def listChannels(iview):
+    i = 1
+    print "Id %-30s %-35s" % ('Name', 'Description')
+    for c in iview.channels:
+        print "%2d %-30s %-35s" % (i, c.name, c.descr)
+        i += 1
+
+def listSeries(chan):
+    i = 1
+    for s in chan.series:
+        if len(s.title) > 1:
+            title = s.title[1]
+        else:
+            title = s.title[0]
+        print "%3d %s" % (i, title)
+        i += 1
+
+def getInt(f):
+    ans = f.readline()
+    try:
+        i = int(ans)
+    except ValueError:
+        return None
+
+    return i
+
+def getSeries(iview, series, outfile = None):
+    cmd = [flvstreamerpath]
+
+    if outfile == None:
+        outfile = outpath + '/' + series.asset.replace('/', '-') + '.' + outext
+    cmd += iview.genFetchCmd(series, outfile)
+    p = subprocess.Popen(cmd)
+    while True:
+        res = p.poll()
+        if res == None:
+            time.sleep(0.1)
+        else:
+            return res
+            
+if __name__ == "__main__":
+    iview = iview.IView()
+    if iview.metered:
+        print "WARNING: iview is metered"
+        print
+
+    slist = []
+    while True:
+        chan = None
+        listChannels(iview)
+        while True:
+            print "Please select a channel number (0 to exit): ",
+            i = getInt(sys.stdin)
+            if i != None and i >= 0 and i <= len(iview.channels):
+                break
+            print "Invalid entry, try again"
+
+        if i == 0:
+            break
+
+        cidx = i - 1
+        chan = iview.channels[cidx]
+        chan.getSeries()
+
+        listSeries(chan)
+        while True:
+            print "Please select which series to download (space separated numbers):"
+            res = sys.stdin.readline()
+            for r in res.split():
+                try:
+                    i = int(r)
+                except ValueError:
+                    i = None
+
+                if i != None and i >= 0 and i <= len(chan.series):
+                    slist += [chan.series[i - 1]]
+                
+            if len(slist) > 0 or i == 0:
+                break
+            print "Invalid entry, try again"
+
+    if len(slist) == 0:
+        print "Nothing to download"
+        sys.exit(0)
+
+    print "Downloading %d items" % (len(slist))
+    for series in slist:
+        print "Fetching " + series.asset
+        res = getSeries(iview, series)
+        print "Result is " + str(res)
+        # Re-auth or the server won't love us
+        iview.getAuth()