MythTV  master
rev3.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
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 import io
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, str):
189  obj = obj.encode(self.encoding)
190  self.out.buffer.write(obj)
191 
192  def __getattr__(self, attr):
193  """Delegate everything but write to the stream"""
194  return getattr(self.out, attr)
195 
196 if isinstance(sys.stdout, io.TextIOWrapper):
197  sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
198  sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
199 
200 
201 # Used for debugging
202 #import nv_python_libs.common.common_api
203 try:
204  '''Import the common python class
205  '''
206  import nv_python_libs.common.common_api as common_api
207 except Exception as e:
208  sys.stderr.write('''
209 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
210 common_exceptions.py (v0.1.3 or greater),
211 They should have been included with the distribution of MythNetvision
212 Error(%s)
213 ''' % e)
214  sys.exit(1)
215 if common_api.__version__ < '0.1.3':
216  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__)
217  sys.exit(1)
218 
219 # Used for debugging
220 #import nv_python_libs.rev3.rev3_api as target
221 try:
222  '''Import the python Rev3 support classes
223  '''
224  import nv_python_libs.rev3.rev3_api as target
225 except Exception as e:
226  sys.stderr.write('''
227 The subdirectory "nv_python_libs/rev3" containing the modules rev3_api.py and
228 rev3_exceptions.py (v0.1.0 or greater),
229 They should have been included with the distribution of rev3.py.
230 Error(%s)
231 ''' % e)
232  sys.exit(1)
233 if target.__version__ < '0.1.0':
234  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__)
235  sys.exit(1)
236 
237 # Verify that the main process modules are installed and accessible
238 try:
239  import nv_python_libs.mainProcess as process
240 except Exception as e:
241  sys.stderr.write('''
242 The python script "nv_python_libs/mainProcess.py" must be present.
243 Error(%s)
244 ''' % e)
245  sys.exit(1)
246 
247 if process.__version__ < '0.2.0':
248  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__)
249  sys.exit(1)
250 
251 if __name__ == '__main__':
252  # No api key is required
253  apikey = ""
254  # Set the base processing directory that the grabber is installed
255  target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
256  # Make sure the target functions have an instance of the common routines
257  target.common = common_api.Common()
258  main = process.mainProcess(target, apikey, )
259  main.grabberInfo = {}
260  main.grabberInfo['enabled'] = True
261  main.grabberInfo['title'] = __title__
262  main.grabberInfo['command'] = 'rev3.py'
263  main.grabberInfo['mashup_title'] = __mashup_title__
264  main.grabberInfo['author'] = __author__
265  main.grabberInfo['thumbnail'] = 'rev3.png'
266  main.grabberInfo['type'] = ['video', ]
267  main.grabberInfo['desc'] = "Revision3 is the leading television network for the internet generation."
268  main.grabberInfo['version'] = __version__
269  main.grabberInfo['search'] = True
270  main.grabberInfo['tree'] = True
271  main.grabberInfo['html'] = False
272  main.grabberInfo['usage'] = __usage_examples__
273  main.grabberInfo['SmaxPage'] = __search_max_page_items__
274  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
275  main.main()
rev3.OutStreamEncoder.__getattr__
def __getattr__(self, attr)
Definition: rev3.py:192
rev3.OutStreamEncoder.out
out
Definition: rev3.py:180
rev3.OutStreamEncoder.encoding
encoding
Definition: rev3.py:182
rev3.OutStreamEncoder
Definition: rev3.py:177
nv_python_libs.mainProcess
Definition: mainProcess.py:1
nv_python_libs.rev3.rev3_api
Definition: rev3_api.py:1
nv_python_libs.common.common_api
Definition: common_api.py:1
rev3.OutStreamEncoder.write
def write(self, obj)
Definition: rev3.py:186
rev3.OutStreamEncoder.__init__
def __init__(self, outstream, encoding=None)
Definition: rev3.py:179