MythTV  master
trailers.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
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 import io
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, str):
90  obj = obj.encode(self.encoding)
91  self.out.buffer.write(obj)
92 
93  def __getattr__(self, attr):
94  """Delegate everything but write to the stream"""
95  return getattr(self.out, attr)
96 
97 if isinstance(sys.stdout, io.TextIOWrapper):
98  sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
99  sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
100 
101 
102 # Used for debugging
103 #import nv_python_libs.common.common_api
104 try:
105  '''Import the common python class
106  '''
107  import nv_python_libs.common.common_api as common_api
108 except Exception as e:
109  sys.stderr.write('''
110 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
111 common_exceptions.py (v0.1.3 or greater),
112 They should have been included with the distribution of MythNetvision
113 Error(%s)
114 ''' % e)
115  sys.exit(1)
116 if common_api.__version__ < '0.1.3':
117  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__)
118  sys.exit(1)
119 
120 
121 # Used for debugging
122 #import nv_python_libs.mashups.mashups_api as target
123 try:
124  '''Import the python mashups support classes
125  '''
126  import nv_python_libs.mashups.mashups_api as target
127 except Exception as e:
128  sys.stderr.write('''
129 The subdirectory "nv_python_libs/mashups" containing the modules mashups_api and
130 mashups_exceptions.py (v0.1.0 or greater),
131 They should have been included with the distribution of nature.py.
132 Error(%s)
133 ''' % e)
134  sys.exit(1)
135 if target.__version__ < '0.1.0':
136  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__)
137  sys.exit(1)
138 
139 # Verify that the main process modules are installed and accessible
140 try:
141  import nv_python_libs.mainProcess as process
142 except Exception as e:
143  sys.stderr.write('''
144 The python script "nv_python_libs/mainProcess.py" must be present.
145 Error(%s)
146 ''' % e)
147  sys.exit(1)
148 
149 if process.__version__ < '0.2.0':
150  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__)
151  sys.exit(1)
152 
153 if __name__ == '__main__':
154  # No api key is required
155  apikey = ""
156  # Set the base processing directory that the grabber is installed
157  target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
158  # Make sure the target functions have an instance of the common routines
159  target.common = common_api.Common()
160  main = process.mainProcess(target, apikey, )
161  main.grabberInfo = {}
162  main.grabberInfo['enabled'] = True
163  main.grabberInfo['title'] = __title__
164  main.grabberInfo['command'] = 'trailers.py'
165  main.grabberInfo['mashup_title'] = __mashup_title__
166  main.grabberInfo['author'] = __author__
167  main.grabberInfo['thumbnail'] = 'trailers.png'
168  main.grabberInfo['type'] = ['video', ]
169  main.grabberInfo['desc'] = "Mashups combines media from multiple sources to create a new work"
170  main.grabberInfo['version'] = __version__
171  main.grabberInfo['search'] = True
172  main.grabberInfo['tree'] = True
173  main.grabberInfo['html'] = False
174  main.grabberInfo['usage'] = __usage_examples__
175  main.grabberInfo['SmaxPage'] = __search_max_page_items__
176  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
177  main.main()
trailers.OutStreamEncoder.__init__
def __init__(self, outstream, encoding=None)
Definition: trailers.py:80
trailers.OutStreamEncoder.write
def write(self, obj)
Definition: trailers.py:87
nv_python_libs.mashups.mashups_api
Definition: mashups_api.py:1
trailers.OutStreamEncoder.encoding
encoding
Definition: trailers.py:83
trailers.OutStreamEncoder.__getattr__
def __getattr__(self, attr)
Definition: trailers.py:93
trailers.OutStreamEncoder.out
out
Definition: trailers.py:81
nv_python_libs.mainProcess
Definition: mainProcess.py:1
nv_python_libs.common.common_api
Definition: common_api.py:1
trailers.OutStreamEncoder
Definition: trailers.py:78