00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 __title__ ="PBS";
00024 __mashup_title__ = "pbs"
00025 __author__="R.D. Vaughan"
00026 __version__="v0.10"
00027
00028
00029 __usage_examples__ ='''
00030 (Option Help)
00031 > ./pbs.py -h
00032 Usage: ./pbs.py -hduvlST [parameters] <search text>
00033 Version: v0.1.0 Author: R.D.Vaughan
00034
00035 For details on the MythTV Netvision plugin see the wiki page at:
00036 http://www.mythtv.org/wiki/MythNetvision
00037
00038 Options:
00039 -h, --help show this help message and exit
00040 -d, --debug Show debugging info (URLs, raw XML ... etc, info
00041 varies per grabber)
00042 -u, --usage Display examples for executing the script
00043 -v, --version Display grabber name and supported options
00044 -l LANGUAGE, --language=LANGUAGE
00045 Select data that matches the specified language fall
00046 back to English if nothing found (e.g. 'es' Español,
00047 'de' Deutsch ... etc). Not all sites or grabbers
00048 support this option.
00049 -p PAGE NUMBER, --pagenumber=PAGE NUMBER
00050 Display specific page of the search results. Default
00051 is page 1. Page number is ignored with the Tree View
00052 option (-T).
00053 -S, --search Search for videos
00054 -T, --treeview Display a Tree View of a sites videos
00055
00056 > ./pbs.py -v
00057 <grabber>
00058 <name>PBS</name>
00059 <author>R.D. Vaughan</author>
00060 <thumbnail>pbs.png</thumbnail>
00061 <command>pbs.py</command>
00062 <type>video</type>
00063 <description>Discover award-winning programming right at your fingertips on PBS Video. Catch the episodes you may have missed and watch your favorite shows whenever you want.</description>
00064 <version>v0.10</version>
00065 <search>true</search>
00066 <tree>true</tree>
00067 </grabber>
00068
00069 > ./pbs.py -S "Dinosaurs"
00070
00071 > ./pbs.py -T
00072 '''
00073 __search_max_page_items__ = 20
00074 __tree_max_page_items__ = 20
00075
00076 import sys, os
00077
00078
00079 class OutStreamEncoder(object):
00080 """Wraps a stream with an encoder"""
00081 def __init__(self, outstream, encoding=None):
00082 self.out = outstream
00083 if not encoding:
00084 self.encoding = sys.getfilesystemencoding()
00085 else:
00086 self.encoding = encoding
00087
00088 def write(self, obj):
00089 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00090 if isinstance(obj, unicode):
00091 try:
00092 self.out.write(obj.encode(self.encoding))
00093 except IOError:
00094 pass
00095 else:
00096 try:
00097 self.out.write(obj)
00098 except IOError:
00099 pass
00100
00101 def __getattr__(self, attr):
00102 """Delegate everything but write to the stream"""
00103 return getattr(self.out, attr)
00104 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
00105 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
00106
00107
00108
00109
00110 try:
00111 '''Import the common python class
00112 '''
00113 import nv_python_libs.common.common_api as common_api
00114 except Exception, e:
00115 sys.stderr.write('''
00116 The subdirectory "nv_python_libs/common" containing the modules mashups_api.py and
00117 mashups_exceptions.py (v0.1.3 or greater),
00118 They should have been included with the distribution of MythNetvision
00119 Error(%s)
00120 ''' % e)
00121 sys.exit(1)
00122
00123 if common_api.__version__ < '0.1.3':
00124 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__)
00125 sys.exit(1)
00126
00127
00128
00129 try:
00130 '''Import the python mashups support classes
00131 '''
00132 import nv_python_libs.pbs.pbs_api as target
00133 except Exception, e:
00134 sys.stderr.write('''
00135 The subdirectory "nv_python_libs/pbs" containing the modules pbs_api and
00136 pbs_exceptions.py (v0.1.0 or greater),
00137 They should have been included with the distribution of pbs.py.
00138 Error(%s)
00139 ''' % e)
00140 sys.exit(1)
00141 if target.__version__ < '0.1.0':
00142 sys.stderr.write("\n! Error: Your current installed pbs_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
00143 sys.exit(1)
00144
00145
00146 try:
00147 import nv_python_libs.mainProcess as process
00148 except Exception, e:
00149 sys.stderr.write('''
00150 The python script "nv_python_libs/mainProcess.py" must be present.
00151 Error(%s)
00152 ''' % e)
00153 sys.exit(1)
00154
00155 if process.__version__ < '0.2.0':
00156 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__)
00157 sys.exit(1)
00158
00159 if __name__ == '__main__':
00160
00161 apikey = ""
00162
00163 target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
00164
00165 target.common = common_api.Common()
00166 main = process.mainProcess(target, apikey, )
00167 main.grabberInfo = {}
00168 main.grabberInfo['title'] = __title__
00169 main.grabberInfo['command'] = u'pbs.py'
00170 main.grabberInfo['mashup_title'] = __mashup_title__
00171 main.grabberInfo['author'] = __author__
00172 main.grabberInfo['thumbnail'] = 'pbs.png'
00173 main.grabberInfo['type'] = ['video', ]
00174 main.grabberInfo['desc'] = u"Discover award-winning programming right at your fingertips on PBS Video. Catch the episodes you may have missed and watch your favorite shows whenever you want."
00175 main.grabberInfo['version'] = __version__
00176 main.grabberInfo['search'] = target.common.checkIfDBItem('dummy', {'feedtitle': __title__, })
00177 main.grabberInfo['tree'] = True
00178 main.grabberInfo['html'] = False
00179 main.grabberInfo['usage'] = __usage_examples__
00180 main.grabberInfo['SmaxPage'] = __search_max_page_items__
00181 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
00182 main.main()