Advertisement
Guest User

spike.py proxy

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