MythTV  master
bliptv.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
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 import io
169 
170 class OutStreamEncoder(object):
171  """Wraps a stream with an encoder"""
172  def __init__(self, outstream, encoding=None):
173  self.out = outstream
174  if not encoding:
175  self.encoding = sys.getfilesystemencoding()
176  else:
177  self.encoding = encoding
178 
179  def write(self, obj):
180  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
181  if isinstance(obj, str):
182  obj = obj.encode(self.encoding)
183  self.out.buffer.write(obj)
184 
185  def __getattr__(self, attr):
186  """Delegate everything but write to the stream"""
187  return getattr(self.out, attr)
188 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
189 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
190 
191 
192 # Used for debugging - usually commented out
193 #import nv_python_libs.bliptv.bliptv_api as target
194 
195 # Verify that the tmdb_api modules are installed and accessible
196 try:
197  import nv_python_libs.bliptv.bliptv_api as target
198 except Exception as e:
199  sys.stderr.write('''
200 The subdirectory "nv_python_libs/bliptv" containing the modules bliptv_api.py (v0.2.0 or greater),
201 They should have been included with the distribution of bliptv.py.
202 Error(%s)
203 ''' % e)
204  sys.exit(1)
205 
206 if target.__version__ < '0.2.0':
207  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__)
208  sys.exit(1)
209 
210 
211 # Verify that the common process modules are installed and accessible
212 try:
213  import nv_python_libs.mainProcess as process
214 except Exception as e:
215  sys.stderr.write('''
216 The python script "nv_python_libs/mainProcess.py" must be present.
217 Error(%s)
218 ''' % e)
219  sys.exit(1)
220 
221 if process.__version__ < '0.2.0':
222  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__)
223  sys.exit(1)
224 
225 if __name__ == '__main__':
226  # No api key is required
227  apikey = ""
228  main = process.mainProcess(target, apikey, )
229  main.grabberInfo = {}
230  main.grabberInfo['enabled'] = True
231  main.grabberInfo['title'] = __title__
232  main.grabberInfo['command'] = 'bliptv.py'
233  main.grabberInfo['author'] = __author__
234  main.grabberInfo['thumbnail'] = 'bliptv.png'
235  main.grabberInfo['type'] = ['video']
236  main.grabberInfo['desc'] = "We're the next generation television network."
237  main.grabberInfo['version'] = __version__
238  main.grabberInfo['search'] = True
239  main.grabberInfo['tree'] = True
240  main.grabberInfo['html'] = False
241  main.grabberInfo['usage'] = __usage_examples__
242  main.grabberInfo['SmaxPage'] = __max_page_items__
243  main.grabberInfo['TmaxPage'] = __max_page_items__
244  main.main()
bliptv.OutStreamEncoder.write
def write(self, obj)
Definition: bliptv.py:179
nv_python_libs.bliptv.bliptv_api
Definition: bliptv_api.py:1
nv_python_libs.mainProcess
Definition: mainProcess.py:1
bliptv.OutStreamEncoder.out
out
Definition: bliptv.py:173
bliptv.OutStreamEncoder
Definition: bliptv.py:170
bliptv.OutStreamEncoder.encoding
encoding
Definition: bliptv.py:175
bliptv.OutStreamEncoder.__getattr__
def __getattr__(self, attr)
Definition: bliptv.py:185
bliptv.OutStreamEncoder.__init__
def __init__(self, outstream, encoding=None)
Definition: bliptv.py:172