MythTV  master
bliptv.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: bliptv.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform blip.tv lookups for the MythTV Netvision plugin
9 # based on information found on the http://blip.tv/ website. It
10 # follows the MythTV Netvision grabber standards.
11 # This script uses the python module bliptv_api.py which should be included
12 # with this script.
13 # The bliptv.py module uses the full access API 2.0 api published by
14 # http://blip.tv/ see: http://blip.tv/about/api/
15 #
16 # Command example:
17 # See help (-u and -h) options
18 #
19 # Design:
20 # 1) Import the specific target site API library.
21 # 2) Set the title for the scripts and the API key (optional) for the target video site
22 # 3) Call the common processing routine
23 #
24 #
25 # License:Creative Commons GNU GPL v2
26 # (http://creativecommons.org/licenses/GPL/2.0/)
27 #-------------------------------------
28 __title__ ="blip.tv";
29 __author__="R.D. Vaughan"
30 __version__="0.23"
31 # 0.1.0 Initial development
32 # 0.1.1 Add tree view
33 # 0.1.2 Documentation review
34 # 0.2.0 Public release
35 # 0.2.1 Improve the information displayed by trapped aborts
36 # 0.22 Change to support xml version information display
37 # 0.23 Added the "command" tag to the xml version information display
38 
39 __usage_examples__ ='''
40 > ./bliptv.py -h
41 Usage: ./bliptv.py -hduvlST [parameters] <search text>
42 
43 For details on the MythTV Netvision plugin see the wiki page at:
44 http://www.mythtv.org/wiki/MythNetvision
45 Version: v0.22 Author: R.D.Vaughan
46 
47 Options:
48  -h, --help show this help message and exit
49  -d, --debug Show debugging info (URLs, raw XML ... etc, info
50  varies per grabber)
51  -u, --usage Display examples for executing the script
52  -v, --version Display grabber name and supported options
53  -l LANGUAGE, --language=LANGUAGE
54  Select data that matches the specified language fall
55  back to English if nothing found (e.g. 'es' Español,
56  'de' Deutsch ... etc). Not all sites or grabbers
57  support this option.
58  -p PAGE NUMBER, --pagenumber=PAGE NUMBER
59  Display specific page of the search results. Default
60  is page 1. Page number is ignored with the Tree
61  View option (-T).
62  -S, --search Search for videos
63  -T, --treeview Display a Tree View of a sites videos
64 
65 
66 (Search for all videos identified with the word "flute")
67 >./bliptv.py -p 1 -S "flute"
68 <?xml version="1.0" encoding="UTF-8"?>
69 <rss version="2.0"
70 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
71 xmlns:content="http://purl.org/rss/1.0/modules/content/"
72 xmlns:cnettv="http://cnettv.com/mrss/"
73 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
74 xmlns:media="http://search.yahoo.com/mrss/"
75 xmlns:atom="http://www.w3.org/2005/Atom"
76 xmlns:amp="http://www.adobe.com/amp/1.0"
77 xmlns:dc="http://purl.org/dc/elements/1.1/">
78  <channel>
79  <title>blip.tv</title>
80  <link>http://blip.tv</link>
81  <description>We're the next generation television network</description>
82  <numresults>21</numresults>
83  <returned>20</returned>
84  <startindex>20</startindex>
85  <item>
86  <title>空中散歩</title>
87  <author>flute</author>
88  <pubDate>Sun, 25 May 2008 02:39:49 +0000</pubDate>
89  <description>test</description>
90  <link>http://blip.tv/file/933615</link>
91  <media:group>
92  <media:thumbnail url='http://a.images.blip.tv/Flute-416-140-781.jpg'/>
93  <media:content url='http://blip.tv/file/get/Flute-416.avi' duration='30' width='' height='' lang='en'/>
94  </media:group>
95  <rating>0.0</rating>
96  </item>
97 ...
98  <item>
99  <title>Bright Sunny Place (music video excerpt)</title>
100  <author>tokyosax</author>
101  <pubDate>Mon, 24 Sep 2007 11:05:46 +0000</pubDate>
102  <description>A brief snippet of my flute work from a larger video composition viewable at http://www.youtube.com/profile?user=japanjazzman. Original tune, original forehead.</description>
103  <link>http://blip.tv/file/394159</link>
104  <media:group>
105  <media:thumbnail url='http://a.images.blip.tv/Arnoldbaruch-BrightSunnyPlace503-931.jpg'/>
106  <media:content url='http://blip.tv/file/get/Arnoldbaruch-BrightSunnyPlace310.mov' duration='45' width='' height='' lang='en'/>
107  </media:group>
108  <rating>0.0</rating>
109  </item>
110  </channel>
111 </rss>
112 
113 (Create a Blip.tv Tree view)
114 >./bliptv.py -T
115 <?xml version="1.0" encoding="UTF-8"?>
116 <rss version="2.0"
117 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
118 xmlns:content="http://purl.org/rss/1.0/modules/content/"
119 xmlns:cnettv="http://cnettv.com/mrss/"
120 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
121 xmlns:media="http://search.yahoo.com/mrss/"
122 xmlns:atom="http://www.w3.org/2005/Atom"
123 xmlns:amp="http://www.adobe.com/amp/1.0"
124 xmlns:dc="http://purl.org/dc/elements/1.1/">
125  <channel>
126  <title>blip.tv</title>
127  <link>http://blip.tv</link>
128  <description>We're the next generation television network</description>
129  <numresults>0</numresults>
130  <returned>1</returned>
131  <startindex>0</startindex>
132  <directory name="Popular/Recent/Features/Random ..." thumbnail="/usr/local/share/mythtv//mythnetvision/icons/bliptv.png">
133  <directory name="Most Comments" thumbnail="/usr/local/share/mythtv//mythnetvision/icons/directories/topics/most_comments.png">
134  <item>
135  <title>VIDEO: Eritrea Movie Timali (Part 24)</title>
136  <author>asmarino5</author>
137  <pubDate>Mon, 04 Jan 2010 05:30:21 +0000</pubDate>
138  <description>VIDEO: Eritrea Movie Timali (Part 24)</description>
139  <link>http://blip.tv/file/3043223</link>
140  <media:group>
141  <media:thumbnail url='http://a.images.blip.tv/Asmarino5-VIDEOEritreaMovieTimaliPart24121-227.jpg'/>
142  <media:content url='http://blip.tv/file/get/Asmarino5-VIDEOEritreaMovieTimaliPart24121.wmv' duration='2216' width='320' height='240' lang='en'/>
143  </media:group>
144  <rating>0.0</rating>
145  </item>
146 ...
147  <item>
148  <title>informest</title>
149  <author>fluido</author>
150  <pubDate>Sun, 03 Jan 2010 22:23:56 +0000</pubDate>
151  <description>informest</description>
152  <link>http://blip.tv/file/3042202</link>
153  <media:group>
154  <media:thumbnail url='http://a.images.blip.tv/Fluido-informest458-244.jpg'/>
155  <media:content url='http://blip.tv/file/get/Fluido-informest458.mp4' duration='310' width='720' height='576' lang='en'/>
156  </media:group>
157  <rating>0.0</rating>
158  </item>
159  </directory>
160  </directory>
161  </channel>
162 </rss>
163 '''
164 
165 __max_page_items__ = 20
166 
167 import sys, os
168 
169 class OutStreamEncoder(object):
170  """Wraps a stream with an encoder"""
171  def __init__(self, outstream, encoding=None):
172  self.out = outstream
173  if not encoding:
174  self.encoding = sys.getfilesystemencoding()
175  else:
176  self.encoding = encoding
177 
178  def write(self, obj):
179  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
180  if isinstance(obj, unicode):
181  try:
182  self.out.write(obj.encode(self.encoding))
183  except IOError:
184  pass
185  else:
186  try:
187  self.out.write(obj)
188  except IOError:
189  pass
190 
191  def __getattr__(self, attr):
192  """Delegate everything but write to the stream"""
193  return getattr(self.out, attr)
194 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
195 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
196 
197 
198 # Used for debugging - usually commented out
199 #import nv_python_libs.bliptv.bliptv_api as target
200 
201 # Verify that the tmdb_api modules are installed and accessible
202 try:
203  import nv_python_libs.bliptv.bliptv_api as target
204 except Exception, e:
205  sys.stderr.write('''
206 The subdirectory "nv_python_libs/bliptv" containing the modules bliptv_api.py (v0.2.0 or greater),
207 They should have been included with the distribution of bliptv.py.
208 Error(%s)
209 ''' % e)
210  sys.exit(1)
211 
212 if target.__version__ < '0.2.0':
213  sys.stderr.write("\n! Error: Your current installed bliptv_api.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % target.__version__)
214  sys.exit(1)
215 
216 
217 # Verify that the common process modules are installed and accessible
218 try:
219  import nv_python_libs.mainProcess as process
220 except Exception, e:
221  sys.stderr.write('''
222 The python script "nv_python_libs/mainProcess.py" must be present.
223 Error(%s)
224 ''' % e)
225  sys.exit(1)
226 
227 if process.__version__ < '0.2.0':
228  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__)
229  sys.exit(1)
230 
231 if __name__ == '__main__':
232  # No api key is required
233  apikey = ""
234  main = process.mainProcess(target, apikey, )
235  main.grabberInfo = {}
236  main.grabberInfo['title'] = __title__
237  main.grabberInfo['command'] = u'bliptv.py'
238  main.grabberInfo['author'] = __author__
239  main.grabberInfo['thumbnail'] = 'bliptv.png'
240  main.grabberInfo['type'] = ['video']
241  main.grabberInfo['desc'] = u"We're the next generation television network."
242  main.grabberInfo['version'] = __version__
243  main.grabberInfo['search'] = True
244  main.grabberInfo['tree'] = True
245  main.grabberInfo['html'] = False
246  main.grabberInfo['usage'] = __usage_examples__
247  main.grabberInfo['SmaxPage'] = __max_page_items__
248  main.grabberInfo['TmaxPage'] = __max_page_items__
249  main.main()
def __getattr__(self, attr)
Definition: bliptv.py:191
def write(self, obj)
Definition: bliptv.py:178
def __init__(self, outstream, encoding=None)
Definition: bliptv.py:171