00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 __title__ ="Comedy Central";
00024 __mashup_title__ = "comedycentralMashup"
00025 __author__="R.D. Vaughan"
00026 __version__="v0.10"
00027
00028
00029 __usage_examples__ ='''
00030 (Option Help)
00031 > ./comedycentral.py -h
00032 Usage: ./comedycentral.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 -T, --treeview Display a Tree View of a sites videos
00054
00055 > ./comedycentral.py -v
00056
00057 > ./comedycentral.py -T
00058 '''
00059 __search_max_page_items__ = 20
00060 __tree_max_page_items__ = 20
00061
00062 import sys, os
00063
00064
00065 class OutStreamEncoder(object):
00066 """Wraps a stream with an encoder"""
00067 def __init__(self, outstream, encoding=None):
00068 self.out = outstream
00069 if not encoding:
00070 self.encoding = sys.getfilesystemencoding()
00071 else:
00072 self.encoding = encoding
00073
00074 def write(self, obj):
00075 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00076 if isinstance(obj, unicode):
00077 try:
00078 self.out.write(obj.encode(self.encoding))
00079 except IOError:
00080 pass
00081 else:
00082 try:
00083 self.out.write(obj)
00084 except IOError:
00085 pass
00086
00087 def __getattr__(self, attr):
00088 """Delegate everything but write to the stream"""
00089 return getattr(self.out, attr)
00090 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
00091 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
00092
00093
00094
00095
00096
00097 try:
00098 '''Import the common python class
00099 '''
00100 import nv_python_libs.common.common_api as common_api
00101 except Exception, e:
00102 sys.stderr.write('''
00103 The subdirectory "nv_python_libs/common" containing the modules mashups_api.py and
00104 mashups_exceptions.py (v0.1.3 or greater),
00105 They should have been included with the distribution of MythNetvision
00106 Error(%s)
00107 ''' % e)
00108 sys.exit(1)
00109
00110 if common_api.__version__ < '0.1.3':
00111 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__)
00112 sys.exit(1)
00113
00114
00115
00116 try:
00117 '''Import the python mashups support classes
00118 '''
00119 import nv_python_libs.mashups.mashups_api as target
00120 except Exception, e:
00121 sys.stderr.write('''
00122 The subdirectory "nv_python_libs/mashups" containing the modules mashups_api and
00123 mashups_exceptions.py (v0.1.0 or greater),
00124 They should have been included with the distribution of comedycentral.py.
00125 Error(%s)
00126 ''' % e)
00127 sys.exit(1)
00128 if target.__version__ < '0.1.0':
00129 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__)
00130 sys.exit(1)
00131
00132
00133 try:
00134 import nv_python_libs.mainProcess as process
00135 except Exception, e:
00136 sys.stderr.write('''
00137 The python script "nv_python_libs/mainProcess.py" must be present.
00138 Error(%s)
00139 ''' % e)
00140 sys.exit(1)
00141
00142 if process.__version__ < '0.2.0':
00143 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__)
00144 sys.exit(1)
00145
00146 if __name__ == '__main__':
00147
00148 apikey = ""
00149
00150 target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
00151
00152 target.common = common_api.Common()
00153 main = process.mainProcess(target, apikey, )
00154 main.grabberInfo = {}
00155 main.grabberInfo['title'] = __title__
00156 main.grabberInfo['command'] = u'comedycentral.py'
00157 main.grabberInfo['mashup_title'] = __mashup_title__
00158 main.grabberInfo['author'] = __author__
00159 main.grabberInfo['thumbnail'] = 'comedycentral.png'
00160 main.grabberInfo['type'] = ['video', ]
00161 main.grabberInfo['desc'] = u"Videos of your favorite shows, whenever you want them!"
00162 main.grabberInfo['version'] = __version__
00163 main.grabberInfo['search'] = False
00164 main.grabberInfo['tree'] = True
00165 main.grabberInfo['html'] = False
00166 main.grabberInfo['usage'] = __usage_examples__
00167 main.grabberInfo['SmaxPage'] = __search_max_page_items__
00168 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
00169 main.main()