alexdunlop81

nickteen

Jun 8th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.31 KB | None | 0 0
  1. import xbmc
  2. import xbmcgui
  3. import xbmcplugin
  4. import urllib
  5. import urllib2
  6. import httplib
  7. import sys
  8. import os
  9. import re
  10.  
  11. from BeautifulSoup import BeautifulStoneSoup
  12. from BeautifulSoup import BeautifulSoup
  13. import demjson
  14. import pyamf
  15.  
  16. from pyamf import remoting, amf3, util
  17.  
  18. import resources.lib._common as common
  19.  
  20. pluginhandle = int(sys.argv[1])
  21. BASE_URL = 'http://www.teennick.com/ajax/videos/all-videos?sort=date+desc&start=0&page=1&type=fullEpisodeItem&updateDropdown=true&viewType=collectionAll'
  22. BASE = 'http://www.teennick.com'
  23.  
  24. def masterlist():
  25.     return rootlist(db=True)
  26.  
  27. def rootlist(db=False):
  28.     data = common.getURL(BASE_URL)
  29.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  30.     db_shows = []
  31.     shows=tree.find('select',attrs={'id':'dropdown-by-show'}).findAll('option')
  32.     for show in shows:
  33.         name = show.string
  34.         if name <> 'All Shows':
  35.             url = show['value']      
  36.             if db==True:
  37.                 db_shows.append((name, 'nickteen', 'episodes', url))
  38.             else:
  39.                 common.addShow(name, 'nickteen', 'episodes', url)
  40.     if db==True:
  41.         return db_shows
  42.     else:
  43.         common.setView('tvshows')
  44.  
  45. def episodes():
  46.     url = 'http://www.teennick.com/ajax/videos/all-videos/'+common.args.url
  47.     url += '?sort=date+desc&start=0&page=1&viewType=collectionAll&type=fullEpisodeItem'
  48.     data = common.getURL(url)
  49.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  50.     episodes=tree.find('ul',attrs={'class':'large-grid-list clearfix'}).findAll('li',recursive=False)
  51.     for episode in episodes:
  52.         h4link=episode.find('h4').find('a')
  53.         name = h4link.string
  54.         url = BASE + h4link['href']
  55.         thumb = episode.find('img')['src'].split('?')[0]
  56.         plot = episode.find('p',attrs={'class':'description text-small color-light'}).string
  57.         u = sys.argv[0]
  58.         u += '?url="'+urllib.quote_plus(url)+'"'
  59.         u += '&mode="nickteen"'
  60.         u += '&sitemode="playvideo"'
  61.         infoLabels={ "Title":name,
  62.                      #"Duration":duration,
  63.                      #"Season":0,
  64.                      #"Episode":0,
  65.                      "Plot":str(plot),
  66.                      "TVShowTitle":common.args.name
  67.                      }
  68.         common.addVideo(u,name,thumb,infoLabels=infoLabels)
  69.     common.setView('episodes')
  70.  
  71. def playuri(uri = common.args.url,referer='http://www.teennick.com'):
  72.     mtvn = 'http://media.nick.com/'+uri
  73.     swfUrl = common.getRedirect(mtvn,referer=referer,forwardHeader=True)
  74.     configurl = urllib.unquote_plus(swfUrl.split('CONFIG_URL=')[1].split('&')[0]).strip()
  75.     configxml = common.getURL(configurl,referer=mtvn,forwardHeader=True)
  76.     tree=BeautifulStoneSoup(configxml, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  77.     mrssurl = tree.find('feed').string.replace('{uri}',uri).replace('&amp;','&').replace('{type}','network').replace('mode=episode','mode=clip')
  78.     mrssxml = common.getURL(mrssurl,forwardHeader=True)
  79.     tree=BeautifulStoneSoup(mrssxml, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  80.     segmenturls = tree.findAll('media:content')
  81.     stacked_url = 'stack://'
  82.     for segment in segmenturls:
  83.         surl = segment['url']
  84.         videos = common.getURL(surl,forwardHeader=True)
  85.         videos = BeautifulStoneSoup(videos, convertEntities=BeautifulStoneSoup.HTML_ENTITIES).findAll('rendition')
  86.         hbitrate = -1
  87.         sbitrate = int(common.settings['quality'])
  88.         for video in videos:
  89.             bitrate = int(video['bitrate'])
  90.             if bitrate > hbitrate and bitrate <= sbitrate:
  91.                 hbitrate = bitrate
  92.                 rtmpdata = video.find('src').string
  93.                 rtmpurl = rtmpdata + " swfurl=" + swfUrl.split('?')[0] +" pageUrl=" + referer + " swfvfy=true"
  94.         stacked_url += rtmpurl.replace(',',',,')+' , '
  95.     stacked_url = stacked_url[:-3]
  96.     item = xbmcgui.ListItem(path=stacked_url)
  97.     xbmcplugin.setResolvedUrl(pluginhandle, True, item)
  98.  
  99. def playvideo(url = common.args.url):
  100.     data=common.getURL(url,forwardHeader=True)
  101.     try:
  102.         uri = re.compile('<meta content="http://media.nick.com/(.+?)" itemprop="embedURL"/>').findall(data)[0]
  103.     except:
  104.         uri=re.compile("NICK.unlock.uri = '(.+?)';").findall(data)[0]
  105.     playuri(uri,referer=url)
Advertisement
Add Comment
Please, Sign In to add comment