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__ ="BBC iPlayer";
00026 __mashup_title__ = "bbcipplayer"
00027 __author__="R.D. Vaughan"
00028 __version__="0.15"
00029
00030
00031
00032
00033
00034
00035
00036 __usage_examples__ ='''
00037 (Option Help)
00038 > ./bbciplayer.py -h
00039 Usage: ./bbciplayer.py -hduvlST [parameters] <search text>
00040 Version: v0.1.2 Author: R.D.Vaughan
00041
00042 For details on the MythTV Netvision plugin see the wiki page at:
00043 http://www.mythtv.org/wiki/MythNetvision
00044
00045 Options:
00046 -h, --help show this help message and exit
00047 -d, --debug Show debugging info (URLs, raw XML ... etc, info
00048 varies per grabber)
00049 -u, --usage Display examples for executing the script
00050 -v, --version Display grabber name and supported options
00051 -l LANGUAGE, --language=LANGUAGE
00052 Select data that matches the specified language fall
00053 back to English if nothing found (e.g. 'es' EspaƱol,
00054 'de' Deutsch ... etc). Not all sites or grabbers
00055 support this option.
00056 -p PAGE NUMBER, --pagenumber=PAGE NUMBER
00057 Display specific page of the search results. Default
00058 is page 1. Page number is ignored with the Tree View
00059 option (-T).
00060 -S, --search Search for videos
00061 -T, --treeview Display a Tree View of a sites videos
00062
00063 > ./bbciplayer.py -v
00064 <grabber>
00065 <name>BBC iPlayer</name>
00066 <author>R.D. Vaughan</author>
00067 <thumbnail>bbciplayer.png</thumbnail>
00068 <type>video</type>
00069 <description>BBC iPlayer is our service that lets you catch up with radio and television programmes from the past week.</description>
00070 <version>v0.13</version>
00071 <search>true</search>
00072 <tree>true</tree>
00073 </grabber>
00074
00075 > ./bbciplayer.py -S "Doctor Who"
00076 <?xml version="1.0" encoding="UTF-8"?>
00077 <rss version="2.0" xmlns:amp="http://www.adobe.com/amp/1.0"
00078 xmlns:atom="http://www.w3.org/2005/Atom"
00079 xmlns:cnettv="http://cnettv.com/mrss/"
00080 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00081 xmlns:creativecommons="http://backend.userland.com/creativeCommonsRssModule"
00082 xmlns:dc="http://purl.org/dc/elements/1.1/"
00083 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/">
00084 <channel>
00085 <title>BBC iPlayer</title>
00086 <link>http://www.bbc.co.uk</link>
00087 <description>BBC iPlayer is our service that lets you catch up with radio and television programmes from the past week.</description>
00088 <numresults>7</numresults>
00089 <returned>7</returned>
00090 <startindex>7</startindex>
00091 <item>
00092 <title>Doctor Who - Series 4 - 11. Turn Left</title>
00093 <author>British Broadcasting Corporation</author>
00094 <pubDate>Wed, 24 Mar 2010 18:35:41 GMT</pubDate>
00095 <description>Can Donna and Rose stop the approaching Darkness? (R)</description>
00096 <link>http://www.bbc.co.uk/iplayer/episode/b00c7ytx/Doctor_Who_Series_4_Turn_Left/</link>
00097 <media:group>
00098 <media:thumbnail url="http://node1.bbcimg.co.uk/iplayer/images/episode/b00c7ytx_120_68.jpg"/>
00099 <media:content duration="" height="" lang=""
00100 url="http://www.bbc.co.uk/iplayer/episode/b00c7ytx/Doctor_Who_Series_4_Turn_Left/" width=""/>
00101 </media:group>
00102 <rating>0.0</rating>
00103 </item>
00104 ...
00105 <item>
00106 <title>Doctor Who Confidential - Series 4 - 13. The End of an Era</title>
00107 <author>British Broadcasting Corporation</author>
00108 <pubDate>Wed, 24 Mar 2010 18:35:41 GMT</pubDate>
00109 <description>The series finale as the Doctor's arch enemy brings the universe to the edge of extinction (R)</description>
00110 <link>http://www.bbc.co.uk/iplayer/episode/b00cgphl/Doctor_Who_Confidential_Series_4_The_End_of_an_Era/</link>
00111 <media:group>
00112 <media:thumbnail url="http://node1.bbcimg.co.uk/iplayer/images/episode/b00cgphl_120_68.jpg"/>
00113 <media:content duration="" height="" lang=""
00114 url="http://www.bbc.co.uk/iplayer/episode/b00cgphl/Doctor_Who_Confidential_Series_4_The_End_of_an_Era/" width=""/>
00115 </media:group>
00116 <rating>0.0</rating>
00117 </item>
00118 </channel>
00119 </rss>
00120
00121 > ./bbciplayer.py -T
00122 <?xml version="1.0" encoding="UTF-8"?>
00123 <rss version="2.0" xmlns:amp="http://www.adobe.com/amp/1.0"
00124 xmlns:atom="http://www.w3.org/2005/Atom"
00125 xmlns:cnettv="http://cnettv.com/mrss/"
00126 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00127 xmlns:creativecommons="http://backend.userland.com/creativeCommonsRssModule"
00128 xmlns:dc="http://purl.org/dc/elements/1.1/"
00129 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/">
00130 <channel>
00131 <title>BBC iPlayer</title>
00132 <link>http://www.bbc.co.uk</link>
00133 <description>BBC iPlayer is our service that lets you catch up with radio and television programmes from the past week.</description>
00134 <numresults>1</numresults>
00135 <returned>1</returned>
00136 <startindex>1</startindex>
00137 <directory name="BBC iPlayer" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/bbciplayer.png">
00138 <directory name="BBC iPlayer - TV Highlights" thumbnail="/usr/local/share/mythtv/mythnetvision/icons/bbciplayer.png">
00139 <item>
00140 <title>Great Ormond Street: Pushing the Boundaries</title>
00141 <author>BBC</author>
00142 <pubDate>Wed, 07 Apr 2010 17:00:49 GMT</pubDate>
00143 <description>A look at the work of the largest children&apos;s cardiac unit in the UK.</description>
00144 <link>http://localhost:8080/emml/cgi-bin/bbciplayer_embedded.py?videocode=b00s02ct</link>
00145 <mrss:group xmlns:mrss="http://search.yahoo.com/mrss/">
00146 <mrss:thumbnail url="http://node2.bbcimg.co.uk/iplayer/images/episode/b00s02ct_150_84.jpg"/>
00147 <mrss:content duration="" height="" lang=""
00148 url="http://localhost:8080/emml/cgi-bin/bbciplayer_embedded.py?videocode=b00s02ct" width=""/>
00149 </mrss:group>
00150 <rating>0.0</rating>
00151 </item>
00152 ...
00153 <item>
00154 <title>The Real Hustle: Series 7: On Holiday - Cutdowns: Episode 8</title>
00155 <author>BBC</author>
00156 <pubDate>Fri, 02 Apr 2010 07:29:46 GMT</pubDate>
00157 <description>Paul relieves some unsuspecting tourists of their spending money in Oxford.</description>
00158 <link>http://localhost:8080/emml/cgi-bin/bbciplayer_embedded.py?videocode=b00rw6xb</link>
00159 <mrss:group xmlns:mrss="http://search.yahoo.com/mrss/">
00160 <mrss:thumbnail url="http://node2.bbcimg.co.uk/iplayer/images/episode/b00rw6xb_150_84.jpg"/>
00161 <mrss:content duration="" height="" lang=""
00162 url="http://localhost:8080/emml/cgi-bin/bbciplayer_embedded.py?videocode=b00rw6xb" width=""/>
00163 </mrss:group>
00164 <rating>0.0</rating>
00165 </item>
00166 </directory>
00167 </directory>
00168 </channel>
00169 </rss>
00170 '''
00171 __search_max_page_items__ = 20
00172 __tree_max_page_items__ = 20
00173
00174 import sys, os
00175
00176
00177 class OutStreamEncoder(object):
00178 """Wraps a stream with an encoder"""
00179 def __init__(self, outstream, encoding=None):
00180 self.out = outstream
00181 if not encoding:
00182 self.encoding = sys.getfilesystemencoding()
00183 else:
00184 self.encoding = encoding
00185
00186 def write(self, obj):
00187 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00188 if isinstance(obj, unicode):
00189 try:
00190 self.out.write(obj.encode(self.encoding))
00191 except IOError:
00192 pass
00193 else:
00194 try:
00195 self.out.write(obj)
00196 except IOError:
00197 pass
00198
00199 def __getattr__(self, attr):
00200 """Delegate everything but write to the stream"""
00201 return getattr(self.out, attr)
00202 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
00203 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
00204
00205
00206
00207
00208 try:
00209 '''Import the common python class
00210 '''
00211 import nv_python_libs.common.common_api as common_api
00212 except Exception, e:
00213 sys.stderr.write('''
00214 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
00215 common_exceptions.py (v0.1.3 or greater),
00216 They should have been included with the distribution of MythNetvision
00217 Error(%s)
00218 ''' % e)
00219 sys.exit(1)
00220 if common_api.__version__ < '0.1.3':
00221 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__)
00222 sys.exit(1)
00223
00224
00225
00226 try:
00227 '''Import the python bbciplayer support classes
00228 '''
00229 import nv_python_libs.bbciplayer.bbciplayer_api as target
00230 except Exception, e:
00231 sys.stderr.write('''
00232 The subdirectory "nv_python_libs/bbciplayer" containing the modules bbciplayer_api and
00233 bbciplayer_exceptions.py (v0.1.0 or greater),
00234 They should have been included with the distribution of bbciplayer.py.
00235 Error(%s)
00236 ''' % e)
00237 sys.exit(1)
00238 if target.__version__ < '0.1.0':
00239 sys.stderr.write("\n! Error: Your current installed bbciplayer_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
00240 sys.exit(1)
00241
00242
00243 try:
00244 import nv_python_libs.mainProcess as process
00245 except Exception, e:
00246 sys.stderr.write('''
00247 The python script "nv_python_libs/mainProcess.py" must be present.
00248 Error(%s)
00249 ''' % e)
00250 sys.exit(1)
00251
00252 if process.__version__ < '0.2.0':
00253 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__)
00254 sys.exit(1)
00255
00256 if __name__ == '__main__':
00257
00258 apikey = ""
00259
00260 target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
00261
00262 target.common = common_api.Common()
00263 main = process.mainProcess(target, apikey, )
00264 main.grabberInfo = {}
00265 main.grabberInfo['title'] = __title__
00266 main.grabberInfo['mashup_title'] = __mashup_title__
00267 main.grabberInfo['command'] = u'bbciplayer.py'
00268 main.grabberInfo['author'] = __author__
00269 main.grabberInfo['thumbnail'] = 'bbciplayer.png'
00270 main.grabberInfo['type'] = ['video', ]
00271 main.grabberInfo['desc'] = u"BBC iPlayer is our service that lets you catch up with radio and television programmes from the past week."
00272 main.grabberInfo['version'] = __version__
00273 main.grabberInfo['search'] = True
00274 main.grabberInfo['tree'] = True
00275 main.grabberInfo['html'] = False
00276 main.grabberInfo['usage'] = __usage_examples__
00277 main.grabberInfo['SmaxPage'] = __search_max_page_items__
00278 main.grabberInfo['TmaxPage'] = __tree_max_page_items__
00279 main.main()