comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:fa7ca67af8c9
1 #!/usr/bin/env python
2
3 import iview
4 import subprocess
5 import sys
6 import time
7
8 outpath = '.'
9 outext = 'flv16x9'
10 flvstreamerpath = '/home/darius/projects/flvstreamer/flvstreamer_x86'
11
12 def listChannels(iview):
13 i = 1
14 print "Id %-30s %-35s" % ('Name', 'Description')
15 for c in iview.channels:
16 print "%2d %-30s %-35s" % (i, c.name, c.descr)
17 i += 1
18
19 def listSeries(chan):
20 i = 1
21 for s in chan.series:
22 if len(s.title) > 1:
23 title = s.title[1]
24 else:
25 title = s.title[0]
26 print "%3d %s" % (i, title)
27 i += 1
28
29 def getInt(f):
30 ans = f.readline()
31 try:
32 i = int(ans)
33 except ValueError:
34 return None
35
36 return i
37
38 def getSeries(iview, series, outfile = None):
39 cmd = [flvstreamerpath]
40
41 if outfile == None:
42 outfile = outpath + '/' + series.asset.replace('/', '-') + '.' + outext
43 cmd += iview.genFetchCmd(series, outfile)
44 p = subprocess.Popen(cmd)
45 while True:
46 res = p.poll()
47 if res == None:
48 time.sleep(0.1)
49 else:
50 return res
51
52 if __name__ == "__main__":
53 iview = iview.IView()
54 if iview.metered:
55 print "WARNING: iview is metered"
56 print
57
58 slist = []
59 while True:
60 chan = None
61 listChannels(iview)
62 while True:
63 print "Please select a channel number (0 to exit): ",
64 i = getInt(sys.stdin)
65 if i != None and i >= 0 and i <= len(iview.channels):
66 break
67 print "Invalid entry, try again"
68
69 if i == 0:
70 break
71
72 cidx = i - 1
73 chan = iview.channels[cidx]
74 chan.getSeries()
75
76 listSeries(chan)
77 while True:
78 print "Please select which series to download (space separated numbers):"
79 res = sys.stdin.readline()
80 for r in res.split():
81 try:
82 i = int(r)
83 except ValueError:
84 i = None
85
86 if i != None and i >= 0 and i <= len(chan.series):
87 slist += [chan.series[i - 1]]
88
89 if len(slist) > 0 or i == 0:
90 break
91 print "Invalid entry, try again"
92
93 if len(slist) == 0:
94 print "Nothing to download"
95 sys.exit(0)
96
97 print "Downloading %d items" % (len(slist))
98 for series in slist:
99 print "Fetching " + series.asset
100 res = getSeries(iview, series)
101 print "Result is " + str(res)
102 # Re-auth or the server won't love us
103 iview.getAuth()