[961c11]: / plugin.video.rt / default.py  Maximize  Restore  History

Download this file

291 lines (230 with data), 11.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# -*- coding: utf-8 -*-
# Russia Today (RT) News
import urllib, urllib2, cookielib, datetime, time, re, os
import xbmcplugin, xbmcgui, xbmcaddon, xbmcvfs
import cgi, gzip
from StringIO import StringIO
USER_AGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
GENRE_NEWS = "News"
UTF8 = 'utf-8'
RTBASE_URL = 'http://rt.com'
RTLIVE_BASE = 'rtmp://rt.fms-04.visionip.tv/live/'
addon = xbmcaddon.Addon('plugin.video.rt')
__addonname__ = addon.getAddonInfo('name')
__language__ = addon.getLocalizedString
home = addon.getAddonInfo('path').decode(UTF8)
icon = xbmc.translatePath(os.path.join(home, 'icon.png'))
fanart = xbmc.translatePath(os.path.join(home, 'fanart.jpg'))
def log(txt):
message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore'))
xbmc.log(msg=message, level=xbmc.LOGDEBUG)
def _parse_argv():
global url,name,iconimage, mode, playlist,fchan,fres,fhost,fname,fepg,fanArt
params = {}
try:
params = dict( arg.split( "=" ) for arg in ((sys.argv[2][1:]).split( "&" )) )
except:
params = {}
url = demunge(params.get("url",None))
name = demunge(params.get("name",""))
iconimage = demunge(params.get("iconimage",""))
fanArt = demunge(params.get("fanart",""))
playlist = demunge(params.get("playlist",""))
fchan = demunge(params.get("fchan",""))
fres = demunge(params.get("fres",""))
fhost = demunge(params.get("fhost",""))
fname = demunge(params.get("fname",""))
fepg = demunge(params.get("fepg",None))
try:
playlist=eval(playlist.replace('|',','))
except:
pass
try:
mode = int(params.get( "mode", None ))
except:
mode = None
def demunge(munge):
try:
munge = urllib.unquote_plus(munge).decode(UTF8)
except:
pass
return munge
def getRequest(url):
log("getRequest URL:"+str(url))
headers = {'User-Agent':USER_AGENT, 'Accept':"text/html", 'Accept-Encoding':'gzip,deflate,sdch', 'Accept-Language':'en-US,en;q=0.8', 'Cookie':'hide_ce=true'}
req = urllib2.Request(url.encode(UTF8), None, headers)
try:
response = urllib2.urlopen(req)
if response.info().getheader('Content-Encoding') == 'gzip':
log("Content Encoding == gzip")
buf = StringIO( response.read())
f = gzip.GzipFile(fileobj=buf)
link1 = f.read()
else:
link1=response.read()
except:
link1 = ""
link1 = str(link1).replace('\n','')
return(link1)
def getSources():
log("main page")
link = getRequest(RTBASE_URL+"/shows/")
addDir("RT Live","plugin://plugin.video.rt/",17,icon,fanart,"RT Live",GENRE_NEWS,"",False)
match=re.compile('<p class="shows-gallery_bottom_link"><a href="(.+?)".+?<img src="(.+?)".+?class="shows-gallery_bottom_text_header">(.+?)</span>(.+?)</p>').findall(link)
for caturl,caticon,cattitle,catdesc in match:
catdesc = catdesc.replace('<P>','').replace('<p>','').replace('</P>','')
caticon = caticon.replace('.a.','.gp.')
caticon = RTBASE_URL+caticon
try:
addDir(cattitle.encode(UTF8, 'ignore'),caturl.encode(UTF8),18,caticon,caticon,catdesc,GENRE_NEWS,"",False)
except:
log("Problem adding directory")
def play_playlist(name, list):
playlist = xbmc.PlayList(1)
playlist.clear()
item = 0
for i in list:
item += 1
info = xbmcgui.ListItem('%s) %s' %(str(item),name))
playlist.add(i, info)
xbmc.executebuiltin('playlist.playoffset(video,0)')
def addDir(name,url,mode,iconimage,fanart,description,genre,date,showcontext=True,playlist=None,autoplay=False):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)
dir_playable = False
if mode != 12:
u += "&name="+urllib.quote_plus(name)+"&fanart="+urllib.quote_plus(fanart)
dir_image = "DefaultFolder.png"
dir_folder = True
else:
dir_image = "DefaultVideo.png"
dir_folder = False
dir_playable = True
ok=True
liz=xbmcgui.ListItem(name, iconImage=dir_image, thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description, "Genre": genre, "Year": date } )
liz.setProperty( "Fanart_Image", fanart )
if dir_playable == True:
liz.setProperty('IsPlayable', 'true')
if not playlist is None:
playlist_name = name.split(') ')[1]
contextMenu_ = [('Play '+playlist_name+' PlayList','XBMC.RunPlugin(%s?mode=13&name=%s&playlist=%s)' %(sys.argv[0], urllib.quote_plus(playlist_name), urllib.quote_plus(str(playlist).replace(',','|'))))]
liz.addContextMenuItems(contextMenu_)
if autoplay == True:
xbmc.PlayList(1).add(u, liz)
else:
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=dir_folder)
return ok
def addLink(url,name,iconimage,fanart,description,genre,date,showcontext=True,playlist=None, autoplay=False):
return addDir(name,url,12,iconimage,fanart,description,genre,date,showcontext,playlist,autoplay)
# MAIN EVENT PROCESSING STARTS HERE
xbmcplugin.setContent(int(sys.argv[1]), 'movies')
try:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
except:
pass
try:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
except:
pass
try:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
except:
pass
try:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_GENRE)
except:
pass
url=name=iconimage=mode=playlist=fchan=fres=fhost=fname=fepg=None
_parse_argv()
log("Mode: "+str(mode))
if not url is None:
try:
log("URL: "+str(url.encode(UTF8)))
except:
pass
try:
log("Name: "+str(name))
except:
pass
auto_play = False
if mode==None:
log("getSources")
getSources()
if addon.getSetting('auto_play') == "true":
current_play=""
try:
current_play = xbmc.Player().getPlayingFile()
except:
auto_play = True
xbmc.PlayList(1).clear()
elif mode==12:
log("setResolvedUrl")
item = xbmcgui.ListItem(path=url)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
elif mode==13:
log("play_playlist")
play_playlist(name, playlist)
if (mode==17) or (auto_play == True):
res_sel = ["HD","SD","SDh","SDq"]
res_names = ["720p","360p","240p","180p"]
i = int(addon.getSetting('rt_res'))
res = res_sel[i]
res_str = res_names[i]
if (auto_play != True):
addLink(RTLIVE_BASE+"rt-global-live-"+str(res),"RT Global Live "+str(res_str),icon,fanart,"RT Global Live "+str(res_str),GENRE_NEWS,"",False)
addLink(RTLIVE_BASE+"rt-america-live-"+str(res),"RT America Live "+str(res_str),icon,fanart,"RT America Live "+str(res_str),GENRE_NEWS,"",False)
addLink(RTLIVE_BASE+"rt-doc-live-"+str(res),"RT Documentary Live "+str(res_str),icon,fanart,"RT Documentary Live "+str(res_str),GENRE_NEWS,"",False)
addLink(RTLIVE_BASE+"rt-enespanol-live-"+str(res),"RT Espanol Live "+str(res_str),icon,fanart,"RT Espanol Live "+str(res_str),GENRE_NEWS,"",False)
addLink(RTLIVE_BASE+"rt-rusiyaalyaum-live-"+str(res),"RT Arabic Live "+str(res_str),icon,fanart,"RT Arabic Live "+str(res_str),GENRE_NEWS,"",False)
else:
if mode != 17:
addLink(RTLIVE_BASE+"rt-global-live-"+str(res),"RT Global Live "+str(res_str),icon,fanart,"RT Global Live "+str(res_str),GENRE_NEWS,"",False, autoplay=True)
xbmc.executebuiltin('playlist.playoffset(video,0)')
elif mode==18:
log("Processing subcategory item")
link = getRequest("http://rt.com"+url)
match = re.compile('<dt class="(.+?)"(.+?)</dl>').findall(link)
for classtype, classdata in match:
if "programm" in classtype:
match_str = '<a href="(.+?)".+?class="header">(.+?)<.+?<img src="(.+?)".+?<dd>(.+?)<span class="time">(.+?)<'
else:
match_str = '<a href="(.+?)".+?<img src="(.+?)".+class="header">(.+?)</a>.+?<p>(.+?)</p.+?class="time">(.+?)<'
match = re.compile(match_str).findall(classdata)
for pgurl,imgurl,cattitle,catdesc, cattime in match:
if "programm" in classtype:
imgurl,cattitle = cattitle,imgurl # swap them
caturl = "plugin://plugin.video.rt/?url="+RTBASE_URL+pgurl+"&name="+urllib.quote_plus(cattitle)+"&mode=19"
caticon = RTBASE_URL+imgurl
catdesc = catdesc.strip()
try:
addLink(caturl.encode(UTF8),cattitle,caticon,fanArt,cattime+"\n"+catdesc,GENRE_NEWS,"")
except:
log("Problem adding directory")
match = re.compile('<a class="pagerLink" href="(.+?)"').findall(link)
for page in match:
addDir("-> Next Page",page,18,fanArt,fanArt,"Next Page",GENRE_NEWS,"",False)
addDir("<< Home Page","",None,fanArt,fanArt,"Home Page",GENRE_NEWS,"",False)
elif mode==19:
log("Processing play category item")
link=getRequest(url)
bad_match = False
if not ("cdnapi.kaltura.com" in link):
match = re.compile('<span class="time">(.+?)<.+?<div class="video_block".+?"thumbnailUrl" content="(.+?)".+?"contentURL" content="(.+?)".+?<p>(.+?)</p>').findall(link)
if not match:
bad_match = True
dialog = xbmcgui.Dialog()
dialog.ok(__language__(30000), '',__language__(30001))
else:
for viddate,icon,vidurl,viddesc in match:
if "comhttp:" in vidurl:
vidurl = vidurl.replace(RTBASE_URL,"")
else:
match = re.compile('<meta name="description" content="(.+?)".+?<link rel="image_src" href="(.+?)".+?<span class="time">(.+?)<.+?<script src="(.+?)embedIframeJs/.+?"entry_id": "(.+?)"').findall(link)
for viddesc,icon,viddate,vidurl,entry_id in match:
vidurl = vidurl+"playManifest/entryId/"+entry_id+"/flavorId/0_ib2gjoc9/format/url/protocol/http/a.mp4"
if not bad_match:
item = xbmcgui.ListItem(path=vidurl.encode(UTF8), iconImage="DefaultVideo.png", thumbnailImage=icon)
item.setInfo( type="Video", infoLabels={ "Title": name, "Plot": viddate+"\n"+viddesc } )
item.setProperty("IsPlayable","true")
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
xbmcplugin.endOfDirectory(int(sys.argv[1]))