MythTV  master
dailymotion.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: dailymotion.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform Dailymotion video lookups for the MythTV Netvision plugin
9 # based on information found on the http://www.dailymotion.com website. It
10 # follows the MythTV Netvision grabber standards.
11 # This script uses the python module dailymotion_api.py which should be included
12 # with this script.
13 # The dailymotion.py module uses the full access API published by
14 # http://www.dailymotion.com see: http://www.dailymotion.com/ca-en/doc/api/player
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 scripts 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__ ="Dailymotion";
29 __author__="R.D. Vaughan"
30 __version__="0.23"
31 # 0.1.0 Initial development
32 # 0.1.1 Update documentation
33 # 0.2.0 Public release
34 # 0.2.1 Improved the diplayed messages when exception occur
35 # 0.22 Change to support xml version information display
36 # 0.23 Added the "command" tag to the xml version information display
37 
38 
39 __usage_examples__ ='''
40 (Option Help)
41 > ./dailymotion.py -h
42 Usage: ./dailymotion.py -hduvlST [parameters] <search text>
43 Version: v0.2.0 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 dailymotion for videos matching search words)
68 > ./dailymotion.py -S "Birds"
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>Dailymotion</title>
81  <link>http://www.dailymotion.com</link>
82  <description>Dailymotion is about finding new ways to see, share and engage your world through the power of online video.</description>
83  <numresults>16</numresults>
84  <returned>15</returned>
85  <startindex>15</startindex>
86  <item>
87  <title>Bob Marley - Three Little Birds</title>
88  <author>hushhush112</author>
89  <pubDate>Wed, 24 Jan 2007 04:29:56 +0100</pubDate>
90  <description>"Three Little Birds" is a song by Bob Marley &amp; The Wailers from their 1977 album Exodus. The single reached the Top 20 in England.</description>
91  <link>http://www.dailymotion.com/swf/x11te1?autoPlay=1</link>
92  <media:group>
93  <media:thumbnail url='http://ak2.static.dailymotion.com/static/video/163/467/1764361:jpeg_preview_large.jpg?20090610235117'/>
94  <media:content url='http://www.dailymotion.com/swf/x11te1?autoPlay=1' duration='204' width='320' height='240' lang='en'/>
95  </media:group>
96  <rating>5.0</rating>
97  </item>
98 ...
99  <item>
100  <title>Birds Eye View Film Festival 2006: Highlights (Part 1)</title>
101  <author>BirdsEyeViewFilm</author>
102  <pubDate>Wed, 11 Feb 2009 17:11:32 +0100</pubDate>
103  <description>Highlights from the Birds Eye View International Women's Day Gala at the BFI Southbank - the opening event for Birds Eye View Film Festival 2006. Special guests included Gurinder Chadha, Arabella Weir, Jerry Hall and Jessica Stevenson (Hynes). Each year we showcase the very best in new features, documentaries and short films from women filmmakers from across the globe, alongside premiere screenings, special multi-media events, Q&amp;As, panel discussions and parties. Birds Eye View celebrates international women filmmakers. http://www.birds-eye-view.co.uk</description>
104  <link>http://www.dailymotion.com/swf/x8c61t?autoPlay=1</link>
105  <media:group>
106  <media:thumbnail url='http://ak2.static.dailymotion.com/static/video/146/400/14004641:jpeg_preview_large.jpg?20090416211915'/>
107  <media:content url='http://www.dailymotion.com/swf/x8c61t?autoPlay=1' duration='199' width='320' height='240' lang='en'/>
108  </media:group>
109  <rating>5.0</rating>
110  </item>
111  </channel>
112 </rss>
113 
114 
115 (Retrieve a Tree View of the Dailymotion Video Categories)
116 > ./dailymotion.py -T
117 <?xml version="1.0" encoding="UTF-8"?>
118 <rss version="2.0"
119 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
120 xmlns:content="http://purl.org/rss/1.0/modules/content/"
121 xmlns:cnettv="http://cnettv.com/mrss/"
122 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
123 xmlns:media="http://search.yahoo.com/mrss/"
124 xmlns:atom="http://www.w3.org/2005/Atom"
125 xmlns:amp="http://www.adobe.com/amp/1.0"
126 xmlns:dc="http://purl.org/dc/elements/1.1/">
127  <channel>
128  <title>Dailymotion</title>
129  <link>http://www.dailymotion.com</link>
130  <description>Dailymotion is about finding new ways to see, share and engage your world through the power of online video.</description>
131  <numresults>0</numresults>
132  <returned>1</returned>
133  <startindex>0</startindex>
134  <directory name="Featured/Most/Best/Current ..." thumbnail="/usr/local/share/mythtv/mythnetvision/icons/dailymotion.jpg">
135  <directory name="Featured Videos" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/featured.png">
136  <item>
137  <title>Born of Hope - Full Movie</title>
138  <author>BornofHope</author>
139  <pubDate>Tue, 01 Dec 2009 09:49:05 +0100</pubDate>
140  <description>This version of the film is not the best one to watch. Please select the Extended Version http://www.dailymotion.com/video/xbhonj_born-of-hope-extended-version_shortfilms Born of Hope is an independent feature film inspired by the Lord of the Rings and produced in the UK. www.bornofhope.comA scattered people, the descendents of storied sea kings of the ancient West, struggle to survive in a lonely wilderness as a dark force relentlessly bends its will toward their destruction. Yet amidst these valiant, desperate people, hope remains. A royal house endures unbroken from father to son.This 70 minute original drama is set in the time before the War of the Ring and tells the story of the Dúnedain, the Rangers of the North, before the return of the King. Inspired by only a couple of paragraphs written by Tolkien in the appendices of the Lord of the Rings we follow Arathorn and Gilraen, the parents of Aragorn, from their first meeting through a turbulent time in their people's history.</description>
141  <link>http://www.dailymotion.com/swf/xbc5ut?autoPlay=1</link>
142  <media:group>
143  <media:thumbnail url='http://ak2.static.dailymotion.com/static/video/732/340/19043237:jpeg_preview_large.jpg?20091215100200'/>
144  <media:content url='http://www.dailymotion.com/swf/xbc5ut?autoPlay=1' duration='4088' width='320' height='240' lang='en'/>
145  </media:group>
146  <rating>4.5</rating>
147  </item>
148 ...
149  <item>
150  <title>Rubik's Cube : un Français recordman du monde</title>
151  <author>newzy-fr</author>
152  <pubDate>Wed, 10 Oct 2007 21:02:52 +0200</pubDate>
153  <description>Il s'appelle Thibaut Jacquinot, il a été champion de France 2006 de Rubik's Cube et il détient toujours le record du monde de la discipline. Démonstration réalisée sans trucages...Plus de vidéos rubik's Cube sur www.newzy.fr</description>
154  <link>http://www.dailymotion.com/swf/x36jkt?autoPlay=1</link>
155  <media:group>
156  <media:thumbnail url='http://ak2.static.dailymotion.com/static/video/751/443/5344157:jpeg_preview_large.jpg?20090618140735'/>
157  <media:content url='http://www.dailymotion.com/swf/x36jkt?autoPlay=1' duration='32' width='320' height='240' lang='en'/>
158  </media:group>
159  <rating>4.9</rating>
160  </item>
161  </directory>
162  </directory>
163  </directory>
164  </channel>
165 </rss>
166 '''
167 __search_max_page_items__ = 10
168 __tree_max_page_items__ = 20
169 
170 import sys, os
171 import io
172 
173 class OutStreamEncoder(object):
174  """Wraps a stream with an encoder"""
175  def __init__(self, outstream, encoding=None):
176  self.out = outstream
177  if not encoding:
178  self.encoding = sys.getfilesystemencoding()
179  else:
180  self.encoding = encoding
181 
182  def write(self, obj):
183  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
184  if isinstance(obj, str):
185  obj = obj.encode(self.encoding)
186  self.out.buffer.write(obj)
187 
188  def __getattr__(self, attr):
189  """Delegate everything but write to the stream"""
190  return getattr(self.out, attr)
191 
192 if isinstance(sys.stdout, io.TextIOWrapper):
193  sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
194  sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
195 
196 # Used for debugging normally commented out
197 #import nv_python_libs.dailymotion.dailymotion_api as target
198 
199 # Verify that the tmdb_api modules are installed and accessible
200 try:
202 except Exception as e:
203  sys.stderr.write('''
204 The subdirectory "nv_python_libs/dailymotion" containing the modules dailymotion_api.py (v0.2.0 or greater),
205 They should have been included with the distribution of dailymotion.py.
206 Error(%s)
207 ''' % e)
208  sys.exit(1)
209 
210 if target.__version__ < '0.2.0':
211  sys.stderr.write("\n! Error: Your current installed dailymotion_api.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % target.__version__)
212  sys.exit(1)
213 
214 
215 # Verify that the common process modules are installed and accessible
216 try:
217  import nv_python_libs.mainProcess as process
218 except Exception as e:
219  sys.stderr.write('''
220 The python script "nv_python_libs/mainProcess.py" must be present.
221 Error(%s)
222 ''' % e)
223  sys.exit(1)
224 
225 if process.__version__ < '0.2.0':
226  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__)
227  sys.exit(1)
228 
229 if __name__ == '__main__':
230  # No api key is required
231  apikey = ""
232  main = process.mainProcess(target, apikey, )
233  main.grabberInfo = {}
234  main.grabberInfo['enabled'] = True
235  main.grabberInfo['title'] = __title__
236  main.grabberInfo['command'] = 'dailymotion.py'
237  main.grabberInfo['author'] = __author__
238  main.grabberInfo['thumbnail'] = 'dailymotion.png'
239  main.grabberInfo['type'] = ['video']
240  main.grabberInfo['desc'] = "Dailymotion is about finding new ways to see, share and engage your world through the power of online video."
241  main.grabberInfo['version'] = __version__
242  main.grabberInfo['search'] = True
243  main.grabberInfo['tree'] = True
244  main.grabberInfo['html'] = False
245  main.grabberInfo['usage'] = __usage_examples__
246  main.grabberInfo['SmaxPage'] = __search_max_page_items__
247  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
248  main.main()
dailymotion.OutStreamEncoder.encoding
encoding
Definition: dailymotion.py:178
dailymotion.OutStreamEncoder
Definition: dailymotion.py:173
dailymotion.OutStreamEncoder.out
out
Definition: dailymotion.py:176
dailymotion.OutStreamEncoder.__getattr__
def __getattr__(self, attr)
Definition: dailymotion.py:188
nv_python_libs.mainProcess
Definition: mainProcess.py:1
nv_python_libs.dailymotion.dailymotion_api
Definition: dailymotion_api.py:1
dailymotion.OutStreamEncoder.__init__
def __init__(self, outstream, encoding=None)
Definition: dailymotion.py:175
dailymotion.OutStreamEncoder.write
def write(self, obj)
Definition: dailymotion.py:182