Mercurial > ~darius > hgwebdir.cgi > py-iview
view iviewget.py @ 5:f2e0787f52b8 default tip
Tidy up output to be clearer.
- Don't bother the user with XML errors & lack of asset tags.
- Print a header for the channel & series lists.
- Inform the user how to navigate the menus.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 21 Aug 2009 13:05:59 +0930 |
parents | c4188feb8f26 |
children |
line wrap: on
line source
#!/usr/bin/env python import iview import os.path import re import subprocess import sys import time outpath = '.' outext = 'flv16x9' flvstreamerpath = '/home/darius/projects/flvstreamer/flvstreamer_x86' flvpattern = re.compile("FLVStreamer v") def listChannels(iview): i = 1 print "===================== Channel List =====================" 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 print "===================== Series List =====================" 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 = os.path.join(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 def checkFLVStreamer(): try: s = subprocess.Popen(flvstreamerpath, stdout = subprocess.PIPE, stderr = subprocess.PIPE) except OSError: print "Couldn't execute FLVstreamer" return False while s.poll() != 1: time.sleep(0.1) out, err = s.communicate() if flvpattern.match(err) == None: print "Unrecognised output from FLVstreamer" return False return True if __name__ == "__main__": if not checkFLVStreamer(): sys.exit(1) iview = iview.IView() if iview.metered: print print "========== **WARNING** iview is metered **WARNING** ==========" print slist = [] while True: chan = None listChannels(iview) while True: print "Please select a channel number (0 to start downloading): ", 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 print "Please select which series to download (space separated numbers)" print " or 0 to exit to channel menu: ", 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()