MythTV  master
rev3.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: rev3.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform Revision3 video lookups for the MythTV Netvision plugin
9 # based on information found on the http://revision3.com/ website. It
10 # follows the MythTV Netvision grabber standards.
11 #
12 # Command example:
13 # See help (-u and -h) options
14 #
15 # Design:
16 # 1) Read the ".../emml/feConfig.xml"
17 # 2) Check if the CGI Web server should be used or if the script is run locally
18 # 3) Initialize the correct target functions for processing (local or remote)
19 # 4) Process the search or treeview request and display to stdout
20 #
21 #
22 # License:Creative Commons GNU GPL v2
23 # (http://creativecommons.org/licenses/GPL/2.0/)
24 #-------------------------------------
25 __title__ ="Revision3";
26 __mashup_title__ = "rev3"
27 __author__="R.D. Vaughan"
28 __version__="0.15"
29 # 0.1.0 Initial development
30 # 0.1.1 Added treeview support
31 # 0.1.2 Convert to detect and use either local or remote processing
32 # 0.13 Change to support xml version information display
33 # 0.14 Added the "command" tag to the xml version information display
34 # 0.15 Converted to new common_api.py library
35 
36 __usage_examples__ ='''
37 (Option Help)
38 > ./rev3.py -h
39 Usage: ./rev3.py -hduvlST [parameters] <search text>
40 Version: v0.1.2 Author: R.D.Vaughan
41 
42 For details on the MythTV Netvision plugin see the wiki page at:
43 http://www.mythtv.org/wiki/MythNetvision
44 
45 Options:
46  -h, --help show this help message and exit
47  -d, --debug Show debugging info (URLs, raw XML ... etc, info
48  varies per grabber)
49  -u, --usage Display examples for executing the script
50  -v, --version Display grabber name and supported options
51  -l LANGUAGE, --language=LANGUAGE
52  Select data that matches the specified language fall
53  back to English if nothing found (e.g. 'es' EspaƱol,
54  'de' Deutsch ... etc). Not all sites or grabbers
55  support this option.
56  -p PAGE NUMBER, --pagenumber=PAGE NUMBER
57  Display specific page of the search results. Default
58  is page 1. Page number is ignored with the Tree View
59  option (-T).
60  -S, --search Search for videos
61  -T, --treeview Display a Tree View of a sites videos
62 
63 > ./rev3.py -v
64 <grabber>
65  <name>Revision3</name>
66  <author>R.D.Vaughan</author>
67  <thumbnail>rev3.png</thumbnail>
68  <type>video</type>
69  <description>Revision3 is the leading television network for the internet generation.</description>
70  <version>v0.13</version>
71  <search>true</search>
72  <tree>true</tree>
73 </grabber>
74 
75 > ./rev3.py -S "iPad" -p 1
76 <?xml version="1.0" encoding="UTF-8"?>
77 <rss version="2.0" xmlns:amp="http://www.adobe.com/amp/1.0"
78  xmlns:atom="http://www.w3.org/2005/Atom"
79  xmlns:cnettv="http://cnettv.com/mrss/"
80  xmlns:content="http://purl.org/rss/1.0/modules/content/"
81  xmlns:creativecommons="http://backend.userland.com/creativeCommonsRssModule"
82  xmlns:dc="http://purl.org/dc/elements/1.1/"
83  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/">
84  <channel>
85  <title>Revision3</title>
86  <link>http://revision3.com/</link>
87  <description>Revision3 is the leading television network for the internet generation.</description>
88  <numresults>16</numresults>
89  <returned>15</returned>
90  <startindex>15</startindex>
91  <item>
92  <title>AppJudgment &amp;gt; Episode 101 &amp;gt; Voice Band for the ...</title>
93  <author>Revision3</author>
94  <pubDate>Mon, 05 Apr 2010 23:10:47 GMT</pubDate>
95  <description>AppJudgment: Voice Band for the iPhone/iPod Touch - &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; AppJudgment:&amp;lt;br /&amp;gt; Download&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; Voice Band&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; Version 1.1 ...</description>
96  <link>http://revision3.com/appjudgment/ip_mau_voiceband/voice-band-for-the-iphone-ipod-touch?fs</link>
97  <mrss:group xmlns:mrss="http://search.yahoo.com/mrss/">
98  <mrss:thumbnail url=""/>
99  <mrss:content duration="" height="" lang=""
100  url="http://revision3.com/appjudgment/ip_mau_voiceband/voice-band-for-the-iphone-ipod-touch?fs" width=""/>
101  </mrss:group>
102  <rating>0.0</rating>
103  </item>
104 ...
105  <item>
106  <title>The Totally Rad Show &amp;gt; Episode 150: Hockey Kahn ...</title>
107  <author>Revision3</author>
108  <pubDate>Mon, 05 Apr 2010 23:10:47 GMT</pubDate>
109  <description>The Totally Rad Show: Hockey Kahn - Edge of Darkness, MAG, iPad Gaming, the End of Miramax, and More Twitter Q&amp;amp;A - We walk the Edge of Darkness with Mel Gibson. MAG ...</description>
110  <link>http://revision3.com/trs/hockeykhan?fs</link>
111  <mrss:group xmlns:mrss="http://search.yahoo.com/mrss/">
112  <mrss:thumbnail url=""/>
113  <mrss:content duration="" height="" lang=""
114  url="http://revision3.com/trs/hockeykhan?fs" width=""/>
115  </mrss:group>
116  <rating>0.0</rating>
117  </item>
118  </channel>
119 </rss>
120 
121 > ./rev3.py -T
122 <?xml version="1.0" encoding="UTF-8"?>
123 <rss version="2.0" xmlns:amp="http://www.adobe.com/amp/1.0"
124  xmlns:atom="http://www.w3.org/2005/Atom"
125  xmlns:cnettv="http://cnettv.com/mrss/"
126  xmlns:content="http://purl.org/rss/1.0/modules/content/"
127  xmlns:creativecommons="http://backend.userland.com/creativeCommonsRssModule"
128  xmlns:dc="http://purl.org/dc/elements/1.1/"
129  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/">
130  <channel>
131  <title>Revision3</title>
132  <link>http://revision3.com/</link>
133  <description>Revision3 is the leading television network for the internet generation.</description>
134  <numresults>1</numresults>
135  <returned>1</returned>
136  <startindex>1</startindex>
137  <directory name="Revision3" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/revision3.png">
138  <directory name="Best Of... (HD MP4)" thumbnail="http://bitcast-a.bitgravity.com/revision3/images/shows/bestof/bestof.jpg">
139  <item>
140  <title>Hick - How to Train Your Dragon - Best Of...</title>
141  <author>feedback@revision3.com (Revision3)</author>
142  <pubDate>Fri, 02 Apr 2010 00:00:00 GMT</pubDate>
143  <description>Dreamworks Animation has played second fiddle to the Pixar juggernaut for years...</description>
144  <link>http://revision3.com/bestof/trs-0158</link>
145  <mrss:group xmlns:mrss="http://search.yahoo.com/mrss/">
146  <mrss:thumbnail url="http://bitcast-a.bitgravity.com/revision3/images/shows/bestof/0501/bestof--0501--trs-0158--mini.thumb.jpg"/>
147  <mrss:content duration="338" height="" lang="en"
148  url="http://www.podtrac.com/pts/redirect.mp4/bitcast-a.bitgravity.com/revision3/web/bestof/0501/bestof--0501--trs-0158--hd.h264.mp4" width=""/>
149  </mrss:group>
150  <rating>0.0</rating>
151  </item>
152 ...
153  <item>
154  <title>What Should You Know: Revision3 Beta</title>
155  <author/>
156  <pubDate>Wed, 10 Sep 2008 20:25:30 GMT</pubDate>
157  <description>So when someone comes up to you and asks if you know about Revision3 Beta. This is what you should say... http://wsyk.opensermo.com</description>
158  <link>http://revision3beta.com/watch/wsyk/4dcf948a/</link>
159  <media:group>
160  <media:thumbnail url="http://cdn-ll-80.viddler.com/e2/thumbnail_2_4dcf948a.jpg"/>
161  <media:content duration="" height="" lang=""
162  url="http://revision3beta.com/watch/wsyk/4dcf948a/" width=""/>
163  </media:group>
164  <rating>0.0</rating>
165  </item>
166  </directory>
167  </directory>
168  </channel>
169 </rss>
170 '''
171 __search_max_page_items__ = 15 # Hardcoded value as this is the maximum allowed by Rev3
172 __tree_max_page_items__ = 15
173 
174 import sys, os
175 
176 
177 class OutStreamEncoder(object):
178  """Wraps a stream with an encoder"""
179  def __init__(self, outstream, encoding=None):
180  self.out = outstream
181  if not encoding:
182  self.encoding = sys.getfilesystemencoding()
183  else:
184  self.encoding = encoding
185 
186  def write(self, obj):
187  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
188  if isinstance(obj, unicode):
189  try:
190  self.out.write(obj.encode(self.encoding))
191  except IOError:
192  pass
193  else:
194  try:
195  self.out.write(obj)
196  except IOError:
197  pass
198 
199  def __getattr__(self, attr):
200  """Delegate everything but write to the stream"""
201  return getattr(self.out, attr)
202 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
203 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
204 
205 
206 # Used for debugging
207 #import nv_python_libs.common.common_api
208 try:
209  '''Import the common python class
210  '''
211  import nv_python_libs.common.common_api as common_api
212 except Exception, e:
213  sys.stderr.write('''
214 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
215 common_exceptions.py (v0.1.3 or greater),
216 They should have been included with the distribution of MythNetvision
217 Error(%s)
218 ''' % e)
219  sys.exit(1)
220 if common_api.__version__ < '0.1.3':
221  sys.stderr.write("\n! Error: Your current installed common_api.py version is (%s)\nYou must at least have version (0.1.3) or higher.\n" % target.__version__)
222  sys.exit(1)
223 
224 # Used for debugging
225 #import nv_python_libs.rev3.rev3_api as target
226 try:
227  '''Import the python Rev3 support classes
228  '''
229  import nv_python_libs.rev3.rev3_api as target
230 except Exception, e:
231  sys.stderr.write('''
232 The subdirectory "nv_python_libs/rev3" containing the modules rev3_api.py and
233 rev3_exceptions.py (v0.1.0 or greater),
234 They should have been included with the distribution of rev3.py.
235 Error(%s)
236 ''' % e)
237  sys.exit(1)
238 if target.__version__ < '0.1.0':
239  sys.stderr.write("\n! Error: Your current installed rev3_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
240  sys.exit(1)
241 
242 # Verify that the main process modules are installed and accessible
243 try:
244  import nv_python_libs.mainProcess as process
245 except Exception, e:
246  sys.stderr.write('''
247 The python script "nv_python_libs/mainProcess.py" must be present.
248 Error(%s)
249 ''' % e)
250  sys.exit(1)
251 
252 if process.__version__ < '0.2.0':
253  sys.stderr.write("\n! Error: Your current installed mainProcess.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % process.__version__)
254  sys.exit(1)
255 
256 if __name__ == '__main__':
257  # No api key is required
258  apikey = ""
259  # Set the base processing directory that the grabber is installed
260  target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
261  # Make sure the target functions have an instance of the common routines
262  target.common = common_api.Common()
263  main = process.mainProcess(target, apikey, )
264  main.grabberInfo = {}
265  main.grabberInfo['title'] = __title__
266  main.grabberInfo['command'] = u'rev3.py'
267  main.grabberInfo['mashup_title'] = __mashup_title__
268  main.grabberInfo['author'] = __author__
269  main.grabberInfo['thumbnail'] = 'rev3.png'
270  main.grabberInfo['type'] = ['video', ]
271  main.grabberInfo['desc'] = u"Revision3 is the leading television network for the internet generation."
272  main.grabberInfo['version'] = __version__
273  main.grabberInfo['search'] = True
274  main.grabberInfo['tree'] = True
275  main.grabberInfo['html'] = False
276  main.grabberInfo['usage'] = __usage_examples__
277  main.grabberInfo['SmaxPage'] = __search_max_page_items__
278  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
279  main.main()
def __init__(self, outstream, encoding=None)
Definition: rev3.py:179
def __getattr__(self, attr)
Definition: rev3.py:199
def write(self, obj)
Definition: rev3.py:186