MythTV  master
trailers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: trailers.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform a mashup of various Moview Trailers Internet media sources
9 # for the MythTV Netvision plugin. It follows the MythTV Netvision grabber standards.
10 #
11 # Command example:
12 # See help (-u and -h) options
13 #
14 # Design:
15 # 1) Read "~/.mythtv/MythNetvision/userGrabberPrefs/trailersMashup.xml" configuration file
16 # 2) Input the sources that are marked as enabled
17 # 3) Process the results and display to stdout
18 #
19 #
20 # License:Creative Commons GNU GPL v2
21 # (http://creativecommons.org/licenses/GPL/2.0/)
22 #-------------------------------------
23 __title__ ="Movie Trailers";
24 __mashup_title__ = "trailersMashup"
25 __author__="R.D. Vaughan"
26 __version__="0.11"
27 # 0.10 Initial development
28 # 0.11 Added a Movie Trailer Search option
29 
30 __usage_examples__ ='''
31 (Option Help)
32 > ./trailers.py -h
33 Usage: ./trailers.py -hduvlST [parameters] <search text>
34 Version: 0.XX Author: R.D. Vaughan
35 
36 For details on the MythTV Netvision plugin see the wiki page at:
37 http://www.mythtv.org/wiki/MythNetvision
38 
39 Options:
40  -h, --help show this help message and exit
41  -d, --debug Show debugging info (URLs, raw XML ... etc, info
42  varies per grabber)
43  -u, --usage Display examples for executing the script
44  -v, --version Display grabber name and supported options
45  -l LANGUAGE, --language=LANGUAGE
46  Select data that matches the specified language fall
47  back to English if nothing found (e.g. 'es' EspaƱol,
48  'de' Deutsch ... etc). Not all sites or grabbers
49  support this option.
50  -p PAGE NUMBER, --pagenumber=PAGE NUMBER
51  Display specific page of the search results. Default
52  is page 1. Page number is ignored with the Tree View
53  option (-T).
54  -S, --search Search for videos
55  -T, --treeview Display a Tree View of a sites videos
56 
57 > ./trailers.py -v
58 <grabber>
59  <name>Movie Trailers</name>
60  <author>R.D. Vaughan</author>
61  <thumbnail>trailers.png</thumbnail>
62  <command>trailers.py</command>
63  <type>video</type>
64  <description>Mashups combines media from multiple sources to create a new work</description>
65  <version>0.11</version>
66  <search>true</search>
67  <tree>true</tree>
68 </grabber>
69 
70 > ./trailers.py -T
71 '''
72 __search_max_page_items__ = 50
73 __tree_max_page_items__ = 20
74 
75 import sys, os
76 
77 
78 class OutStreamEncoder(object):
79  """Wraps a stream with an encoder"""
80  def __init__(self, outstream, encoding=None):
81  self.out = outstream
82  if not encoding:
83  self.encoding = sys.getfilesystemencoding()
84  else:
85  self.encoding = encoding
86 
87  def write(self, obj):
88  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
89  if isinstance(obj, unicode):
90  try:
91  self.out.write(obj.encode(self.encoding))
92  except IOError:
93  pass
94  else:
95  try:
96  self.out.write(obj)
97  except IOError:
98  pass
99 
100  def __getattr__(self, attr):
101  """Delegate everything but write to the stream"""
102  return getattr(self.out, attr)
103 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
104 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
105 
106 
107 # Used for debugging
108 #import nv_python_libs.common.common_api
109 try:
110  '''Import the common python class
111  '''
112  import nv_python_libs.common.common_api as common_api
113 except Exception, e:
114  sys.stderr.write('''
115 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
116 common_exceptions.py (v0.1.3 or greater),
117 They should have been included with the distribution of MythNetvision
118 Error(%s)
119 ''' % e)
120  sys.exit(1)
121 if common_api.__version__ < '0.1.3':
122  sys.stderr.write("\n! Error: Your current installed common_api.py version is (%s)\nYou must at least have version (0.1.3) or higher.\n" % target.__version__)
123  sys.exit(1)
124 
125 
126 # Used for debugging
127 #import nv_python_libs.mashups.mashups_api as target
128 try:
129  '''Import the python mashups support classes
130  '''
131  import nv_python_libs.mashups.mashups_api as target
132 except Exception, e:
133  sys.stderr.write('''
134 The subdirectory "nv_python_libs/mashups" containing the modules mashups_api and
135 mashups_exceptions.py (v0.1.0 or greater),
136 They should have been included with the distribution of nature.py.
137 Error(%s)
138 ''' % e)
139  sys.exit(1)
140 if target.__version__ < '0.1.0':
141  sys.stderr.write("\n! Error: Your current installed mashups_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
142  sys.exit(1)
143 
144 # Verify that the main process modules are installed and accessible
145 try:
146  import nv_python_libs.mainProcess as process
147 except Exception, e:
148  sys.stderr.write('''
149 The python script "nv_python_libs/mainProcess.py" must be present.
150 Error(%s)
151 ''' % e)
152  sys.exit(1)
153 
154 if process.__version__ < '0.2.0':
155  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__)
156  sys.exit(1)
157 
158 if __name__ == '__main__':
159  # No api key is required
160  apikey = ""
161  # Set the base processing directory that the grabber is installed
162  target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
163  # Make sure the target functions have an instance of the common routines
164  target.common = common_api.Common()
165  main = process.mainProcess(target, apikey, )
166  main.grabberInfo = {}
167  main.grabberInfo['title'] = __title__
168  main.grabberInfo['command'] = u'trailers.py'
169  main.grabberInfo['mashup_title'] = __mashup_title__
170  main.grabberInfo['author'] = __author__
171  main.grabberInfo['thumbnail'] = 'trailers.png'
172  main.grabberInfo['type'] = ['video', ]
173  main.grabberInfo['desc'] = u"Mashups combines media from multiple sources to create a new work"
174  main.grabberInfo['version'] = __version__
175  main.grabberInfo['search'] = True
176  main.grabberInfo['tree'] = True
177  main.grabberInfo['html'] = False
178  main.grabberInfo['usage'] = __usage_examples__
179  main.grabberInfo['SmaxPage'] = __search_max_page_items__
180  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
181  main.main()
def write(self, obj)
Definition: trailers.py:87
def __getattr__(self, attr)
Definition: trailers.py:100
def __init__(self, outstream, encoding=None)
Definition: trailers.py:80