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