MythTV master
youtube.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: UTF-8 -*-
3# ----------------------
4# Name: youtube.py
5# Python Script
6# Author: R.D. Vaughan
7# Purpose:
8# This python script is intended to perform youtube video lookups for the MythTV Netvision plugin
9# based on information found on the http://www.youtube.com/ website. It
10# follows the MythTV Netvision grabber standards.
11# This script uses the python module youtube_api.py which should be included
12# with this script.
13# The youtube.py module uses the full access API published by
14# http://www.youtube.com/ see: http://developer.youtubenservices.com/docs
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 scrips and the API optional key 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__ ="YouTube";
29__author__="R.D. Vaughan"
30__version__="0.23"
31# 0.1.0 Initial development
32# 0.1.1 Added the Tree view option
33# 0.1.2 Documentation review
34# 0.2.0 Public release
35# 0.2.1 Completed abort exception display message improvements
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__ =r'''
40(Option Help)
41> ./youtube.py -h
42Usage: ./youtube.py -hduvlST [parameters] <search text>
43Version: v0.2.0 Author: R.D.Vaughan
44
45For details on the MythTV Netvision plugin see the wiki page at:
46http://www.mythtv.org/wiki/MythNetvision
47
48Options:
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 youtube for videos matching search words)
68> ./youtube.py -S "Buckethead" -p 2
69<?xml version="1.0" encoding="UTF-8"?>
70<rss version="2.0"
71xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
72xmlns:content="http://purl.org/rss/1.0/modules/content/"
73xmlns:cnettv="http://cnettv.com/mrss/"
74xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
75xmlns:media="http://search.yahoo.com/mrss/"
76xmlns:atom="http://www.w3.org/2005/Atom"
77xmlns:amp="http://www.adobe.com/amp/1.0"
78xmlns:dc="http://purl.org/dc/elements/1.1/">
79 <channel>
80 <title>YouTube</title>
81 <link>http://www.youtube.com/</link>
82 <description>Share your videos with friends, family, and the world.</description>
83 <numresults>2092</numresults>
84 <returned>20</returned>
85 <startindex>40</startindex>
86 <item>
87 <title>Buckethead and Brain Jam [original video]</title>
88 <author>bunghole30</author>
89 <pubDate>Sat, 20 Sep 2008 20:37:42 GMT</pubDate>
90 <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>
91 <link>http://www.youtube.com/v/S7l3L6Ikb9M?f=videos&amp;app=youtube_gdata&amp;autoplay=1</link>
92 <media:group>
93 <media:thumbnail url='http://i.ytimg.com/vi/S7l3L6Ikb9M/0.jpg'/>
94 <media:content url='http://www.youtube.com/v/S7l3L6Ikb9M?f=videos&amp;app=youtube_gdata&amp;autoplay=1' duration='399' width='' height='' lang=''/>
95 </media:group>
96 <rating>4.941772</rating>
97 </item>
98...
99 <item>
100 <title>Slap That Bass, Buckethead</title>
101 <author>R41N570RM</author>
102 <pubDate>Fri, 29 Jun 2007 01:25:40 GMT</pubDate>
103 <description>Buckethead on Bass Slappin' and Maximum Bob with Willie T. From Secret Recipe</description>
104 <link>http://www.youtube.com/v/0QA-1EeVLvg?f=videos&amp;app=youtube_gdata&amp;autoplay=1</link>
105 <media:group>
106 <media:thumbnail url='http://i.ytimg.com/vi/0QA-1EeVLvg/0.jpg'/>
107 <media:content url='http://www.youtube.com/v/0QA-1EeVLvg?f=videos&amp;app=youtube_gdata&amp;autoplay=1' duration='111' width='' height='' lang=''/>
108 </media:group>
109 <rating>4.890556</rating>
110 </item>
111 </channel>
112</rss>
113
114
115(Retrieve a Tree View of the YouTube Video Categories)
116> ./youtube.py -T
117<?xml version="1.0" encoding="UTF-8"?>
118<rss version="2.0"
119xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
120xmlns:content="http://purl.org/rss/1.0/modules/content/"
121xmlns:cnettv="http://cnettv.com/mrss/"
122xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
123xmlns:media="http://search.yahoo.com/mrss/"
124xmlns:atom="http://www.w3.org/2005/Atom"
125xmlns:amp="http://www.adobe.com/amp/1.0"
126xmlns:dc="http://purl.org/dc/elements/1.1/">
127 <channel>
128 <title>YouTube</title>
129 <link>http://www.youtube.com/</link>
130 <description>Share your videos with friends, family, and the world.</description>
131 <numresults>13239230</numresults>
132 <returned>20</returned>
133 <startindex>20</startindex>
134 <directory name="Feeds" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/youtube.png">
135 <directory name="Highest Rated" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/rated.png">
136 <item>
137 <title>Project for Awesome - My Public Access Channel!</title>
138 <author>peron75</author>
139 <pubDate>Thu, 17 Dec 2009 13:51:34 GMT</pubDate>
140 <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>
141 <link>http://www.youtube.com/v/tdBHzkoXB_8?f=standard&amp;app=youtube_gdata&amp;autoplay=1</link>
142 <media:group>
143 <media:thumbnail url='http://i.ytimg.com/vi/tdBHzkoXB_8/hqdefault.jpg'/>
144 <media:content url='http://www.youtube.com/v/tdBHzkoXB_8?f=standard&amp;app=youtube_gdata&amp;autoplay=1' duration='259' width='' height='' lang=''/>
145 </media:group>
146 <rating>4.972514</rating>
147 </item>
148...
149 <item>
150 <title>Harry Chapin--Taxi</title>
151 <author>Lewismadmax</author>
152 <pubDate>Fri, 04 May 2007 21:10:00 GMT</pubDate>
153 <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>
154 <link>http://www.youtube.com/v/c5dwksSbD34?f=videos&amp;app=youtube_gdata&amp;autoplay=1</link>
155 <media:group>
156 <media:thumbnail url='http://i.ytimg.com/vi/c5dwksSbD34/hqdefault.jpg'/>
157 <media:content url='http://www.youtube.com/v/c5dwksSbD34?f=videos&amp;app=youtube_gdata&amp;autoplay=1' duration='401' width='' height='' lang=''/>
158 </media:group>
159 <rating>4.9039855</rating>
160 </item>
161 </directory>
162 </directory>
163 </channel>
164</rss>
165'''
166__search_max_page_items__ = 10
167__tree_max_page_items__ = 20
168
169import sys, os
170
171# Used for debugging
172#import nv_python_libs.youtube.youtube_api as target
173
174# Verify that the tmdb_api modules are installed and accessible
175try:
177except Exception as e:
178 sys.stderr.write('''
179The subdirectory "nv_python_libs/youtube" containing the modules youtube_api.py (v0.2.0 or greater),
180They should have been included with the distribution of youtube.py.
181Error(%s)
182''' % e)
183 sys.exit(1)
184
185if target.__version__ < '0.2.0':
186 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__)
187 sys.exit(1)
188
189
190# Verify that the common process modules are installed and accessible
191try:
192 import nv_python_libs.mainProcess as process
193except Exception as e:
194 sys.stderr.write('''
195The python script "nv_python_libs/mainProcess.py" must be present.
196Error(%s)
197''' % e)
198 sys.exit(1)
199
200if process.__version__ < '0.2.0':
201 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__)
202 sys.exit(1)
203
204if __name__ == '__main__':
205 apikey = ""
206 # Set the base processing directory that the grabber is installed
207 target.baseProcessingDir = os.path.dirname( os.path.realpath(__file__))
208 main = process.mainProcess(target, apikey, )
209 main.grabberInfo = {}
210 main.grabberInfo['enabled'] = True
211 main.grabberInfo['title'] = __title__
212 main.grabberInfo['command'] = 'youtube.py'
213 main.grabberInfo['author'] = __author__
214 main.grabberInfo['thumbnail'] = 'youtube.png'
215 main.grabberInfo['type'] = ['video']
216 main.grabberInfo['desc'] = "Share your videos with friends, family, and the world."
217 main.grabberInfo['version'] = __version__
218 main.grabberInfo['search'] = True
219 main.grabberInfo['tree'] = True
220 main.grabberInfo['html'] = False
221 main.grabberInfo['usage'] = __usage_examples__
222 main.grabberInfo['SmaxPage'] = __search_max_page_items__
223 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
224 main.main()