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
00026
00027
00028 __title__ ="MTV";
00029 __author__="R.D. Vaughan"
00030 __version__="0.23"
00031
00032
00033
00034
00035
00036
00037
00038
00039 __usage_examples__ ='''
00040 (Option Help)
00041 > ./mtv.py -h
00042 Usage: ./mtv.py -hduvlST [parameters] <search text>
00043 Version: v0.2.0 Author: R.D.Vaughan
00044
00045 For details on the MythTV Netvision plugin see the wiki page at:
00046 http://www.mythtv.org/wiki/MythNetvision
00047
00048 Options:
00049 -h, --help show this help message and exit
00050 -d, --debug Show debugging info (URLs, raw XML ... etc, info
00051 varies per grabber)
00052 -u, --usage Display examples for executing the script
00053 -v, --version Display grabber name and supported options
00054 -l LANGUAGE, --language=LANGUAGE
00055 Select data that matches the specified language fall
00056 back to English if nothing found (e.g. 'es' EspaƱol,
00057 'de' Deutsch ... etc). Not all sites or grabbers
00058 support this option.
00059 -p PAGE NUMBER, --pagenumber=PAGE NUMBER
00060 Display specific page of the search results. Default
00061 is page 1. Page number is ignored with the Tree View
00062 option (-T).
00063 -S, --search Search for videos
00064 -T, --treeview Display a Tree View of a sites videos
00065
00066
00067 (Search MTV for videos matching search words)
00068 > ./mtv.py -S "Sleeping" -p 2
00069 <?xml version="1.0" encoding="UTF-8"?>
00070 <rss version="2.0"
00071 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00072 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00073 xmlns:cnettv="http://cnettv.com/mrss/"
00074 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00075 xmlns:media="http://search.yahoo.com/mrss/"
00076 xmlns:atom="http://www.w3.org/2005/Atom"
00077 xmlns:amp="http://www.adobe.com/amp/1.0"
00078 xmlns:dc="http://purl.org/dc/elements/1.1/">
00079 <channel>
00080 <title>MTV</title>
00081 <link>http://www.mtv.com</link>
00082 <description>Visit MTV (Music Television) for TV shows, music videos, celebrity photos, news.</description>
00083 <numresults>41</numresults>
00084 <returned>20</returned>
00085 <startindex>40</startindex>
00086 <item>
00087 <title>While You Were Sleeping</title>
00088 <author>Elvis Perkins</author>
00089 <pubDate>Tue, 20 Feb 2007 00:00:00 GMT</pubDate>
00090 <description>Elvis Perkins - While You Were Sleeping - XL Recordings</description>
00091 <link>http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:170754</link>
00092 <media:group>
00093 <media:thumbnail url='http://www.mtv.com/shared/promoimages/bands/p/perkins_elvis/while_you_were_sleeping/281x211.jpg'/>
00094 <media:content url='http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:170754' duration='229' width='' height='' lang=''/>
00095 </media:group>
00096 <rating></rating>
00097 </item>
00098 ...
00099 <item>
00100 <title>She is Love</title>
00101 <author>Parachute</author>
00102 <pubDate>Mon, 16 Mar 2009 00:00:00 GMT</pubDate>
00103 <description>Parachute - She is Love - Mercury</description>
00104 <link>http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:353524</link>
00105 <media:group>
00106 <media:thumbnail url='http://www.mtv.com/shared/promoimages/bands/p/parachute/she_is_love/281x211.jpg'/>
00107 <media:content url='http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:353524' duration='226.76' width='' height='' lang=''/>
00108 </media:group>
00109 <rating></rating>
00110 </item>
00111 </channel>
00112 </rss>
00113
00114
00115 (Option Tree view)
00116 > ./mtv.py -T
00117 <?xml version="1.0" encoding="UTF-8"?>
00118 <rss version="2.0"
00119 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00120 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00121 xmlns:cnettv="http://cnettv.com/mrss/"
00122 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00123 xmlns:media="http://search.yahoo.com/mrss/"
00124 xmlns:atom="http://www.w3.org/2005/Atom"
00125 xmlns:amp="http://www.adobe.com/amp/1.0"
00126 xmlns:dc="http://purl.org/dc/elements/1.1/">
00127 <channel>
00128 <title>MTV</title>
00129 <link>http://www.mtv.com</link>
00130 <description>Visit MTV (Music Television) for TV shows, music videos, celebrity photos, news.</description>
00131 <numresults>5050</numresults>
00132 <returned>20</returned>
00133 <startindex>20</startindex>
00134 <directory name="New over the last 3 months" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/topics/recent.png">
00135 <directory name="Rock" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/directories/music_genres/rock.png">
00136 <item>
00137 <title>Useless</title>
00138 <author>Tiny Animals</author>
00139 <pubDate>Thu, 17 Dec 2009 00:00:00 GMT</pubDate>
00140 <description></description>
00141 <link>http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:444694</link>
00142 <media:group>
00143 <media:thumbnail url='http://www.mtv.com/shared/promoimages/bands/t/tiny_animals/useless/281x211.jpg'/>
00144 <media:content url='http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:444694' duration='212.88' width='' height='' lang='en'/>
00145 </media:group>
00146 <rating></rating>
00147 </item>
00148 ...
00149 <item>
00150 <title>Our Velocity</title>
00151 <author>Maximo Park</author>
00152 <pubDate>Mon, 02 Apr 2007 00:00:00 GMT</pubDate>
00153 <description></description>
00154 <link>http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:149873</link>
00155 <media:group>
00156 <media:thumbnail url='http://www.mtv.com/shared/promoimages/bands/m/maximo_park/our_velocity/281x211.jpg'/>
00157 <media:content url='http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:149873' duration='218' width='' height='' lang='en'/>
00158 </media:group>
00159 <rating></rating>
00160 </item>
00161 </directory>
00162 </directory>
00163 </channel>
00164 </rss>
00165 '''
00166 __search_max_page_items__ = 10
00167 __tree_max_page_items__ = 20
00168
00169 import sys, os
00170
00171 class OutStreamEncoder(object):
00172 """Wraps a stream with an encoder"""
00173 def __init__(self, outstream, encoding=None):
00174 self.out = outstream
00175 if not encoding:
00176 self.encoding = sys.getfilesystemencoding()
00177 else:
00178 self.encoding = encoding
00179
00180 def write(self, obj):
00181 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00182 if isinstance(obj, unicode):
00183 try:
00184 self.out.write(obj.encode(self.encoding))
00185 except IOError:
00186 pass
00187 else:
00188 try:
00189 self.out.write(obj)
00190 except IOError:
00191 pass
00192
00193 def __getattr__(self, attr):
00194 """Delegate everything but write to the stream"""
00195 return getattr(self.out, attr)
00196 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
00197 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
00198
00199
00200
00201
00202
00203
00204 try:
00205 import nv_python_libs.mtv.mtv_api as target
00206 except Exception, e:
00207 sys.stderr.write('''
00208 The subdirectory "nv_python_libs/mtv" containing the modules mtv_api.py (v0.2.0 or greater),
00209 They should have been included with the distribution of mtv.py.
00210 Error(%s)
00211 ''' % e)
00212 sys.exit(1)
00213
00214 if target.__version__ < '0.2.0':
00215 sys.stderr.write("\n! Error: Your current installed mtv_api.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % target.__version__)
00216 sys.exit(1)
00217
00218
00219
00220 try:
00221 import nv_python_libs.mainProcess as process
00222 except Exception, e:
00223 sys.stderr.write('''
00224 The python script "nv_python_libs/mainProcess.py" must be present.
00225 Error(%s)
00226 ''' % e)
00227 sys.exit(1)
00228
00229 if process.__version__ < '0.2.0':
00230 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__)
00231 sys.exit(1)
00232
00233 if __name__ == '__main__':
00234
00235 apikey = ""
00236 main = process.mainProcess(target, apikey, )
00237 main.grabberInfo = {}
00238 main.grabberInfo['title'] = __title__
00239 main.grabberInfo['command'] = u'mtv.py'
00240 main.grabberInfo['author'] = __author__
00241 main.grabberInfo['thumbnail'] = 'mtv.png'
00242 main.grabberInfo['type'] = ['video']
00243 main.grabberInfo['desc'] = u"Visit MTV (Music Television) for TV shows, music videos, celebrity photos, and news."
00244 main.grabberInfo['version'] = __version__
00245 main.grabberInfo['search'] = True
00246 main.grabberInfo['tree'] = True
00247 main.grabberInfo['html'] = False
00248 main.grabberInfo['usage'] = __usage_examples__
00249 main.grabberInfo['SmaxPage'] = __search_max_page_items__
00250 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
00251 main.main()