00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 __title__ ="YouTube";
00029 __author__="R.D. Vaughan"
00030 __version__="0.23"
00031
00032
00033
00034
00035
00036
00037
00038
00039 __usage_examples__ ='''
00040 (Option Help)
00041 > ./youtube.py -h
00042 Usage: ./youtube.py -hduvlST [parameters] <search text>
00043 Version: v0.2.0 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 youtube for videos matching search words)
00068 > ./youtube.py -S "Buckethead" -p 2
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>YouTube</title>
00081 <link>http://www.youtube.com/</link>
00082 <description>Share your videos with friends, family, and the world.</description>
00083 <numresults>2092</numresults>
00084 <returned>20</returned>
00085 <startindex>40</startindex>
00086 <item>
00087 <title>Buckethead and Brain Jam [original video]</title>
00088 <author>bunghole30</author>
00089 <pubDate>Sat, 20 Sep 2008 20:37:42 GMT</pubDate>
00090 <description>Hey guy's ;) \m/ Here, we have a video of Buckethead along with Brain, havin a jam session along with a few Buckethead binge buddy antics, please enjoy www.bucketheadland.com www.tdrsmusic.com -bunghole \m/</description>
00091 <link>http://www.youtube.com/v/S7l3L6Ikb9M?f=videos&app=youtube_gdata&autoplay=1</link>
00092 <media:group>
00093 <media:thumbnail url='http://i.ytimg.com/vi/S7l3L6Ikb9M/0.jpg'/>
00094 <media:content url='http://www.youtube.com/v/S7l3L6Ikb9M?f=videos&app=youtube_gdata&autoplay=1' duration='399' width='' height='' lang=''/>
00095 </media:group>
00096 <rating>4.941772</rating>
00097 </item>
00098 ...
00099 <item>
00100 <title>Slap That Bass, Buckethead</title>
00101 <author>R41N570RM</author>
00102 <pubDate>Fri, 29 Jun 2007 01:25:40 GMT</pubDate>
00103 <description>Buckethead on Bass Slappin' and Maximum Bob with Willie T. From Secret Recipe</description>
00104 <link>http://www.youtube.com/v/0QA-1EeVLvg?f=videos&app=youtube_gdata&autoplay=1</link>
00105 <media:group>
00106 <media:thumbnail url='http://i.ytimg.com/vi/0QA-1EeVLvg/0.jpg'/>
00107 <media:content url='http://www.youtube.com/v/0QA-1EeVLvg?f=videos&app=youtube_gdata&autoplay=1' duration='111' width='' height='' lang=''/>
00108 </media:group>
00109 <rating>4.890556</rating>
00110 </item>
00111 </channel>
00112 </rss>
00113
00114
00115 (Retrieve a Tree View of the YouTube Video Categories)
00116 > ./youtube.py -T
00117 <?xml version="1.0" encoding="UTF-8"?>
00118 <rss version="2.0"
00119 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00120 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00121 xmlns:cnettv="http://cnettv.com/mrss/"
00122 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00123 xmlns:media="http://search.yahoo.com/mrss/"
00124 xmlns:atom="http://www.w3.org/2005/Atom"
00125 xmlns:amp="http://www.adobe.com/amp/1.0"
00126 xmlns:dc="http://purl.org/dc/elements/1.1/">
00127 <channel>
00128 <title>YouTube</title>
00129 <link>http://www.youtube.com/</link>
00130 <description>Share your videos with friends, family, and the world.</description>
00131 <numresults>13239230</numresults>
00132 <returned>20</returned>
00133 <startindex>20</startindex>
00134 <directory name="Feeds" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/youtube.png">
00135 <directory name="Highest Rated" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/rated.png">
00136 <item>
00137 <title>Project for Awesome - My Public Access Channel!</title>
00138 <author>peron75</author>
00139 <pubDate>Thu, 17 Dec 2009 13:51:34 GMT</pubDate>
00140 <description>Please support all the Project for Awesome videos today with ratings/comments! Thank you! Thank you to Hank and John Green, Dan Brown and everyone involved!!! I chose the public access station where I began What the Buck! They are fundraising to help with their new building project. You can help buy simply signing up for this site and then when you shop, they get donations from that! Yay! Thanks if you can sign up! (its Free!) LOL xoxo Michael Please sign up: http://igive.com/wpaa</description>
00141 <link>http://www.youtube.com/v/tdBHzkoXB_8?f=standard&app=youtube_gdata&autoplay=1</link>
00142 <media:group>
00143 <media:thumbnail url='http://i.ytimg.com/vi/tdBHzkoXB_8/hqdefault.jpg'/>
00144 <media:content url='http://www.youtube.com/v/tdBHzkoXB_8?f=standard&app=youtube_gdata&autoplay=1' duration='259' width='' height='' lang=''/>
00145 </media:group>
00146 <rating>4.972514</rating>
00147 </item>
00148 ...
00149 <item>
00150 <title>Harry Chapin--Taxi</title>
00151 <author>Lewismadmax</author>
00152 <pubDate>Fri, 04 May 2007 21:10:00 GMT</pubDate>
00153 <description>"Baby's so high that shes skying, yeah she's flying afraid to fall, I'll tell you why Baby's crying, cuz' she's dying arent we all". The greatest person to fight world hunger died in 1982 God bless Harry Chapin.</description>
00154 <link>http://www.youtube.com/v/c5dwksSbD34?f=videos&app=youtube_gdata&autoplay=1</link>
00155 <media:group>
00156 <media:thumbnail url='http://i.ytimg.com/vi/c5dwksSbD34/hqdefault.jpg'/>
00157 <media:content url='http://www.youtube.com/v/c5dwksSbD34?f=videos&app=youtube_gdata&autoplay=1' duration='401' width='' height='' lang=''/>
00158 </media:group>
00159 <rating>4.9039855</rating>
00160 </item>
00161 </directory>
00162 </directory>
00163 </channel>
00164 </rss>
00165 '''
00166 __search_max_page_items__ = 10
00167 __tree_max_page_items__ = 20
00168
00169 import sys, os
00170
00171 class OutStreamEncoder(object):
00172 """Wraps a stream with an encoder"""
00173 def __init__(self, outstream, encoding=None):
00174 self.out = outstream
00175 if not encoding:
00176 self.encoding = sys.getfilesystemencoding()
00177 else:
00178 self.encoding = encoding
00179
00180 def write(self, obj):
00181 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00182 if isinstance(obj, unicode):
00183 try:
00184 self.out.write(obj.encode(self.encoding))
00185 except IOError:
00186 pass
00187 else:
00188 try:
00189 self.out.write(obj)
00190 except IOError:
00191 pass
00192
00193 def __getattr__(self, attr):
00194 """Delegate everything but write to the stream"""
00195 return getattr(self.out, attr)
00196 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
00197 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
00198
00199
00200
00201
00202
00203 try:
00204 import nv_python_libs.youtube.youtube_api as target
00205 except Exception, e:
00206 sys.stderr.write('''
00207 The subdirectory "nv_python_libs/youtube" containing the modules youtube_api.py (v0.2.0 or greater),
00208 They should have been included with the distribution of youtube.py.
00209 Error(%s)
00210 ''' % e)
00211 sys.exit(1)
00212
00213 if target.__version__ < '0.2.0':
00214 sys.stderr.write("\n! Error: Your current installed youtube_api.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % target.__version__)
00215 sys.exit(1)
00216
00217
00218
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
00234 apikey = ""
00235 main = process.mainProcess(target, apikey, )
00236 main.grabberInfo = {}
00237 main.grabberInfo['title'] = __title__
00238 main.grabberInfo['command'] = u'youtube.py'
00239 main.grabberInfo['author'] = __author__
00240 main.grabberInfo['thumbnail'] = 'youtube.png'
00241 main.grabberInfo['type'] = ['video']
00242 main.grabberInfo['desc'] = u"Share your videos with friends, family, and the world."
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()