Advertisement
Guest User

Untitled

a guest
May 31st, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.38 KB | None | 0 0
  1. import urllib,urllib2,re,xbmcplugin,xbmcgui, string, xbmcaddon
  2. import os
  3.  
  4. pluginhandle = int(sys.argv[1])
  5. shownail = xbmc.translatePath(os.path.join(os.getcwd().replace(';', ''),"icon.png"))
  6. fanart = xbmc.translatePath(os.path.join(os.getcwd().replace(';', ''),'fanart.jpg'))
  7. xbmcplugin.setPluginFanart(pluginhandle, fanart, color2='0xFFFF3300')
  8. TVShowTitle = 'The Colbert Report'
  9.  
  10. addon = xbmcaddon.Addon(id='plugin.video.the.colbert.report')
  11. test_setting = addon.getSetting('sort')
  12. if test_setting == '0':
  13. SORTORDER = 'date'
  14. elif test_setting == '1':
  15. SORTORDER = 'views'
  16. elif test_setting == '2':
  17. SORTORDER = 'rating'
  18.  
  19. ################################ Common
  20. def getURL( url ):
  21. try:
  22. print 'The Colbert Report --> getURL :: url = '+url
  23. txdata = None
  24. txheaders = {
  25. 'Referer': 'http://www.colbertnation.com/video/',
  26. 'X-Forwarded-For': '12.13.14.15',
  27. 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US;rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)',
  28. }
  29. req = urllib2.Request(url, txdata, txheaders)
  30. #req = urllib2.Request(url)
  31. #req.addheaders = [('Referer', 'http://www.colbertnation.com/video/'),
  32. # ('Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)')]
  33. response = urllib2.urlopen(req)
  34. link=response.read()
  35. response.close()
  36. except urllib2.URLError, e:
  37. error = 'Error code: '+ str(e.code)
  38. xbmcgui.Dialog().ok(error,error)
  39. print 'Error code: ', e.code
  40. return False
  41. else:
  42. return link
  43.  
  44. def addLink(name,url,iconimage='',plot=''):
  45. ok=True
  46. liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  47. liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot":plot, "TVShowTitle":TVShowTitle})
  48. liz.setProperty('fanart_image',fanart)
  49. ok=xbmcplugin.addDirectoryItem(handle=pluginhandle,url=url,listitem=liz)
  50. return ok
  51.  
  52. def addDir(name,url,mode,iconimage=shownail,plot=''):
  53. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
  54. ok=True
  55. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  56. liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot":plot, "TVShowTitle":TVShowTitle})
  57. liz.setProperty('fanart_image',fanart)
  58. ok=xbmcplugin.addDirectoryItem(handle=pluginhandle,url=u,listitem=liz,isFolder=True)
  59. return ok
  60.  
  61. def pageFragments(url):
  62. data = getURL(url)
  63. try:
  64. nextpage=re.compile('><span class="pageOff"><a href="(.+?)" class="nextprev" title="Go to Next Page">').findall(data)[0]
  65. nextpage = 'http://www.colbertnation.com'+nextpage
  66. addDir('Next Page',nextpage,7)
  67. except:
  68. print 'Last or Single page'
  69. try:
  70. prevpage=re.compile('\t<span class="pageOff"><a href="(.+?)" class="nextprev" title="Go to Previous Page">').findall(data)[0]
  71. prevpage = 'http://www.colbertnation.com'+prevpage
  72. addDir('Previous Page',prevpage,7)
  73. except:
  74. print 'No Previous page'
  75. LISTVIDEOS(url)
  76. xbmcplugin.endOfDirectory(pluginhandle,updateListing=True)
  77.  
  78. ################################ Root listing
  79. def ROOT():
  80. addDir('Full Episodes','full',5)
  81. addDir('Segments','segments',4)
  82. addDir('Guests','guests',3)
  83. xbmcplugin.endOfDirectory(pluginhandle)
  84.  
  85. def FULLEPISODES():
  86. xbmcplugin.setContent(pluginhandle, 'episodes')
  87. xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_NONE)
  88. full = 'http://www.colbertnation.com/full-episodes/'
  89. data = getURL(full)
  90. weeks = re.compile('<a id="(.+?)" class="seaso.+?" href="#">(.+?)</a>').findall(data)
  91. for url, week in weeks:
  92. data = getURL(url)
  93. episodes=re.compile('<span class="date"><a href="(.+?)">(.+?)</a></span>').findall(data)
  94. thumbnails=re.compile('<img width=".+?" height=".+?" src="(.+?)\?width=.+?".+?/>').findall(data)
  95. descriptions=re.compile('<span class="description">(.+?)</span>').findall(data)
  96. airdates=re.compile('<span class="date">Aired: (.+?)</span>').findall(data)
  97. epNumbers=re.compile('<span class="id">Episode (.+?)</span>').findall(data)
  98. listings = []
  99. for link, name in episodes:
  100. listing = []
  101. listing.append(name)
  102. listing.append(link)
  103. listings.append(listing)
  104. for thumbnail in thumbnails:
  105. marker = thumbnails.index(thumbnail)
  106. listings[marker].append(thumbnail+'?width=400')
  107. for description in descriptions:
  108. marker = descriptions.index(description)
  109. listings[marker].append(description)
  110. for airdate in airdates:
  111. marker = airdates.index(airdate)
  112. listings[marker].append(airdate)
  113. for epNumber in epNumbers:
  114. marker = epNumbers.index(epNumber)
  115. listings[marker].append(epNumber)
  116. print listings
  117. for name, link, thumbnail, plot, date, seasonepisode in listings:
  118. mode = 10
  119. season = int(seasonepisode[:-3])
  120. episode = int(seasonepisode[-3:])
  121. u=sys.argv[0]+"?url="+urllib.quote_plus(link)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
  122. u += "&season="+urllib.quote_plus(str(season))
  123. u += "&episode="+urllib.quote_plus(str(episode))
  124. u += "&premiered="+urllib.quote_plus(date)
  125. u += "&plot="+urllib.quote_plus(plot)
  126. u += "&thumbnail="+urllib.quote_plus(thumbnail)
  127. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=thumbnail)
  128. liz.setInfo( type="Video", infoLabels={ "Title": name,
  129. "Plot":plot,
  130. "Season":season,
  131. "Episode": episode,
  132. "premiered":date,
  133. "TVShowTitle":TVShowTitle})
  134. liz.setProperty('IsPlayable', 'true')
  135. liz.setProperty('fanart_image',fanart)
  136. xbmcplugin.addDirectoryItem(handle=pluginhandle,url=u,listitem=liz)
  137. xbmcplugin.endOfDirectory(pluginhandle)
  138.  
  139.  
  140. def GUESTS():
  141. segurl = 'http://www.colbertnation.com/video/tag/'
  142. segments=[('Author','Author'),
  143. ('Expert','Expert'),
  144. ('Journalist','Journalist'),
  145. ('Political Figure','Political+Figure'),
  146. ('Better Know a District','Better+Know+a+District')
  147. ]
  148. for name,link in segments:
  149. furl = segurl+link
  150. addDir(name,furl,7)
  151. xbmcplugin.endOfDirectory(pluginhandle)
  152.  
  153. def SEGMENTS():
  154. exclude = ('Author','Expert','Journalist','Political Figure')
  155. url = 'http://www.colbertnation.com/alltags'
  156. data = getURL(url)
  157. tags=re.compile('<div class="navTags"><a href="(.+?)">(.+?)</a><span class="derivitiveTagsNumber">(.+?)</span></div>').findall(data)
  158. for url, name,count in tags:
  159. if name in exclude:
  160. continue
  161. url = 'http://www.colbertnation.com'+url
  162. addDir(name+count,url,7)
  163. xbmcplugin.endOfDirectory(pluginhandle)
  164.  
  165.  
  166. ################################ List Videos
  167.  
  168. def LISTVIDEOS(url):
  169. xbmcplugin.setContent(pluginhandle, 'episodes')
  170. data = getURL(url)
  171. playbackUrls=re.compile('<div class="clipTitle"><a onclick="siteSearchReport\(\);" href="http://www.colbertnation.com/the-colbert-report-videos/(.+?)"').findall(data)
  172. #playbackUrls=re.compile('href="http://www.colbertnation.com/the-colbert-report-videos/(.+?)"').findall(data)
  173. thumbnails=re.compile('<img src="(.+?)?width=.+?" width=".+?" height="71"').findall(data)
  174. names=re.compile('<div class="clipTitle"><a onclick="siteSearchReport\(\);" href="http://www.colbertnation.com/the-colbert-report-videos/.+?">(.+?)</a></div>').findall(data)
  175. descriptions=re.compile('<div class="clipDescription">(.+?)\(.+?\)</div>').findall(data)
  176. durations=re.compile('<div class="clipDescription">.+?\((.+?)\)</div>').findall(data)
  177. epNumbers=re.compile('<span>Episode:</span> #(.+?)</div>').findall(data)
  178. airdates=re.compile('<div class="clipDate">Aired: (.+?)</div>').findall(data)
  179. for pb in playbackUrls:
  180. url = "http://www.colbertnation.com/the-colbert-report-videos/"+pb
  181. marker = playbackUrls.index(pb)
  182. thumbnail = thumbnails[marker]+'?width=400'
  183. fname = names[marker]
  184. description = descriptions[marker]
  185. duration = durations[marker]
  186. try:
  187. seasonepisode = epNumbers[marker]
  188. season = int(seasonepisode[:-3])
  189. episode = int(seasonepisode[-3:])
  190. except:
  191. season = 0
  192. episode = 0
  193. date = airdates[marker]
  194. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(11)+"&name="+urllib.quote_plus(fname)
  195. u += "&season="+urllib.quote_plus(str(season))
  196. u += "&episode="+urllib.quote_plus(str(episode))
  197. u += "&premiered="+urllib.quote_plus(date)
  198. u += "&plot="+urllib.quote_plus(description)
  199. u += "&thumbnail="+urllib.quote_plus(thumbnail)
  200. liz=xbmcgui.ListItem(fname, iconImage="DefaultVideo.png", thumbnailImage=thumbnail)
  201. liz.setInfo( type="Video", infoLabels={ "Title": fname,
  202. "Episode": episode,
  203. "Season": season,
  204. "Plot":description,
  205. "premiered":date,
  206. "Duration": duration,
  207. "TVShowTitle":TVShowTitle})
  208. liz.setProperty('IsPlayable', 'true')
  209. liz.setProperty('fanart_image',fanart)
  210. xbmcplugin.addDirectoryItem(handle=pluginhandle,url=u,listitem=liz)
  211.  
  212.  
  213. ################################ Play Video
  214.  
  215. def PLAYVIDEO(name,url):
  216. data = getURL(url)
  217. uri = re.compile('"http://media.mtvnservices.com/(.+?)"/>').findall(data)[0]
  218. rtmp = GRAB_RTMP(uri)
  219. item = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail, path=rtmp)
  220. item.setInfo( type="Video", infoLabels={ "Title": name,
  221. "Plot":plot,
  222. "premiered":premiered,
  223. "Season":int(season),
  224. "Episode":int(episode),
  225. "TVShowTitle":TVShowTitle})
  226. item.setProperty('fanart_image',fanart)
  227. xbmcplugin.setResolvedUrl(pluginhandle, True, item)
  228.  
  229.  
  230. ################################ Play Full Episode
  231.  
  232. def PLAYFULLEPISODE(name,url):
  233. data = getURL(url)
  234. uri=re.compile('<param name="movie" value="(.+?)"/>').findall(data)[0]
  235. uri = string.split(uri, "/")[3]
  236. #uri=re.compile('<param name="movie" value="http://media.mtvnservices.com/(.+?)"').findall(data)[0]
  237. url = 'http://shadow.comedycentral.com/feeds/video_player/mrss/?uri='+uri
  238. #url = 'http://media.mtvnservices.com/player/config.jhtml?uri='+uri+'&group=entertainment&type=network&site=colbertnation.com'
  239. data = getURL(url)
  240. uris=re.compile('<guid isPermaLink="false">(.+?)</guid>').findall(data)
  241. stacked_url = 'stack://'
  242. for uri in uris:
  243. rtmp = GRAB_RTMP(uri)
  244. stacked_url += rtmp.replace(',',',,')+' , '
  245. stacked_url = stacked_url[:-3]
  246. item = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail, path=stacked_url)
  247. item.setInfo( type="Video", infoLabels={ "Title": name,
  248. "Plot":plot,
  249. "premiered":premiered,
  250. "Season":int(season),
  251. "Episode":int(episode),
  252. "TVShowTitle":TVShowTitle})
  253. item.setProperty('fanart_image',fanart)
  254. print stacked_url
  255. xbmcplugin.setResolvedUrl(pluginhandle, True, item)
  256.  
  257. ################################ Grab rtmp
  258.  
  259. def GRAB_RTMP(uri):
  260. swfurl = 'http://media.mtvnservices.com/player/release/?v=4.5.3'
  261. url = 'http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?uri='+uri+'&showTicker=true'
  262. data = getURL(url)
  263. widths = re.compile('width="(.+?)"').findall(data)
  264. heights = re.compile('height="(.+?)"').findall(data)
  265. bitrates = re.compile('bitrate="(.+?)"').findall(data)
  266. rtmps = re.compile('<src>rtmp(.+?)</src>').findall(data)
  267. mpixels = 0
  268. mbitrate = 0
  269. furl=''
  270. rate_setting = addon.getSetting("bitrate")
  271. if rate_setting == '0':
  272. lbitrate = 0
  273. elif rate_setting == '1':
  274. lbitrate = 1720
  275. elif rate_setting == '2':
  276. lbitrate = 1300
  277. elif rate_setting == '3':
  278. lbitrate = 960
  279. elif rate_setting == '4':
  280. lbitrate = 640
  281. elif rate_setting == '5':
  282. lbitrate = 450
  283. for rtmp in rtmps:
  284. marker = rtmps.index(rtmp)
  285. w = int(widths[marker])
  286. h = int(heights[marker])
  287. bitrate = int(bitrates[marker])
  288. if bitrate == 0:
  289. continue
  290. elif bitrate > lbitrate and lbitrate <> 0:
  291. continue
  292. elif lbitrate <= bitrate or lbitrate == 0:
  293. pixels = w * h
  294. if pixels > mpixels or bitrate > mbitrate:
  295. mpixels = pixels
  296. mbitrate = bitrate
  297. #rtmpsplit = rtmp.split('/ondemand')
  298. #server = rtmpsplit[0]
  299. #path = rtmpsplit[1].replace('.flv','')
  300. #if '.mp4' in path:
  301. # path = 'mp4:' + path
  302. #port = ':1935'
  303. #app = '/ondemand?ovpfv=2.1.4'
  304. #furl = 'rtmp'+server+port+app+path+" playpath="+path+" swfurl="+swfurl+" swfvfy=true"
  305. furl = 'rtmp'+ rtmp + " swfurl=" + swfurl + " swfvfy=true"
  306. if furl <> '':
  307. return furl
  308. else:
  309. return False
  310.  
  311.  
  312. def get_params():
  313. param=[]
  314. paramstring=sys.argv[2]
  315. if len(paramstring)>=2:
  316. params=sys.argv[2]
  317. cleanedparams=params.replace('?','')
  318. if (params[len(params)-1]=='/'):
  319. params=params[0:len(params)-2]
  320. pairsofparams=cleanedparams.split('&')
  321. param={}
  322. for i in range(len(pairsofparams)):
  323. splitparams={}
  324. splitparams=pairsofparams[i].split('=')
  325. if (len(splitparams))==2:
  326. param[splitparams[0]]=splitparams[1]
  327.  
  328. return param
  329.  
  330.  
  331. params=get_params()
  332. url=None
  333. name=None
  334. mode=None
  335.  
  336. try:
  337. url=urllib.unquote_plus(params["url"])
  338. except:
  339. pass
  340. try:
  341. name=urllib.unquote_plus(params["name"])
  342. except:
  343. pass
  344. try:
  345. mode=int(params["mode"])
  346. except:
  347. pass
  348. try:
  349. thumbnail=urllib.unquote_plus(params["thumbnail"])
  350. except:
  351. thumbnail=''
  352. try:
  353. season=int(params["season"])
  354. except:
  355. season=0
  356. try:
  357. episode=int(params["episode"])
  358. except:
  359. episode=0
  360. try:
  361. premiered=urllib.unquote_plus(params["premiered"])
  362. except:
  363. premiered=''
  364. try:
  365. plot=urllib.unquote_plus(params["plot"])
  366. except:
  367. plot=''
  368.  
  369.  
  370. print "Mode: "+str(mode)
  371. print "URL: "+str(url)
  372. print "Name: "+str(name)
  373.  
  374.  
  375. if mode==None or url==None or len(url)<1:
  376. ROOT()
  377. elif mode==3:
  378. GUESTS()
  379. elif mode==4:
  380. SEGMENTS()
  381. elif mode==5:
  382. FULLEPISODES()
  383. elif mode==7:
  384. pageFragments(url)
  385. elif mode==9:
  386. LISTVIDEOS(url)
  387. xbmcplugin.endOfDirectory(pluginhandle)
  388. elif mode==10:
  389. PLAYFULLEPISODE(name,url)
  390. elif mode==11:
  391. PLAYVIDEO(name,url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement