Mercurial > ~darius > hgwebdir.cgi > py-iview
view iviewget.py @ 1:f914f08d69f5
Don't re-get series info if we already have it as it's very slow.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 20 Aug 2009 17:33:35 +0930 |
parents | fa7ca67af8c9 |
children | 6edc508e0775 |
line wrap: on
line source
#!/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()