MythTV  master
vimeo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: vimeo.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform vimeo.com lookups for the MythTV Netvision plugin
9 # based on information found on the http://vimeo.com/ website. It
10 # follows the MythTV Netvision grabber standards.
11 # This script uses the python module vimeo.py which should be included
12 # with this script.
13 # The vimeo.py module uses the full access API v2 api published by
14 # http://vimeo.com/ see: http://vimeo.com/api/docs/advanced-api
15 # Users of this script are encouraged to populate vimeo.com with your own Videos. The richer the source the
16 # more valuable the script.
17 # Command example:
18 # See help (-u and -h) options
19 #
20 # Design:
21 # 1) Import the specific target site API library.
22 # 2) Set the title for the scrips and the API optional key for the target video site
23 # 3) Call the common processing routine
24 #
25 #
26 # License:Creative Commons GNU GPL v2
27 # (http://creativecommons.org/licenses/GPL/2.0/)
28 #-------------------------------------
29 __title__ ="Vimeo";
30 __author__="R.D. Vaughan"
31 __version__="0.23"
32 # 0.1.0 Initial development
33 # 0.1.1 Added the Tree view option
34 # 0.1.2 Documentation review
35 # 0.2.0 Public release
36 # 0.2.1 Improved error display messages on an exception abort
37 # 0.22 Change to support xml version information display
38 # 0.23 Added the "command" tag to the xml version information display
39 
40 __usage_examples__ ='''
41 > ./vimeo.py -h
42 Usage: ./vimeo.py -hduvlST [parameters] <search text>
43 Version: v0.22 Author: R.D.Vaughan
44 
45 For details on the MythTV Netvision plugin see the wiki page at:
46 http://www.mythtv.org/wiki/MythNetvision
47 
48 Options:
49  -h, --help show this help message and exit
50  -d, --debug Show debugging info (URLs, raw XML ... etc, info
51  varies per grabber)
52  -u, --usage Display examples for executing the script
53  -v, --version Display grabber name and supported options
54  -l LANGUAGE, --language=LANGUAGE
55  Select data that matches the specified language fall
56  back to English if nothing found (e.g. 'es' Español,
57  'de' Deutsch ... etc). Not all sites or grabbers
58  support this option.
59  -p PAGE NUMBER, --pagenumber=PAGE NUMBER
60  Display specific page of the search results. Default
61  is page 1. Page number is ignored with the Tree View
62  option (-T).
63  -S, --search Search for videos
64  -T, --treeview Display a Tree View of a sites videos
65 
66 
67 (Search for all videos identified with the word "Dragon")
68 > ./vimeo.py -p 1 -S "Dragon"
69 <?xml version="1.0" encoding="UTF-8"?>
70 <rss version="2.0"
71 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
72 xmlns:content="http://purl.org/rss/1.0/modules/content/"
73 xmlns:cnettv="http://cnettv.com/mrss/"
74 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
75 xmlns:media="http://search.yahoo.com/mrss/"
76 xmlns:atom="http://www.w3.org/2005/Atom"
77 xmlns:amp="http://www.adobe.com/amp/1.0"
78 xmlns:dc="http://purl.org/dc/elements/1.1/">
79  <channel>
80  <title>Vimeo</title>
81  <link>http://vimeo.com</link>
82  <description>Vimeo is a respectful community of creative people who are passionate about sharing the videos they make.</description>
83  <numresults>4856</numresults>
84  <returned>20</returned>
85  <startindex>20</startindex>
86  <item>
87  <title>Typophile Film Festival 5 Opening Titles</title>
88  <author>Brent Barson</author>
89  <pubDate>Tue, 01 Sep 2009 12:27:46 GMT</pubDate>
90  <description>Handcrafted with love by BYU design students and faculty, for the 5th Typophile Film Festival. A visual typographic feast about the five senses, and how they contribute to and enhance our creativity. Everything in the film is real—no CG effects! Shot with a RED One, a Canon EOS 5D Mark II, a Canon EOS 40D, and a Nikon D80. Stop motion created with Dragon Stop Motion. Creative Director &amp; Faculty Mentor: Brent Barson Writing &amp; Storyboarding: Brent Barson, Jessica Blackham, Analisa Estrada, Meg Gallagher, John Jensen, Regan Fred Johnson, Colin “The Pin” Pinegar Construction, Paint &amp; Glue: Brent Barson, Wynn Burton, Analisa Estrada, Meg Gallagher, Olivia Juarez Knudsen, Casey Lewis, Reeding Roberts, Deven Stephens, Brian Christensen (Brain Sculpture) Animators: Brent Barson, Wynn Burton, Analisa Estrada, Meg Gallagher, Olivia Juarez Knudsen, Reeding Roberts, Deven Stephens Cinematographer: Wynn Burton Editing: Brent Barson, Wynn Burton, Analisa Estrada, Meg Gallagher, Reeding Roberts Hand Models: Analisa Estrada, Meg Gallagher, Olivia Juarez Knudsen, Deven Stephens, Michelle Stephens Original Music: micah dahl anderson - www.micahdahl.com Special thanks to Joe, Jared, Zara, and the Punchut/Typophile crew for enabling this!</description>
91  <link>http://vimeo.com/moogaloop.swf?clip_id=6382511&amp;autoplay=1</link>
92  <media:group>
93  <media:thumbnail url='http://ats.vimeo.com/238/418/23841853_200.jpg'/>
94  <media:content url='http://vimeo.com/moogaloop.swf?clip_id=6382511&amp;autoplay=1' duration='221' width='640' height='352' lang=''/>
95  </media:group>
96  <rating>3233</rating>
97  </item>
98 ...
99  <item>
100  <title>"The Dragon's Claw" by Justice of the Unicorns</title>
101  <author>Robert Bruce</author>
102  <pubDate>Mon, 20 Apr 2009 08:10:32 GMT</pubDate>
103  <description>"The Dragon's Claw" The official music video for Justice of the Unicorns from the album "Angels with Uzis". Winner of Best Music Video at the 2009 Animation Block Party. http://justiceoftheunicorns.com Animated in Flash. Composited in Combustion. Get your free Cubeecraft Bunny Toy! http://robbruce.blogspot.com/2009/05/mutant-pmp-bunny-of-your-very-own.html robthebruce.com Please feel free to email me for rate quotes, questions, answers, weather reports, cookie recipes, or just to say hi. rob@robthebruce.com</description>
104  <link>http://vimeo.com/moogaloop.swf?clip_id=4239300&amp;autoplay=1</link>
105  <media:group>
106  <media:thumbnail url='http://ats.vimeo.com/926/443/9264438_200.jpg'/>
107  <media:content url='http://vimeo.com/moogaloop.swf?clip_id=4239300&amp;autoplay=1' duration='206' width='640' height='368' lang=''/>
108  </media:group>
109  <rating>47</rating>
110  </item>
111  </channel>
112 </rss>
113 
114 (Option return Tree view)
115 > ./vimeo.py -T
116 <?xml version="1.0" encoding="UTF-8"?>
117 <rss version="2.0"
118 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
119 xmlns:content="http://purl.org/rss/1.0/modules/content/"
120 xmlns:cnettv="http://cnettv.com/mrss/"
121 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
122 xmlns:media="http://search.yahoo.com/mrss/"
123 xmlns:atom="http://www.w3.org/2005/Atom"
124 xmlns:amp="http://www.adobe.com/amp/1.0"
125 xmlns:dc="http://purl.org/dc/elements/1.1/">
126  <channel>
127  <title>Vimeo</title>
128  <link>http://vimeo.com</link>
129  <description>Vimeo is a respectful community of creative people who are passionate about sharing the videos they make.</description>
130  <numresults>18</numresults>
131  <returned>1</returned>
132  <startindex>0</startindex>
133  <directory name="Newest Channels/Most ..." thumbnail="/usr/local/share/mythtv/mythnetvision/icons/vimeo.png">
134  <directory name="Most Recent Channels" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/most_recent.png">
135  <item>
136  <title>PSA 1: Family Meal is a Healthy Meal</title>
137  <author>Kevin Shermach</author>
138  <pubDate>Tue, 05 Jan 2010 13:08:56 GMT</pubDate>
139  <description>Channel "NYC YMCA new PSA Campaign": :30, :15 and :10</description>
140  <link>http://vimeo.com/moogaloop.swf?clip_id=8557253&amp;autoplay=1</link>
141  <media:group>
142  <media:thumbnail url='http://ts.vimeo.com.s3.amazonaws.com/402/131/40213146_200.jpg'/>
143  <media:content url='http://vimeo.com/moogaloop.swf?clip_id=8557253&amp;autoplay=1' duration='60' width='480' height='272' lang=''/>
144  </media:group>
145  <rating>0</rating>
146  </item>
147 ...
148  <item>
149  <title>NIN Sydney 2.24.09 - Mid-show Power Outage [HD]</title>
150  <author>Nine Inch Nails</author>
151  <pubDate>Tue, 24 Feb 2009 13:58:19 GMT</pubDate>
152  <description>Power in the Hordern Pavilion went out midway through the set, forcing the show to stop for 40 minutes and nearly causing it to be canceled. Filmed by Rob Sheridan with the Canon 5D Mark II.</description>
153  <link>http://vimeo.com/moogaloop.swf?clip_id=3353364&amp;autoplay=1</link>
154  <media:group>
155  <media:thumbnail url='http://ats.vimeo.com/240/077/2400771_200.jpg'/>
156  <media:content url='http://vimeo.com/moogaloop.swf?clip_id=3353364&amp;autoplay=1' duration='268' width='504' height='284' lang=''/>
157  </media:group>
158  <rating>216</rating>
159  </item>
160  </directory>
161  </directory>
162  </directory>
163  </channel>
164 </rss>
165 '''
166 __search_max_page_items__ = 20
167 __tree_max_page_items__ = 20
168 
169 import sys, os
170 
171 class OutStreamEncoder(object):
172  """Wraps a stream with an encoder
173  """
174  def __init__(self, outstream, encoding=None):
175  self.out = outstream
176  if not encoding:
177  self.encoding = sys.getfilesystemencoding()
178  else:
179  self.encoding = encoding
180 
181  def write(self, obj):
182  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
183  if isinstance(obj, unicode):
184  self.out.write(obj.encode(self.encoding))
185  else:
186  self.out.write(obj)
187 
188  def __getattr__(self, attr):
189  """Delegate everything but write to the stream"""
190  return getattr(self.out, attr)
191 # Sub class sys.stdout and sys.stderr as a utf8 stream. Deals with print and stdout unicode issues
192 sys.stdout = OutStreamEncoder(sys.stdout)
193 sys.stderr = OutStreamEncoder(sys.stderr)
194 
195 # Makes it easier to debug. Comment out for production
196 #import nv_python_libs.vimeo.vimeo_api as target
197 
198 # Verify that the tmdb_api modules are installed and accessible
199 try:
200  import nv_python_libs.vimeo.vimeo_api as target
201 except Exception,e:
202  sys.stderr.write('''
203 The subdirectory "nv_python_libs/vimeo" containing the modules vimeo_api.py (v0.2.0 or greater),
204 They should have been included with the distribution of vimeo.py.
205 Error(%s)
206 ''' % e)
207  sys.exit(1)
208 
209 if target.__version__ < '0.2.0':
210  sys.stderr.write("\n! Error: Your current installed vimeo_api.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % target.__version__)
211  sys.exit(1)
212 
213 
214 # Makes it easier to debug. Comment out for production
215 import nv_python_libs.mainProcess as process
216 
217 
218 # Verify that the common process modules are installed and accessible
219 try:
220  import nv_python_libs.mainProcess as process
221 except Exception, e:
222  sys.stderr.write('''
223 The python script "nv_python_libs/mainProcess.py" must be present.
224 Error(%s)
225 ''' % e)
226  sys.exit(1)
227 
228 if process.__version__ < '0.2.0':
229  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__)
230  sys.exit(1)
231 
232 if __name__ == '__main__':
233  # No api key is required
234  apikey = ""
235  main = process.mainProcess(target, apikey, )
236  main.grabberInfo = {}
237  main.grabberInfo['title'] = __title__
238  main.grabberInfo['command'] = u'vimeo.py'
239  main.grabberInfo['author'] = __author__
240  main.grabberInfo['thumbnail'] = 'vimeo.png'
241  main.grabberInfo['type'] = ['video']
242  main.grabberInfo['desc'] = u"Vimeo is a respectful community of creative people who are passionate about sharing the videos they make."
243  main.grabberInfo['version'] = __version__
244  main.grabberInfo['search'] = True
245  main.grabberInfo['tree'] = True
246  main.grabberInfo['html'] = False
247  main.grabberInfo['usage'] = __usage_examples__
248  main.grabberInfo['SmaxPage'] = __search_max_page_items__
249  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
250  main.main()
def __init__(self, outstream, encoding=None)
Definition: vimeo.py:174
def __getattr__(self, attr)
Definition: vimeo.py:188
def write(self, obj)
Definition: vimeo.py:181