Guest User

xbmc free cable spike

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