MythTV  0.26-pre
vimeo.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: UTF-8 -*-
00003 # ----------------------
00004 # Name: vimeo.py
00005 # Python Script
00006 # Author: R.D. Vaughan
00007 # Purpose:
00008 #   This python script is intended to perform vimeo.com lookups for the MythTV Netvision plugin
00009 #   based on information found on the http://vimeo.com/ website. It
00010 #   follows the MythTV Netvision grabber standards.
00011 #   This script uses the python module vimeo.py which should be included
00012 #   with this script.
00013 #   The vimeo.py module uses the full access API v2 api published by
00014 #   http://vimeo.com/ see: http://vimeo.com/api/docs/advanced-api
00015 #   Users of this script are encouraged to populate vimeo.com with your own Videos. The richer the source the
00016 #   more valuable the script.
00017 # Command example:
00018 # See help (-u and -h) options
00019 #
00020 # Design:
00021 #   1) Import the specific target site API library.
00022 #   2) Set the title for the scrips and the API optional key for the target video site
00023 #   3) Call the common processing routine
00024 #
00025 #
00026 # License:Creative Commons GNU GPL v2
00027 # (http://creativecommons.org/licenses/GPL/2.0/)
00028 #-------------------------------------
00029 __title__ ="Vimeo";
00030 __author__="R.D. Vaughan"
00031 __version__="0.23"
00032 # 0.1.0 Initial development
00033 # 0.1.1 Added the Tree view option
00034 # 0.1.2 Documentation review
00035 # 0.2.0 Public release
00036 # 0.2.1 Improved error display messages on an exception abort
00037 # 0.22  Change to support xml version information display
00038 # 0.23  Added the "command" tag to the xml version information display
00039 
00040 __usage_examples__ ='''
00041 > ./vimeo.py -h
00042 Usage: ./vimeo.py -hduvlST [parameters] <search text>
00043 Version: v0.22 Author: R.D.Vaughan
00044 
00045 For details on the MythTV Netvision plugin see the wiki page at:
00046 http://www.mythtv.org/wiki/MythNetvision
00047 
00048 Options:
00049   -h, --help            show this help message and exit
00050   -d, --debug           Show debugging info (URLs, raw XML ... etc, info
00051                         varies per grabber)
00052   -u, --usage           Display examples for executing the script
00053   -v, --version         Display grabber name and supported options
00054   -l LANGUAGE, --language=LANGUAGE
00055                         Select data that matches the specified language fall
00056                         back to English if nothing found (e.g. 'es' Español,
00057                         'de' Deutsch ... etc). Not all sites or grabbers
00058                         support this option.
00059   -p PAGE NUMBER, --pagenumber=PAGE NUMBER
00060                         Display specific page of the search results. Default
00061                         is page 1. Page number is ignored with the Tree View
00062                         option (-T).
00063   -S, --search          Search for videos
00064   -T, --treeview        Display a Tree View of a sites videos
00065 
00066 
00067 (Search for all videos identified with the word "Dragon")
00068 > ./vimeo.py -p 1 -S "Dragon"
00069 <?xml version="1.0" encoding="UTF-8"?>
00070 <rss version="2.0"
00071 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00072 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00073 xmlns:cnettv="http://cnettv.com/mrss/"
00074 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00075 xmlns:media="http://search.yahoo.com/mrss/"
00076 xmlns:atom="http://www.w3.org/2005/Atom"
00077 xmlns:amp="http://www.adobe.com/amp/1.0"
00078 xmlns:dc="http://purl.org/dc/elements/1.1/">
00079     <channel>
00080         <title>Vimeo</title>
00081         <link>http://vimeo.com</link>
00082         <description>Vimeo is a respectful community of creative people who are passionate about sharing the videos they make.</description>
00083         <numresults>4856</numresults>
00084         <returned>20</returned>
00085         <startindex>20</startindex>
00086         <item>
00087             <title>Typophile Film Festival 5 Opening Titles</title>
00088             <author>Brent Barson</author>
00089             <pubDate>Tue, 01 Sep 2009 12:27:46 GMT</pubDate>
00090             <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>
00091             <link>http://vimeo.com/moogaloop.swf?clip_id=6382511&amp;autoplay=1</link>
00092             <media:group>
00093                 <media:thumbnail url='http://ats.vimeo.com/238/418/23841853_200.jpg'/>
00094                 <media:content url='http://vimeo.com/moogaloop.swf?clip_id=6382511&amp;autoplay=1' duration='221' width='640' height='352' lang=''/>
00095             </media:group>
00096             <rating>3233</rating>
00097         </item>
00098 ...
00099         <item>
00100             <title>"The Dragon's Claw" by Justice of the Unicorns</title>
00101             <author>Robert Bruce</author>
00102             <pubDate>Mon, 20 Apr 2009 08:10:32 GMT</pubDate>
00103             <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>
00104             <link>http://vimeo.com/moogaloop.swf?clip_id=4239300&amp;autoplay=1</link>
00105             <media:group>
00106                 <media:thumbnail url='http://ats.vimeo.com/926/443/9264438_200.jpg'/>
00107                 <media:content url='http://vimeo.com/moogaloop.swf?clip_id=4239300&amp;autoplay=1' duration='206' width='640' height='368' lang=''/>
00108             </media:group>
00109             <rating>47</rating>
00110         </item>
00111     </channel>
00112 </rss>
00113 
00114 (Option return Tree view)
00115 > ./vimeo.py -T
00116 <?xml version="1.0" encoding="UTF-8"?>
00117 <rss version="2.0"
00118 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00119 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00120 xmlns:cnettv="http://cnettv.com/mrss/"
00121 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00122 xmlns:media="http://search.yahoo.com/mrss/"
00123 xmlns:atom="http://www.w3.org/2005/Atom"
00124 xmlns:amp="http://www.adobe.com/amp/1.0"
00125 xmlns:dc="http://purl.org/dc/elements/1.1/">
00126     <channel>
00127         <title>Vimeo</title>
00128         <link>http://vimeo.com</link>
00129         <description>Vimeo is a respectful community of creative people who are passionate about sharing the videos they make.</description>
00130         <numresults>18</numresults>
00131         <returned>1</returned>
00132         <startindex>0</startindex>
00133             <directory name="Newest Channels/Most ..." thumbnail="/usr/local/share/mythtv/mythnetvision/icons/vimeo.png">
00134             <directory name="Most Recent Channels" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/most_recent.png">
00135                 <item>
00136                     <title>PSA 1: Family Meal is a Healthy Meal</title>
00137                     <author>Kevin Shermach</author>
00138                     <pubDate>Tue, 05 Jan 2010 13:08:56 GMT</pubDate>
00139                     <description>Channel "NYC YMCA new PSA Campaign": :30, :15 and :10</description>
00140                     <link>http://vimeo.com/moogaloop.swf?clip_id=8557253&amp;autoplay=1</link>
00141                     <media:group>
00142                         <media:thumbnail url='http://ts.vimeo.com.s3.amazonaws.com/402/131/40213146_200.jpg'/>
00143                         <media:content url='http://vimeo.com/moogaloop.swf?clip_id=8557253&amp;autoplay=1' duration='60' width='480' height='272' lang=''/>
00144                     </media:group>
00145                     <rating>0</rating>
00146                 </item>
00147 ...
00148                 <item>
00149                     <title>NIN Sydney 2.24.09 - Mid-show Power Outage [HD]</title>
00150                     <author>Nine Inch Nails</author>
00151                     <pubDate>Tue, 24 Feb 2009 13:58:19 GMT</pubDate>
00152                     <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>
00153                     <link>http://vimeo.com/moogaloop.swf?clip_id=3353364&amp;autoplay=1</link>
00154                     <media:group>
00155                         <media:thumbnail url='http://ats.vimeo.com/240/077/2400771_200.jpg'/>
00156                         <media:content url='http://vimeo.com/moogaloop.swf?clip_id=3353364&amp;autoplay=1' duration='268' width='504' height='284' lang=''/>
00157                     </media:group>
00158                     <rating>216</rating>
00159                 </item>
00160             </directory>
00161             </directory>
00162             </directory>
00163     </channel>
00164 </rss>
00165 '''
00166 __search_max_page_items__ = 20
00167 __tree_max_page_items__ = 20
00168 
00169 import sys, os
00170 
00171 class OutStreamEncoder(object):
00172     """Wraps a stream with an encoder
00173     """
00174     def __init__(self, outstream, encoding=None):
00175         self.out = outstream
00176         if not encoding:
00177             self.encoding = sys.getfilesystemencoding()
00178         else:
00179             self.encoding = encoding
00180 
00181     def write(self, obj):
00182         """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00183         if isinstance(obj, unicode):
00184             self.out.write(obj.encode(self.encoding))
00185         else:
00186             self.out.write(obj)
00187 
00188     def __getattr__(self, attr):
00189         """Delegate everything but write to the stream"""
00190         return getattr(self.out, attr)
00191 # Sub class sys.stdout and sys.stderr as a utf8 stream. Deals with print and stdout unicode issues
00192 sys.stdout = OutStreamEncoder(sys.stdout)
00193 sys.stderr = OutStreamEncoder(sys.stderr)
00194 
00195 # Makes it easier to debug. Comment out for production
00196 #import nv_python_libs.vimeo.vimeo_api as target
00197 
00198 # Verify that the tmdb_api modules are installed and accessable
00199 try:
00200     import nv_python_libs.vimeo.vimeo_api as target
00201 except Exception,e:
00202     sys.stderr.write('''
00203 The subdirectory "nv_python_libs/vimeo" containing the modules vimeo_api.py (v0.2.0 or greater),
00204 They should have been included with the distribution of vimeo.py.
00205 Error(%s)
00206 ''' % e)
00207     sys.exit(1)
00208 
00209 if target.__version__ < '0.2.0':
00210     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__)
00211     sys.exit(1)
00212 
00213 
00214 # Makes it easier to debug. Comment out for production
00215 import nv_python_libs.mainProcess as process
00216 
00217 
00218 # Verify that the common process modules are installed and accessable
00219 try:
00220     import nv_python_libs.mainProcess as process
00221 except Exception, e:
00222     sys.stderr.write('''
00223 The python script "nv_python_libs/mainProcess.py" must be present.
00224 Error(%s)
00225 ''' % e)
00226     sys.exit(1)
00227 
00228 if process.__version__ < '0.2.0':
00229     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__)
00230     sys.exit(1)
00231 
00232 if __name__ == '__main__':
00233     # No api key is required
00234     apikey = ""
00235     main = process.mainProcess(target, apikey, )
00236     main.grabberInfo = {}
00237     main.grabberInfo['title'] = __title__
00238     main.grabberInfo['command'] = u'vimeo.py'
00239     main.grabberInfo['author'] = __author__
00240     main.grabberInfo['thumbnail'] = 'vimeo.png'
00241     main.grabberInfo['type'] = ['video']
00242     main.grabberInfo['desc'] = u"Vimeo is a respectful community of creative people who are passionate about sharing the videos they make."
00243     main.grabberInfo['version'] = __version__
00244     main.grabberInfo['search'] = True
00245     main.grabberInfo['tree'] = True
00246     main.grabberInfo['html'] = False
00247     main.grabberInfo['usage'] = __usage_examples__
00248     main.grabberInfo['SmaxPage'] = __search_max_page_items__
00249     main.grabberInfo['TmaxPage'] = __tree_max_page_items__
00250     main.main()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends