annotate iviewget.py @ 4:c4188feb8f26

Make the unmetered warning more strident.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 20 Aug 2009 17:35:27 +0930
parents 34471d354603
children f2e0787f52b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
4 import os.path
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
5 import re
0
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 subprocess
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 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
8 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
9
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 outpath = '.'
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 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
12 flvstreamerpath = '/home/darius/projects/flvstreamer/flvstreamer_x86'
2
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
13 flvpattern = re.compile("FLVStreamer v")
0
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 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
16 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
17 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
18 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
19 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
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
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 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
23 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
24 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
25 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
26 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
27 else:
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 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
29 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
30 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
31
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 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
33 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
34 try:
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 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
36 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
37 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
38
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 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
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 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
42 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
43
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 if outfile == None:
3
34471d354603 Use os.path.join to construct the output filename, hopefully more portable.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
45 outfile = os.path.join(outpath, series.asset.replace('/', '-') + '.' + outext)
0
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 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
47 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
48 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
49 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
50 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
51 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
52 else:
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 return res
2
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
54
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
55 def checkFLVStreamer():
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
56 try:
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
57 s = subprocess.Popen(flvstreamerpath, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
58 except OSError:
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
59 print "Couldn't execute FLVstreamer"
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
60 return False
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
61 while s.poll() != 1:
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
62 time.sleep(0.1)
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
63
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
64 out, err = s.communicate()
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
65 if flvpattern.match(err) == None:
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
66 print "Unrecognised output from FLVstreamer"
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
67 return False
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
68
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
69 return True
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
70
0
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 if __name__ == "__main__":
2
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
72 if not checkFLVStreamer():
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
73 sys.exit(1)
6edc508e0775 Try and run flvstreamer on init and exit if it fails.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
74
0
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 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
76 if iview.metered:
4
c4188feb8f26 Make the unmetered warning more strident.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
77 print
c4188feb8f26 Make the unmetered warning more strident.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
78 print "========== **WARNING** iview is metered **WARNING** =========="
0
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 print
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 slist = []
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 break
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 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
91
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 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
93 break
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 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
96 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
97 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
98
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 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
100 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
101 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
102 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
103 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
104 try:
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 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
106 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
107 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
108
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 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
110 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
111
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 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
113 break
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 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
115
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 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
117 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
118 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
119
fa7ca67af8c9 Initial commit of a python program to fetch iview streams using flvstreamer.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 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
121 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
122 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
123 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
124 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
125 # 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
126 iview.getAuth()