Advertisement
alexdunlop81

spike.py merge

May 21st, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.40 KB | None | 0 0
  1. import xbmc, xbmcgui, xbmcplugin, urllib2, urllib, re, sys, os, time
  2. from BeautifulSoup import BeautifulSoup
  3. from BeautifulSoup import BeautifulStoneSoup
  4. import resources.lib._common as common
  5.  
  6. BASE = 'http://www.spike.com'
  7. pluginhandle = int(sys.argv[1])
  8.  
  9. def masterlist():
  10.     return rootlist(db=True)
  11.        
  12. def rootlist(db=False):
  13.     url = BASE + '/shows/'
  14.     data = common.getURL(url)
  15.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  16.     categories=tree.findAll(attrs={'class' : 'module  primetime_and_originals'})
  17.     db_shows = []
  18.     for category in categories:
  19.         shows = category.findAll('li')
  20.         for show in shows:
  21.             link = show.find('a')
  22.             url = BASE+link['href']
  23.             print "URL",url
  24.             name = link.string
  25.             if name == 'The Ultimate Fighter':
  26.                 continue
  27.             if db==True:
  28.                 db_shows.append((name,'spike','episodes',url))
  29.             else:
  30.                 common.addShow(name, 'spike', 'episodes', url)
  31.     if db==True:
  32.         return db_shows
  33.     else:
  34.         common.setView('tvshows')
  35.  
  36. def episodes(url=common.args.url):
  37.     xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  38.     data = common.getURL(url)
  39.     #print "D",data
  40.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  41.     seeall=tree.find('a', attrs={'class' : 'see_all'})
  42.     print "eall",seeall
  43.     menu=tree.find('div', attrs={'class' : 'menu'})
  44.     print "menu",menu
  45.     categories=menu.findAll('a', attrs={'href' : re.compile("http://.*")})
  46.     #categories=tree.findAll('a',attrs={'class' : 'read_full'})
  47.     categories.append(seeall)
  48.     try:
  49.         for category in categories:
  50.             print "categories",categories
  51.             print "cat",category
  52.             if category is not None and category.string is not None:
  53.                 url = category['href']
  54.                 print "catu",url
  55.                 print "cn",category.string,category
  56.                 name = category.string.replace('See all ','')
  57.                 print 'name',name
  58.                 if name == 'Video Clips':
  59.                     print "ADDD",name, 'spike', 'videos', url
  60.                     common.addDirectory(name, 'spike', 'videos', url)
  61.                 elif name == 'Full Episodes':
  62.                     common.addDirectory(name, 'spike', 'fullepisodes', url)
  63.                 elif name == 'Episode Guide':
  64.                     common.addDirectory(name, 'spike', 'fullepisodes', url)
  65.         common.setView('seasons')
  66.     except:
  67.         video=tree.find(attrs={'class' : 'see_all_videos clearfix'}).find('a')
  68.         url = video['href']
  69.         name = video.contents[1].contents[0].replace('See All ','')
  70.         common.addDirectory(name, 'spike', 'videos', url)
  71.         common.setView('seasons')
  72.  
  73.  
  74. def videos(url=common.args.url):
  75.     data = common.getURL(url)
  76.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  77.     episodes=tree.find(attrs={'id' : 'show_clips_res'}).findAll(attrs={'class' : 'block'})
  78.     for episode in episodes:
  79.         description = episode.find('p').renderContents()#.encode('utf-8')
  80.         thumb = episode.find('img')['src'].split('?')[0]
  81.         name = episode.find('h3').find('a').string.encode('utf-8')
  82.         url = episode.find('h3').find('a')['href']
  83.         print name, url, thumb, description
  84.         u = sys.argv[0]
  85.         u += '?url="'+urllib.quote_plus(url)+'"'
  86.         u += '&mode="spike"'
  87.         u += '&sitemode="playvideo"'
  88.         infoLabels={ "Title":name,
  89.                      #"Season":season,
  90.                      #"Episode":episode,
  91.                      "Plot":description
  92.                      #"premiered":airDate,
  93.                      #"Duration":duration,
  94.                      #"TVShowTitle":common.args.name
  95.                      }
  96.         common.addVideo(u,name,thumb,infoLabels=infoLabels)
  97.     common.setView('episodes')
  98.  
  99.  
  100. def fullepisodes(url=common.args.url):
  101.     data = common.getURL(url)
  102.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  103.     seasons=tree.find('ul',attrs={'class' : 'season_navigation'}).findAll('a')
  104.     for season in seasons:
  105.         data = common.getURL(season['href'])
  106.         tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  107.         episodes=tree.find(attrs={'class' : 'clips'}).findAll('div',recursive=False)
  108.         for episode in episodes:
  109.             try: uri = episode.find('a')['href']
  110.             except: continue
  111.             name = episode.find('img')['title']
  112.             thumb = episode.find('img')['src'].split('?')[0]
  113.             description = episode.findAll('p')[0].contents[0].strip().encode('utf-8')
  114.             print "PP12",episode.findAll('p')[1].contents[1]
  115.             #slces 26.04.2013 changed index
  116.             airDate = episode.findAll('p')[1].contents[1].strip().encode('utf-8')
  117.             try:
  118.                 seasonepisode = episode.find(attrs={'class' : 'title'}).contents[2].replace('- Episode ','').strip()
  119.                 if 3 == len(seasonepisode):
  120.                     season = int(seasonepisode[:1])
  121.                     episode = int(seasonepisode[-2:])
  122.                 elif 4 == len(seasonepisode):
  123.                     season = int(seasonepisode[:2])
  124.                     episode = int(seasonepisode[-2:])
  125.             except:
  126.                 season=0
  127.                 episode=0
  128.             if season <> 0 or episode <> 0:
  129.                 displayname = '%sx%s - %s' % (str(season),str(episode),name)
  130.             else:
  131.                 displayname = name
  132.             #except:
  133.             #    print 'no season data'
  134.             #    displayname = name
  135.             #    season = 0
  136.             #    episode = 0
  137.             u = sys.argv[0]
  138.             u += '?url="'+urllib.quote_plus(uri)+'"'
  139.             u += '&mode="spike"'
  140.             u += '&sitemode="playepisode"'
  141.             infoLabels={ "Title":name,
  142.                          "Season":season,
  143.                          "Episode":episode,
  144.                          "Plot":description,
  145.                          "premiered":airDate
  146.                          #"Duration":duration,
  147.                          #"TVShowTitle":common.args.name
  148.                          }
  149.             common.addVideo(u,displayname,thumb,infoLabels=infoLabels)
  150.     common.setView('episodes')
  151.    
  152. def playepisode(url = common.args.url):
  153.     #data = common.getURL(url)
  154.     if (common.settings['enableproxy'] == 'true'):proxy = True
  155.     else:proxy = False
  156.     data = common.getURL(url,proxy=proxy)
  157.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  158.     #print tree.prettify()
  159.     uri = tree.find('div',attrs={'id':'video_player_box'})['data-mgid']
  160.     #uri = tree.find('object',attrs={'id':'video_player'})['resource'].split('/')[-1]
  161.     play(uri)
  162.  
  163. def play(uri = common.args.url,referer='http://www.tvland.com'):
  164.     mp4_url = "http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=/44620/mtvnorigin"
  165.     mtvn = 'http://media.mtvnservices.com/'+uri
  166.     swfUrl = common.getRedirect(mtvn,referer=referer)
  167.     configurl = urllib.unquote_plus(swfUrl.split('CONFIG_URL=')[1].split('&')[0])
  168.     configxml = common.getURL(configurl)
  169.     tree=BeautifulStoneSoup(configxml, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  170.     #print tree.prettify()
  171.     mrssurl = tree.find('feed').string.replace('{uri}',uri).replace('&amp;','&').replace('{ref}','www.spike.com')
  172.     mrssxml = common.getURL(mrssurl)
  173.     tree=BeautifulStoneSoup(mrssxml, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  174.     segmenturls = tree.findAll('media:content')
  175.     stacked_url = 'stack://'
  176.     for segment in segmenturls:
  177.         surl = segment['url']
  178.         videos = common.getURL(surl)
  179.         #print videos
  180.         videos = BeautifulStoneSoup(videos, convertEntities=BeautifulStoneSoup.HTML_ENTITIES).findAll('rendition')
  181.         hbitrate = -1
  182.         sbitrate = int(common.settings['quality'])
  183.         for video in videos:
  184.             bitrate = int(video['bitrate'])
  185.             if bitrate > hbitrate and bitrate <= sbitrate:
  186.                 hbitrate = bitrate
  187.                 rtmpdata = video.find('src').string
  188.                 rtmpdata = video.find('src').string
  189.                 rtmpurl = mp4_url+rtmpdata.split('mtvnorigin')[1]
  190.                 #app = rtmpdata.split('://')[1].split('/')[1]
  191.                 #rtmpdata = rtmpdata.split(app)
  192.                 #rtmp = rtmpdata[0]
  193.                 #playpath = rtmpdata[1]
  194.                 #if '.mp4' in playpath:
  195.                 #    playpath = 'mp4:'+playpath.replace('.mp4','')
  196.                 #else:
  197.                 #    playpath = playpath.replace('.flv','')
  198.                 #swfUrl = "http://media.mtvnservices.com/player/prime/mediaplayerprime.1.12.1.swf"
  199.                 #rtmpurl = rtmp+app+playpath +" playpath=" + playpath + " swfurl=" + swfUrl + " pageUrl=" + referer + " swfvfy=true"
  200.                 #print rtmpurl
  201.         stacked_url += rtmpurl.replace(',',',,')+' , '
  202.     stacked_url = stacked_url[:-3]
  203.     item = xbmcgui.ListItem(path=stacked_url)
  204.     xbmcplugin.setResolvedUrl(pluginhandle, True, item)
  205.  
  206. def playvideo(url = common.args.url):
  207.     data=common.getURL(url)
  208.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  209.     #uri = tree.find('meta',attrs={'property':'og:video'})['content'].split('://')[1].split('/')[1]
  210.     uri = tree.find('div',attrs={'id':'video_player_box'})['data-mgid']
  211.     play(uri,referer=url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement