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