15 __title__ =
"dailymotion_api - Simple-to-use Python interface to the dailymotion API (http://www.dailymotion.com/ca-en/doc/api/player)"
16 __author__=
"R.D. Vaughan"
18 This python script is intended to perform a variety of utility functions to search and access text
19 meta data, video and image URLs from dailymotion. These routines are based on the api. Specifications
20 for this api are published at http://www.dailymotion.com/ca-en/doc/api/player
37 import os, struct, sys, re, time
38 import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse
40 from MythTV
import MythXML
43 import xml.etree.cElementTree
as ElementTree
45 import xml.etree.ElementTree
as ElementTree
47 from .dailymotion_exceptions
import (DailymotionUrlError, DailymotionHttpError, DailymotionRssError, DailymotionVideoNotFound, DailymotionInvalidSearchType, DailymotionXmlError, DailymotionVideoDetailError, DailymotionCategoryNotFound)
51 """Wraps a stream with an encoder"""
60 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
61 if isinstance(obj, str):
63 self.
out.buffer.write(obj)
66 """Delegate everything but write to the stream"""
67 return getattr(self.
out, attr)
69 if isinstance(sys.stdout, io.TextIOWrapper):
75 """Deals with retrieval of XML files from API
82 urlhandle = urllib.request.urlopen(url)
83 except IOError
as errormsg:
85 return urlhandle.read()
90 et = ElementTree.fromstring(xml)
91 except SyntaxError
as errormsg:
97 """Main interface to http://www.dailymotion.com
98 This is done to support a common naming framework for all python Netvision plugins no matter their site
101 Supports search and tree view methods
102 The apikey is a not required to access http://www.dailymotion.com
108 select_first = False,
112 search_all_languages = False,
114 """apikey (str/unicode):
115 Specify the target site API key. Applications need their own key in some cases
118 When True, the returned meta data is being returned has the key and values massaged to match MythTV
119 When False, the returned meta data is being returned matches what target site returned
121 interactive (True/False): (This option is not supported by all target site apis)
122 When True, uses built-in console UI is used to select the correct show.
123 When False, the first search result is used.
125 select_first (True/False): (This option is not supported currently implemented in any grabbers)
126 Automatically selects the first series search result (rather
127 than showing the user a list of more than one series).
128 Is overridden by interactive = False, or specifying a custom_ui
131 shows verbose debugging information
133 custom_ui (xx_ui.BaseUI subclass): (This option is not supported currently implemented in any grabbers)
134 A callable subclass of interactive class (overrides interactive option)
136 language (2 character language abbreviation): (This option is not supported by all target site apis)
137 The language of the returned data. Is also the language search
138 uses. Default is "en" (English). For full list, run..
140 search_all_languages (True/False): (This option is not supported by all target site apis)
141 By default, a Netvision grabber will only search in the language specified using
142 the language option. When this is True, it will search for the
149 if apikey
is not None:
150 self.
config[
'apikey'] = apikey
154 self.
config[
'debug_enabled'] = debug
159 self.
config[
'custom_ui'] = custom_ui
163 self.
config[
'select_first'] = select_first
165 self.
config[
'search_all_languages'] = search_all_languages
167 self.
error_messages = {
'DailymotionUrlError':
"! Error: The URL (%s) cause the exception error (%s)\n",
'DailymotionHttpError':
"! Error: An HTTP communicating error with Dailymotion was raised (%s)\n",
'DailymotionRssError':
"! Error: Invalid RSS meta data\nwas received from Dailymotion error (%s). Skipping item.\n",
'DailymotionVideoNotFound':
"! Error: Video search with Dailymotion did not return any results (%s)\n",
'DailymotionVideoDetailError':
"! Error: Invalid Video meta data detail\nwas received from Dailymotion error (%s). Skipping item.\n", }
170 self.
key_translation = [{
'channel_title':
'channel_title',
'channel_link':
'channel_link',
'channel_description':
'channel_description',
'channel_numresults':
'channel_numresults',
'channel_returned':
'channel_returned',
'channel_startindex':
'channel_startindex'}, {
'title':
'item_title',
'author':
'item_author',
'published_parsed':
'item_pubdate',
'media_description':
'item_description',
'video':
'item_link',
'thumbnail':
'item_thumbnail',
'link':
'item_url',
'duration':
'item_duration',
'rating':
'item_rating',
'item_width':
'item_width',
'item_height':
'item_height',
'language':
'item_lang'}]
174 self.
config[
'language'] = language
176 self.
config[
'language'] =
'en'
182 self.
config[
'urls'][
'video.search'] =
'http://www.dailymotion.com/rss/relevance/search/%s/%s'
183 self.
config[
'urls'][
'group.search'] =
'http://www.dailymotion.com/rss/groups/relevance/search/%s/%s'
184 self.
config[
'urls'][
'user.search'] =
'http://www.dailymotion.com/rss/users/relevance/search/%s/%s'
187 self.
config[
'item_parser'] = {}
192 self.
config[
'urls'][
'tree.view'] = {
194 'featured': [
'http://www.dailymotion.com/rss/us/relevance/%s/search/movie/1',
'main'],
195 'creative': [
'http://www.dailymotion.com/rss/us/relevance/%s/search/movie/1',
'main'],
196 'official': [
'http://www.dailymotion.com/rss/us/%s/search/movie/1',
'main'],
197 'hd': [
'http://www.dailymotion.com/rss/relevance/%s/search/movie/1',
'main'],
198 'commented': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
199 'visited': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
200 'rated': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
201 'relevance-month': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
202 'relevance-week': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
203 'relevance-today': [
'http://www.dailymotion.com/rss/us/%s/official/search/movie/1',
'main'],
206 'movie': [
'http://www.dailymotion.com/rss/us/relevance/official/search/%s',
'main'],
207 'comedy': [
'http://www.dailymotion.com/rss/us/relevance/official/search/%s',
'main'],
208 'short+film': [
'http://www.dailymotion.com/rss/creative/relevance/search/%s',
'main'],
209 'television': [
'http://www.dailymotion.com/rss/us/relevance/official/search/%s',
'main'],
210 'documentary': [
'http://www.dailymotion.com/rss/us/relevance/official/search/%s',
'main'],
211 'festival': [
'http://www.dailymotion.com/rss/creative/relevance/search/%s',
'main'],
214 'animals_motionmaker': [
'http://www.dailymotion.com/rss/creative/lang/en/channel/animals/1',
'main'],
215 'animals_most_recent': [
'http://www.dailymotion.com/rss/lang/en/channel/animals/1',
'main'],
216 'animals_hd': [
'http://www.dailymotion.com/rss/hd/channel/animals/1',
'main'],
217 'animals_official_users': [
'http://www.dailymotion.com/rss/official/lang/en/channel/animals/1',
'main'],
218 'animals_most_viewed': [
'http://www.dailymotion.com/rss/visited/lang/en/channel/animals/1',
'main'],
219 'animals_best_rated': [
'http://www.dailymotion.com/rss/rated/lang/en/channel/animals/1',
'main'],
221 'auto_most_recent': [
'http://www.dailymotion.com/rss/lang/en/channel/auto/1',
'main'],
222 'auto_motionmaker': [
'http://www.dailymotion.com/rss/creative/channel/auto/1',
'main'],
223 'auto_most_viewed': [
'http://www.dailymotion.com/rss/visited/lang/en/channel/auto/1',
'main'],
224 'auto_official_users': [
'http://www.dailymotion.com/rss/official/channel/auto/1',
'main'],
226 'film_TV_movie': [
'http://www.dailymotion.com/rss/us/relevance/official/search/movie',
'main'],
227 'film_TV_comedy': [
'http://www.dailymotion.com/rss/us/relevance/official/search/comedy',
'main'],
228 'film_TV_short_film': [
'http://www.dailymotion.com/rss/creative/relevance/search/short+film',
'main'],
229 'film_TV_television': [
'http://www.dailymotion.com/rss/us/relevance/official/search/television',
'main'],
230 'film_TV_documentary': [
'http://www.dailymotion.com/rss/us/relevance/official/search/documentary',
'main'],
231 'film_TV_festival': [
'http://www.dailymotion.com/rss/official/relevance/search/festival',
'main'],
233 'gaming_Trailer': [
'http://www.dailymotion.com/rss/official/search/videogames+trailer/1',
'main'],
234 'gaming_Lego': [
'http://www.dailymotion.com/rss/relevance/search/lego',
'main'],
235 'gaming_Machinima': [
'http://www.dailymotion.com/rss/relevance/creative/search/machinima/1',
'main'],
236 'gaming_Motionmaker': [
'http://www.dailymotion.com/rss/us/creative/channel/videogames/1',
'main'],
237 'gaming_Review': [
'http://www.dailymotion.com/rss/official/search/videogames+review/1',
'main'],
238 'gaming_News': [
'http://www.dailymotion.com/rss/official/search/videogames+news/1',
'main'],
239 'gaming_recent': [
'http://www.dailymotion.com/rss/us/channel/videogames/lang/en/1',
'main'],
240 'gaming_users': [
'http://www.dailymotion.com/rss/us/official/channel/videogames/1',
'main'],
242 'lifestyle_best_rated': [
'http://www.dailymotion.com/rss/rated/lang/en/channel/lifestyle/1',
'main'],
243 'lifestyle_most_commented': [
'http://www.dailymotion.com/rss/commented/lang/en/channel/lifestyle/1',
'main'],
244 'lifestyle_most_viewed': [
'http://www.dailymotion.com/rss/viewed/lang/en/channel/lifestyle/1',
'main'],
245 'lifestyle_HD': [
'http://www.dailymotion.com/rss/hd/lang/en/channel/lifestyle/1',
'main'],
247 'news_politics_Politics': [
'http://www.dailymotion.com/rss/official/relevance/search/politics',
'main'],
248 'news_politics_Celebrity': [
'http://www.dailymotion.com/rss/official/relevance/search/celeb+news',
'main'],
249 'news_politics_official_users': [
'http://www.dailymotion.com/rss/official/search/news/1',
'main'],
250 'news_politics_International': [
'http://www.dailymotion.com/rss/official/search/international+news/1',
'main'],
251 'news_politics_Entertainment': [
'http://www.dailymotion.com/rss/official/search/entertainment+news/1',
'main'],
252 'news_politics_Motionmakers': [
'http://www.dailymotion.com/rss/relevance/creative/search/news/1',
'main'],
254 'sports_extreme_surf': [
'http://www.dailymotion.com/rss/relevance/official/search/surf/1',
'main'],
255 'sports_extreme_baseball': [
'http://www.dailymotion.com/rss/relevance/official/search/baseball',
'main'],
256 'sports_extreme_wrestling': [
'http://www.dailymotion.com/rss/relevance/official/search/wrestling/1',
'main'],
257 'sports_extreme_BMX': [
'http://www.dailymotion.com/rss/relevance/official/search/BMX/1',
'main'],
259 'webcam_vlogs_Most_viewed': [
'http://www.dailymotion.com/rss/visited/channel/webcam/lang/en/1',
'main'],
260 'webcam_vlogs_Featured_videos': [
'http://www.dailymotion.com/rss/us/featured/channel/webcam/1',
'main'],
261 'webcam_vlogs_Best_rated': [
'http://www.dailymotion.com/rss/rated/channel/webcam/lang/en/1',
'main'],
262 'webcam_vlogs_Most_Commented': [
'http://www.dailymotion.com/rss/commented/channel/webcam/lang/en/1',
'main'],
264 'arts_Animation': [
'http://www.dailymotion.com/rss/relevance/creative-official/search/animation',
'main'],
265 'arts_Short_Film': [
'http://www.dailymotion.com/rss/us/relevance/creative/search/shortfilm',
'main'],
266 'arts_Motionmaker': [
'http://www.dailymotion.com/rss/creative-official/lang/en/1',
'main'],
267 'arts_Official_Users': [
'http://www.dailymotion.com/rss/official/channel/creation/lang/en/1',
'main'],
268 'arts_Suede_swede': [
'http://www.dailymotion.com/rss/relevance/creative/search/suede',
'main'],
269 'arts_Most_recent': [
'http://www.dailymotion.com/rss/channel/creation/lang/en/1',
'main'],
271 'college_Most_viewed': [
'http://www.dailymotion.com/rss/visited/channel/school/lang/en/1',
'main'],
272 'college_HD_videos': [
'http://www.dailymotion.com/rss/hd/channel/school/1',
'main'],
273 'college_Best_rated': [
'http://www.dailymotion.com/rss/rated/channel/school/lang/en/1',
'main'],
274 'college_Most_commented': [
'http://www.dailymotion.com/rss/channel/school/lang/en/1',
'main'],
276 'funny_STAND UP': [
'http://www.dailymotion.com/rss/official/relevance/search/standup',
'main'],
277 'funny_Hulu: NBC & Fox': [
'http://www.dailymotion.com/rss/hulu/1',
'main'],
278 'funny_My Damn Channel': [
'http://www.dailymotion.com/rss/mydamnchannel/1',
'main'],
279 'funny_Motionmakers': [
'http://www.dailymotion.com/rss/us/creative/search/comedy/1',
'main'],
280 'funny_Sketch': [
'http://www.dailymotion.com/rss/official/relevance/search/sketch',
'main'],
281 "funny_Nat'l Lampoon": [
'http://www.dailymotion.com/rss/nationallampoon/1',
'main'],
282 'funny_Classic Sitcoms': [
'http://www.dailymotion.com/rss/Classic_WB_TV/1',
'main'],
283 'funny_Official Users': [
'http://www.dailymotion.com/rss/us/official/search/comedy/1',
'main'],
285 'latino_Featured Videos': [
'http://www.dailymotion.com/rss/featured/channel/latino/1',
'main'],
286 'latino_HD content': [
'http://www.dailymotion.com/rss/hd/channel/latino/1',
'main'],
287 'latino_Official Content': [
'http://www.dailymotion.com/rss/official/channel/latino/1',
'main'],
288 'latino_Creative Content': [
'http://www.dailymotion.com/rss/creative/channel/latino/1',
'main'],
289 'latino_Most Commented': [
'http://www.dailymotion.com/rss/commented-week/featured/channel/latino/1',
'main'],
290 'latino_Most Viewed': [
'http://www.dailymotion.com/rss/visited-week/featured/channel/latino/1',
'main'],
291 'latino_Best Rated': [
'http://www.dailymotion.com/rss/rated-week/featured/channel/latino/1',
'main'],
293 'music_Pop': [
'http://www.dailymotion.com/rss/official/relevance/search/pop',
'main'],
294 'music_Rock': [
'http://www.dailymotion.com/rss/relevance/official/search/Rock+Music+Videos/1',
'main'],
295 'music_Jazz': [
'http://www.dailymotion.com/rss/channel/music/official/relevance/search/jazz',
'main'],
296 'music_Covers': [
'http://www.dailymotion.com/rss/channel/us/channel/music/relevance/creative/search/cover/1',
'main'],
297 'music_Rap': [
'http://www.dailymotion.com/rss/official/relevance/search/rap',
'main'],
298 'music_R&B': [
'http://www.dailymotion.com/rss/us/channel/music/relevance/search/rnb',
'main'],
299 'music_Metal': [
'http://www.dailymotion.com/rss/channel/us/channel/music/official/relevance/search/metal',
'main'],
300 'music_Electro': [
'http://www.dailymotion.com/rss/channel/music/official/relevance/search/electro',
'main'],
302 'People_Family_Featured Videos': [
'http://www.dailymotion.com/rss/featured/channel/people/1',
'main'],
303 'People_Family_HD content': [
'http://www.dailymotion.com/rss/hd/channel/people/1',
'main'],
304 'People_Family_Official Content': [
'http://www.dailymotion.com/rss/official/channel/people/1',
'main'],
305 'People_Family_Creative Content': [
'http://www.dailymotion.com/rss/creative/channel/people/1',
'main'],
306 'People_Family_Most Commented': [
'http://www.dailymotion.com/rss/commented-week/featured/channel/people/1',
'main'],
307 'People_Family_Most Viewed': [
'http://www.dailymotion.com/rss/visited-week/featured/channel/people/1',
'main'],
308 'People_Family_Best Rated': [
'http://www.dailymotion.com/rss/rated-week/featured/channel/people/1',
'main'],
310 'Tech_Science_Most recent': [
'http://www.dailymotion.com/rss/channel/tech/1',
'main'],
311 'Tech_Science_Most viewed': [
'http://www.dailymotion.com/rss/visited/channel/tech/1',
'main'],
312 'Tech_Science_Most commented': [
'http://www.dailymotion.com/rss/commented/channel/tech/1',
'main'],
313 'Tech_Science_Best rated': [
'http://www.dailymotion.com/rss/rated/channel/tech/1',
'main'],
322 'F_M_B_C_Featured': [
'http://www.dailymotion.com/rss/groups/featured',
'groups'],
323 'F_M_B_C_Most Recent': [
'http://www.dailymotion.com/rss/groups/1',
'groups'],
324 'F_M_B_C_Most Active': [
'http://www.dailymotion.com/rss/groups/active',
'groups'],
325 'F_M_B_C_Month': [
'http://www.dailymotion.com/rss/groups/active-month',
'groups'],
326 'F_M_B_C_Week': [
'http://www.dailymotion.com/rss/groups/active-week',
'groups'],
327 'F_M_B_C_Today': [
'http://www.dailymotion.com/rss/groups/active-today',
'groups'],
331 'group_Top rated': [
'http://www.dailymotion.com/rss/rated/group',
'main'],
332 'group_Most viewed': [
'http://www.dailymotion.com/rss/visited/group',
'main'],
333 'group_Most commented': [
'http://www.dailymotion.com/rss/commented/group',
'main'],
338 self.
config[
'image_extentions'] = [
"png",
"jpg",
"bmp"]
345 'F_M_B_C': [[
'Featured/Most/Best/Current ...', [
'featured',
'creative',
'official',
'hd',
'commented',
'visited',
'rated',
'relevance-month',
'relevance-week',
'relevance-today']],
348 [
'Categories', [
'movie',
'comedy',
'short+film',
'television',
'documentary',
'festival', ]],
351 [
'Video Channels',
''],
353 [
'Animals', [
'animals_motionmaker',
'animals_most_recent',
'animals_hd',
'animals_official_users',
'animals_most_viewed',
'animals_best_rated', ]],
355 [
'Auto-Moto', [
'auto_most_recent',
'auto_motionmaker',
'auto_most_viewed',
'auto_official_users', ]],
357 [
'Film & TV', [
'film_TV_movie',
'film_TV_comedy',
'film_TV_short_film',
'film_TV_television',
'film_TV_documentary',
'film_TV_festival', ]],
359 [
'Gaming', [
'gaming_Trailer',
'gaming_Lego',
'gaming_Machinima',
'gaming_Motionmaker',
'gaming_Review',
'gaming_News',
'gaming_recent',
'gaming_users', ]],
361 [
'Life & Style', [
'lifestyle_best_rated',
'lifestyle_most_commented',
'lifestyle_most_viewed',
'lifestyle_HD', ]],
363 [
'News & Politics', [
'news_politics_Politics',
'news_politics_Celebrity',
'news_politics_official_users',
'news_politics_International',
'news_politics_Entertainment',
'news_politics_Motionmakers', ]],
365 [
'Sports & Extreme', [
'sports_extreme_surf',
'sports_extreme_baseball',
'sports_extreme_wrestling',
'sports_extreme_BMX', ]],
367 [
'Webcam & Vlogs', [
'webcam_vlogs_Most_viewed',
'webcam_vlogs_Featured_videos',
'webcam_vlogs_Best_rated',
'webcam_vlogs_Most_Commented', ]],
369 [
'Arts', [
'arts_Animation',
'arts_Short_Film',
'arts_Motionmaker',
'arts_Official_Users',
'arts_Suede_swede',
'arts_Most_recent', ]],
371 [
'College', [
'college_Most_viewed',
'college_HD_videos',
'college_Best_rated',
'college_Most_commented', ]],
373 [
'Funny', [
'funny_STAND UP',
'funny_Hulu: NBC & Fox',
'funny_My Damn Channel',
'funny_Motionmakers',
'funny_Sketch',
"funny_Nat'l Lampoon",
'funny_Classic Sitcoms',
'funny_Official Users', ]],
375 [
'Latino', [
'latino_Featured Videos',
'latino_HD content',
'latino_Official Content',
'latino_Creative Content',
'latino_Most Commented',
'latino_Most Viewed',
'latino_Best Rated', ]],
377 [
'Music', [
'music_Pop',
'music_Rock',
'music_Jazz',
'music_Covers',
'music_Rap',
'music_R&B',
'music_Metal',
'music_Electro', ]],
379 [
'People & Family', [
'People_Family_Featured Videos',
'People_Family_HD content',
'People_Family_Official Content',
'People_Family_Creative Content',
'People_Family_Most Commented',
'People_Family_Most Viewed',
'People_Family_Best Rated', ]],
381 [
'Tech & Science', [
'Tech_Science_Most recent',
'Tech_Science_Most viewed',
'Tech_Science_Most commented',
'Tech_Science_Best rated', ]],
389 [
'Featured', [
'F_M_B_C_Featured']],
390 [
'Most Recent', [
'F_M_B_C_Most Recent']],
391 [
'Most Active', [
'F_M_B_C_Most Active']],
392 [
'Month', [
'F_M_B_C_Month']],
393 [
'Week', [
'F_M_B_C_Week']],
394 [
'Today', [
'F_M_B_C_Today']],
400 [
'', [
'group_Top rated',
'group_Most viewed',
'group_Most commented', ], ],
423 '__default__': {
'add_':
'' },
429 'F_M_B_C': {
'featured':
'Featured Videos',
'creative':
'Creative Content',
'official':
'Most Recent',
'hd':
'HD content',
'commented':
'Most Comments',
'visited':
'Most Viewed',
'rated':
'Highest Rated',
'relevance-month':
'Month',
'relevance-week':
'Week',
'relevance-today':
'Today'
431 'categories': {
'movie':
'Trailers',
'comedy':
'Comedy',
'short+film':
'Short Films',
'television':
'TV Clips',
'documentary':
'Documentaries',
'festival':
'Festivals',
434 'animals_motionmaker':
'Motionmaker',
'animals_most_recent':
'Most recent',
'animals_hd':
'HD videos',
'animals_official_users':
'Official users',
'animals_most_viewed':
'Most Viewed',
'animals_best_rated':
'Highest Rated',
436 'auto_most_recent':
'Most recent',
'auto_motionmaker':
'Motionmaker',
'auto_most_viewed':
'Most Viewed',
'auto_official_users':
'Official users',
438 'film_TV_movie':
'Trailers',
'film_TV_comedy':
'Comedy',
'film_TV_short_film':
'Short Films',
'film_TV_television':
'TV Clips',
'film_TV_documentary':
'Documentaries',
'film_TV_festival':
'Festivals',
440 'gaming_Trailer':
'Trailer',
'gaming_Lego':
'Lego fan film',
'gaming_Machinima':
'Machinima',
'gaming_Motionmaker':
'Motionmaker',
'gaming_Review':
'Review',
'gaming_News':
'News',
'gaming_recent':
'Most recent',
'gaming_users':
'Official users',
442 'lifestyle_best_rated':
'Highest Rated',
'lifestyle_most_commented':
'Most Comments',
'lifestyle_most_viewed':
'Most Viewed',
'lifestyle_HD':
'HD videos',
444 'news_politics_Politics':
'Politics',
'news_politics_Celebrity':
'Celebrity news',
'news_politics_official_users':
'Official users',
'news_politics_International':
'International',
'news_politics_Entertainment':
'Entertainment',
'news_politics_Motionmakers':
'Motionmakers',
446 'sports_extreme_surf':
'Surf',
'sports_extreme_baseball':
'Baseball',
'sports_extreme_wrestling':
'Wrestling',
'sports_extreme_BMX':
'BMX',
448 'webcam_vlogs_Most_viewed':
'Most viewed',
'webcam_vlogs_Featured_videos':
'Featured videos',
'webcam_vlogs_Best_rated':
'Highest Rated',
'webcam_vlogs_Most_Commented':
'Most Comments',
450 'arts_Animation':
'Animation',
'arts_Short_Film':
'Short Films',
'arts_Motionmaker':
'Motionmaker',
'arts_Official_Users':
'Official Users',
'arts_Suede_swede':
'Suede/Swede',
'arts_Most_recent':
'Most recent',
452 'college_Most_viewed':
'Most viewed',
'college_HD_videos':
'HD videos',
'college_Best_rated':
'Highest Rated',
'college_Most_commented':
'Most Comments',
454 'funny_STAND UP':
'STAND UP',
'funny_Hulu: NBC & Fox':
'Hulu: NBC & Fox',
'funny_My Damn Channel':
'My Damn Channel',
'funny_Motionmakers':
'Motionmakers',
'funny_Sketch':
'Sketch',
"funny_Nat'l Lampoon":
"Nat'l Lampoon",
'funny_Classic Sitcoms':
'Classic Sitcoms',
'funny_Official Users':
'Official Users',
456 'latino_Featured Videos':
'Featured Videos',
'latino_HD content':
'HD content',
'latino_Official Content':
'Official Content',
'latino_Creative Content':
'Creative Content',
'latino_Most Commented':
'Most Comments',
'latino_Most Viewed':
'Most Viewed',
'latino_Best Rated':
'Highest Rated',
458 'music_Pop':
'Pop',
'music_Rock':
'Rock',
'music_Jazz':
'Jazz',
'music_Covers':
'Covers',
'music_Rap':
'Rap',
'music_R&B':
'R&B',
'music_Metal':
'Metal',
'music_Electro':
'Electro',
460 'People_Family_Featured Videos':
'Featured Videos',
'People_Family_HD content':
'HD content',
'People_Family_Official Content':
'Official Content',
'People_Family_Creative Content':
'Creative Content',
'People_Family_Most Commented':
'Most Comments',
'People_Family_Most Viewed':
'Most Viewed',
'People_Family_Best Rated':
'Highest Rated',
462 'Tech_Science_Most recent':
'Most recent',
'Tech_Science_Most viewed':
'Most viewed',
'Tech_Science_Most commented':
'Most Comments',
'Tech_Science_Best rated':
'Highest Rated',
466 'F_M_B_C_Featured':
'Featured',
'F_M_B_C_Most Recent':
'Most Recent',
'F_M_B_C_Most Active':
'Most Active',
'F_M_B_C_Month':
'Month',
'F_M_B_C_Week':
'Week',
'F_M_B_C_Today':
'Today',
470 'group_Top rated':
'Top rated',
'group_Most viewed':
'Most viewed',
'group_Most commented':
'Most Comments',
476 'F_M_B_C': {
'featured':
'directories/topics/featured',
'creative':
'',
'official':
'directories/topics/most_recent',
'hd':
'directories/topics/hd',
'commented':
'directories/topics/most_comments',
'visited':
'directories/topics/most_viewed',
'rated':
'directories/topics/rated',
'relevance-month':
'directories/topics/month',
'relevance-week':
'directories/topics/week',
'relevance-today':
'directories/topics/today'
478 'categories': {
'movie':
'directories/film_genres/trailers',
'comedy':
'directories/film_genres/comedy',
'short+film':
'directories/film_genres/short_film',
'television':
'directories/topics/tv',
'documentary':
'directories/film_genres/documentaries',
'festival':
'directories/film_genres/film_festivals',
481 'animals_motionmaker':
'directories/topics/animals',
'animals_most_recent':
'directories/topics/most_recent',
'animals_hd':
'directories/topics/hd',
'animals_official_users':
'directories/topics/animals',
'animals_most_viewed':
'directories/topics/most_viewed',
'animals_best_rated':
'directories/topics/rated',
483 'auto_most_recent':
'directories/topics/most_recent',
'auto_motionmaker':
'directories/topics/automotive',
'auto_most_viewed':
'directories/topics/most_viewed',
'auto_official_users':
'directories/topics/most_subscribed',
485 'film_TV_movie':
'directories/film_genres/trailers',
'film_TV_comedy':
'directories/film_genres/comedy',
'film_TV_short_film':
'directories/film_genres/short_film',
'film_TV_television':
'directories/topics/tv',
'film_TV_documentary':
'directories/film_genres/documentaries',
'film_TV_festival':
'directories/film_genres/film_festivals',
487 'gaming_Trailer':
'directories/film_genres/trailers',
'gaming_Lego':
'directories/topics/games',
'gaming_Machinima':
'directories/topics/games',
'gaming_Motionmaker':
'directories/topics/games',
'gaming_Review':
'directories/topics/games',
'gaming_News':
'directories/topics/news',
'gaming_recent':
'directories/topics/most_recent',
'gaming_users':
'directories/topics/most_comments',
489 'lifestyle_best_rated':
'directories/topics/rated',
'lifestyle_most_commented':
'directories/topics/most_comments',
'lifestyle_most_viewed':
'directories/topics/most_viewed',
'lifestyle_HD':
'directories/topics/hd',
491 'news_politics_Politics':
'directories/topics/news',
'news_politics_Celebrity':
'directories/topics/news',
'news_politics_official_users':
'directories/topics/news',
'news_politics_International':
'directories/topics/news',
'news_politics_Entertainment':
'directories/topics/entertainment',
'news_politics_Motionmakers':
'directories/topics/news',
493 'sports_extreme_surf':
'directories/topics/sports',
'sports_extreme_baseball':
'directories/topics/sports',
'sports_extreme_wrestling':
'directories/topics/sports',
'sports_extreme_BMX':
'directories/topics/sports',
495 'webcam_vlogs_Most_viewed':
'directories/topics/most_viewed',
'webcam_vlogs_Featured_videos':
'directories/topics/featured',
'webcam_vlogs_Best_rated':
'directories/topics/rated',
'webcam_vlogs_Most_Commented':
'directories/topics/most_comments',
497 'arts_Animation':
'directories/film_genres/animation',
'arts_Short_Film':
'directories/film_genres/short_film',
'arts_Motionmaker':
'',
'arts_Official_Users':
'',
'arts_Suede_swede':
'',
'arts_Most_recent':
'directories/topics/most_recent',
499 'college_Most_viewed':
'directories/topics/most_viewed',
'college_HD_videos':
'directories/topics/hd',
'college_Best_rated':
'directories/topics/rated',
'college_Most_commented':
'directories/topics/most_comments',
501 'funny_STAND UP':
'directories/film_genres/comedy',
'funny_Hulu: NBC & Fox':
'directories/film_genres/comedy',
'funny_My Damn Channel':
'directories/film_genres/comedy',
'funny_Motionmakers':
'directories/film_genres/comedy',
'funny_Sketch':
'directories/film_genres/comedy',
"funny_Nat'l Lampoon":
"directories/film_genres/comedy",
'funny_Classic Sitcoms':
'directories/film_genres/comedy',
'funny_Official Users':
'directories/film_genres/comedy',
503 'latino_Featured Videos':
'directories/topics/featured',
'latino_HD content':
'directories/topics/hd',
'latino_Official Content':
'directories/music_genres/latino',
'latino_Creative Content':
'directories/music_genres/latino',
'latino_Most Commented':
'directories/topics/most_comments',
'latino_Most Viewed':
'directories/topics/most_viewed',
'latino_Best Rated':
'directories/topics/rated',
505 'music_Pop':
'directories/music_genres/pop',
'music_Rock':
'directories/music_genres/rock',
'music_Jazz':
'directories/music_genres/jazz',
'music_Covers':
'directories/topics/music',
'music_Rap':
'directories/music_genres/hiphop',
'music_R&B':
'directories/music_genres/rnb',
'music_Metal':
'directories/music_genres/metal',
'music_Electro':
'directories/music_genres/electronic_dance',
507 'People_Family_Featured Videos':
'directories/topics/featured',
'People_Family_HD content':
'directories/topics/hd',
'People_Family_Official Content':
'directories/topics/people',
'People_Family_Creative Content':
'directories/topics/people',
'People_Family_Most Commented':
'directories/topics/most_comments',
'People_Family_Most Viewed':
'directories/topics/most_viewed',
'People_Family_Best Rated':
'directories/topics/rated',
509 'Tech_Science_Most recent':
'directories/topics/recent',
'Tech_Science_Most viewed':
'directories/topics/most_viewed',
'Tech_Science_Most commented':
'directories/topics/most_comments',
'Tech_Science_Best rated':
'directories/topics/rated',
511 'Animals':
'directories/topics/animals',
512 'Auto-Moto':
'directories/topics/automotive',
513 'Film & TV':
'directories/topics/movies',
514 'Gaming':
'directories/topics/games',
515 'Life & Style':
'directories/topics/????',
516 'News & Politics':
'directories/topics/news',
517 'Sports & Extreme':
'directories/topics/sports',
518 'Webcam & Vlogs':
'directories/topics/videoblog',
519 'Arts':
'directories/topics/arts',
520 'College':
'directories/topics/college',
521 'Funny':
'directories/film_genres/comedy',
522 'Latino':
'directories/music_genres/latino',
523 'Music':
'directories/topics/music',
524 'People & Family':
'directories/topics/people',
525 'Tech & Science':
'directories/topics/technology',
545 '''Get longitude and latitiude to find videos relative to your location. Up to three different
546 servers will be tried before giving up.
547 return a dictionary e.g.
548 {'Latitude': '43.6667', 'Country': 'Canada', 'Longitude': '-79.4167', 'City': 'Toronto'}
549 return an empty dictionary if there were any errors
550 Code found at: http://blog.suinova.com/2009/04/from-ip-to-geolocation-country-city.html
553 '''Find the external IP address of this computer.
555 url = urllib.request.URLopener()
557 resp = url.open(
'http://www.whatismyip.com/automation/n09230945.asp')
569 gs = urllib.request.urlopen(
'http://blogama.org/ip_query.php?ip=%s&output=xml' % ip)
573 gs = urllib.request.urlopen(
'http://www.seomoz.org/ip2location/look.php?ip=%s' % ip)
577 gs = urllib.request.urlopen(
'http://api.hostip.info/?ip=%s' % ip)
580 logging.error(
'GeoIP servers not available')
583 if txt.find(
'<Response>') > 0:
584 countrys = re.findall(
r'<CountryName>([\w ]+)<',txt)[0]
585 citys = re.findall(
r'<City>([\w ]+)<',txt)[0]
586 lats,lons = re.findall(
r'<Latitude>([\d\-\.]+)</Latitude>\s*<Longitude>([\d\-\.]+)<',txt)[0]
587 elif txt.find(
'GLatLng') > 0:
588 citys,countrys = re.findall(
r'<br />\s*([^<]+)<br />\s*([^<]+)<',txt)[0]
589 lats,lons = re.findall(
r'LatLng\(([-\d\.]+),([-\d\.]+)',txt)[0]
590 elif txt.find(
'<gml:coordinates>') > 0:
591 citys = re.findall(
r'<Hostip>\s*<gml:name>(\w+)</gml:name>',txt)[0]
592 countrys = re.findall(
r'<countryName>([\w ,\.]+)</countryName>',txt)[0]
593 lats,lons = re.findall(
r'gml:coordinates>([-\d\.]+),([-\d\.]+)<',txt)[0]
595 logging.error(
'error parsing IP result %s'%txt)
597 return {
'Country':countrys,
'City':citys,
'Latitude':lats,
'Longitude':lons}
599 logging.error(
'Error parsing IP result %s'%txt)
604 '''Removes HTML markup from a text string.
605 @param text The HTML source.
606 @return The plain text. If the HTML source contains non-ASCII
607 entities or character references, this is a Unicode string.
615 if text[:3] ==
"&#x":
616 return chr(int(text[3:-1], 16))
618 return chr(int(text[2:-1]))
621 elif text[:1] ==
"&":
623 entity = html.entities.entitydefs.get(text[1:-1])
625 if entity[:2] ==
"&#":
627 return chr(int(entity[2:-1]))
631 return str(entity,
"iso-8859-1")
633 return self.
ampReplace(re.sub(
r"(?s)<[^>]*>|&#?\w+;", fixup, self.
textUtf8(text))).replace(
'\n',
' ')
638 """Setups a logger using the logging module, returns a log object
640 logger = logging.getLogger(self.
log_name)
641 formatter = logging.Formatter(
'%(asctime)s) %(levelname)s %(message)s')
643 hdlr = logging.StreamHandler(sys.stdout)
645 hdlr.setFormatter(formatter)
646 logger.addHandler(hdlr)
648 if self.
config[
'debug_enabled']:
649 logger.setLevel(logging.DEBUG)
651 logger.setLevel(logging.WARNING)
660 return str(text,
'utf8')
661 except UnicodeDecodeError:
663 except (UnicodeEncodeError, TypeError):
669 '''Replace all "&" characters with "&"
672 return text.replace(
'&',
'~~~~~').replace(
'&',
'&').replace(
'~~~~~',
'&')
677 '''Check if there is a specific generic tree view icon. If not default to the channel icon.
678 return self.tree_dir_icon
689 self.
tree_dir_icon =
'%%SHAREDIR%%/mythnetvision/icons/%s.png' % (dir_icon, )
699 playerUrl = self.
mythxml.getInternetContentUrl(
"nv_python_libs/configs/HTML/dailymotion.html", \
700 url.replace(
'http://www.dailymotion.com/swf/video/',
''))
704 '''Key word video search of the Dailymotion web site
705 return an array of matching item dictionaries
708 url = self.
config[
'urls'][
'video.search'] % (urllib.parse.quote_plus(title.encode(
"utf-8")), pagenumber)
709 if self.
config[
'debug_enabled']:
713 return self.
config[
'item_parser'][
'main'](url, [])
718 """Common name for a video search. Used to interface with MythTV plugin NetVision
721 self.
channel = {
'channel_title':
'Dailymotion',
'channel_link':
'http://www.dailymotion.com',
'channel_description':
"Dailymotion is about finding new ways to see, share and engage your world through the power of online video.",
'channel_numresults': 0,
'channel_returned': 1,
'channel_startindex': 0}
729 data = self.
searchTitle(title, int(pagenumber), self.page_limit)
730 except DailymotionVideoNotFound
as msg:
731 sys.stderr.write(
"%s\n" % msg)
733 except DailymotionUrlError
as msg:
734 sys.stderr.write(
'%s\n' % msg)
736 except DailymotionHttpError
as msg:
737 sys.stderr.write(self.
error_messages[
'DailymotionHttpError'] % msg)
739 except DailymotionRssError
as msg:
740 sys.stderr.write(self.
error_messages[
'DailymotionRssError'] % msg)
742 except Exception
as e:
743 sys.stderr.write(
"! Error: Unknown error during a Video search (%s)\nError(%s)\n" % (title, e))
752 self.
channel[
'channel_numresults'] = len(data) * int(pagenumber) + 1
754 self.
channel[
'channel_numresults'] = int(pagenumber) * len(data)
756 self.
channel[
'channel_startindex'] = int(pagenumber) * len(data)
757 self.
channel[
'channel_returned'] = len(data)
763 '''Gather the Dailymotion categories/feeds/...etc then get a max page of videos meta data in
765 return array of directories and their video meta data
768 self.
channel = {
'channel_title':
'Dailymotion',
'channel_link':
'http://www.dailymotion.com',
'channel_description':
"Dailymotion is about finding new ways to see, share and engage your world through the power of online video.",
'channel_numresults': 0,
'channel_returned': 1,
'channel_startindex': 0}
770 if self.
config[
'debug_enabled']:
784 return [[self.
channel, dictionaries]]
788 '''Form a URL to search for videos
800 for ky
in list(additions.keys()):
801 if ky.startswith(
'add_'):
802 addition+=
'/%s' % additions[ky]
804 addition+=
'&%s=%s' % (ky, additions[ky])
805 index = URL.find(
'%')
807 return (URL+addition)
809 return (URL+addition) % self.feed
814 '''Parse a list made of category lists and retrieve video meta data
815 return a dictionary of directory names and category's video meta data
817 for sets
in dir_dict:
818 if not isinstance(sets[1], list):
825 dictionaries.append([
'',
''])
828 for self.feed
in sets[1]:
833 temp_dictionary = self.
config[
'item_parser'][URL[1]](self.
makeURL(URL[0]), temp_dictionary)
834 if len(temp_dictionary):
840 for element
in temp_dictionary:
841 dictionaries.append(element)
843 dictionaries.append([
'',
''])
848 '''Get the video meta data for url search
849 return the video dictionary of directories and their video mata data
851 initial_length = len(dictionaries)
853 if self.
config[
'debug_enabled']:
860 except Exception
as errormsg:
861 sys.stderr.write(self.
error_messages[
'DailymotionUrlError'] % (url, errormsg))
865 sys.stderr.write(
'1-No Videos for (%s)\n' % self.feed)
868 dictionary_first =
False
871 language = self.
config[
'language']
872 for elements
in etree.find(
'channel'):
873 if elements.tag.endswith(
'language'):
875 language = elements.text[:2]
878 if elements.tag.endswith(
'link'):
879 if elements.get(
'rel') ==
"next":
883 if elements.tag.endswith(
'image'):
884 if elements.get(
'href'):
885 directory_image = self.
ampReplace(elements.get(
'href').strip())
888 if not elements.tag.endswith(
'item'):
894 meta_data[
'language'] = language
896 if e.tag.endswith(
'title'):
900 if e.tag.endswith(
'author'):
904 if e.tag.endswith(
'pubDate'):
906 meta_data[
'published_parsed'] = e.text.strip()
908 if e.tag.endswith(
'description'):
910 index1 = e.text.find(
'<p>')
911 index2 = e.text.find(
'</p>')
912 if index1 != -1
and index2 != -1:
913 meta_data[
'media_description'] = self.
massageDescription(e.text[index1+3:index2].strip())
915 if e.tag.endswith(
'thumbnail'):
917 meta_data[
'thumbnail'] = self.
ampReplace(e.get(
'url').strip())
919 if e.tag.endswith(
'player'):
921 meta_data[
'link'] = self.
ampReplace(e.get(
'url').strip())
923 if e.tag.endswith(
'videorating'):
925 meta_data[
'rating'] = e.text.strip()
927 if not e.tag.endswith(
'group'):
930 if elem.tag.endswith(
'content')
and elem.get(
'type') ==
'application/x-shockwave-flash':
933 if elem.get(
'duration'):
934 meta_data[
'duration'] = elem.get(
'duration').strip()
935 if elem.get(
'width'):
936 meta_data[
'item_width'] = elem.get(
'width').strip()
937 if elem.get(
'height'):
938 meta_data[
'item_height'] = elem.get(
'height').strip()
942 if 'video' not in meta_data
and 'link' not in meta_data:
945 if 'video' not in meta_data:
946 meta_data[
'video'] = meta_data[
'link']
948 meta_data[
'link'] = meta_data[
'video']
951 if not dictionary_first:
956 dictionary_first =
True
960 if key
not in meta_data:
964 dictionaries.append(final_item)
967 if initial_length < len(dictionaries):
968 dictionaries.append([
'',
''])
974 '''Get the video meta data for a group url search
975 return the video dictionary of directories and their video mata data
978 initial_length = len(dictionaries)
981 if self.
config[
'debug_enabled']:
988 except Exception
as errormsg:
989 sys.stderr.write(self.
error_messages[
'DailymotionUrlError'] % (url, errormsg))
993 sys.stderr.write(
'1-No Groups for (%s)\n' % self.feed)
996 for elements
in etree.find(
'channel'):
997 if not elements.tag.endswith(
'item'):
1002 for group
in elements:
1003 if group.tag ==
'title':
1006 if group.tag ==
'link':
1008 self.
group_id = group.text.strip().replace(
'http://www.dailymotion.com/group/',
'')
1009 if group.tag.endswith(
'thumbnail'):
1010 if group.get(
'url'):
1011 group_image = self.
ampReplace(group.get(
'url').strip())
1012 if group_name !=
'' and self.
group_id !=
'' and group_image !=
'':
1014 temp_dictionary = []
1019 if len(temp_dictionary):
1021 dictionaries.append([group_name, group_image])
1023 for element
in temp_dictionary:
1024 dictionaries.append(element)
1027 dictionaries.append([
'',
''])