Advertisement
alexdunlop81

usa.py

Apr 27th, 2013
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.28 KB | None | 0 0
  1. import xbmcplugin
  2. import xbmc
  3. import xbmcgui
  4. import urllib
  5. import urllib2
  6. import sys
  7. import os
  8. import re
  9.  
  10. import demjson
  11. from BeautifulSoup import BeautifulSoup
  12. from BeautifulSoup import BeautifulStoneSoup
  13. from pyamf.remoting.client import RemotingService
  14. import resources.lib._common as common
  15.  
  16. pluginhandle = int (sys.argv[1])
  17. BASE_URL = 'http://feed.theplatform.com/f/OyMl-B/PleQEkKucpUm/categories?form=json&fields=order,title,fullTitle,label,:smallBannerUrl,:largeBannerUrl&fileFields=duration,url,width,height&sort=order'
  18. BASE = 'http://www.usanetwork.com'
  19.  
  20. def masterlist():
  21.     return rootlist(db=True)
  22.  
  23. def rootlist(db=False):
  24.     xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  25.     data = common.getURL(BASE_URL)
  26.     shows = demjson.decode(data)['entries']
  27.     db_shows = []
  28.     for item in shows:
  29.         print item
  30.         url = item['plcategory$fullTitle']
  31.         name = item['title']
  32.         if db==True:
  33.             db_shows.append((name,'usa','showroot',url))
  34.         else:
  35.             common.addShow(name, 'usa', 'showroot', url)
  36.     if db==True:
  37.         return db_shows
  38.     else:
  39.         common.setView('tvshows')
  40.  
  41. def showroot():
  42.     common.addDirectory('Full Episodes', 'usa', 'episodes', common.args.url)
  43.     common.addDirectory('All Videos', 'usa', 'allvideos', common.args.url)
  44.     common.setView('seasons')
  45.  
  46. def allvideos():
  47.     process('http://feed.theplatform.com/f/OyMl-B/8IyhuVgUXDd_?')
  48.     common.setView('episodes')
  49.    
  50. def episodes():
  51.     process('http://feed.theplatform.com/f/AqNl-B/Y3vAV4MxgwlM?&byCustomValue={fullEpisode}{true}')
  52.     common.setView('episodes')
  53.  
  54. def process(urlBase, fullname = common.args.url):
  55.     #url = 'http://feed.theplatform.com/f/OyMl-B/Y3vAV4MxgwlM'
  56.     url = urlBase
  57.     url += '&form=json'
  58.     #url += '&fields=guid,title,description,categories,content,defaultThumbnailUrl'
  59.     url += '&fileFields=duration,url,width,height'
  60.     url += '&count=true'
  61.     url += '&byCategories='+urllib.quote_plus(fullname)
  62.     #url += '&byCustomValue={fullEpisode}{true}'
  63.     data = common.getURL(url)
  64.     episodes = demjson.decode(data)['entries']
  65.     for episode in episodes:
  66.         try:
  67.             name = episode['title'].split(':')[1].strip()
  68.             seasonEpisode =episode['title'].split(':')[0].strip()
  69.             season = int(seasonEpisode[:1])
  70.             episodeNum = int(seasonEpisode[1:])
  71.         except:
  72.             name = episode['title']
  73.             season=0
  74.             episodeNum=0
  75.         description = episode['description']
  76.         thumb= episode['plmedia$defaultThumbnailUrl']
  77.         duration=str(int(episode['media$content'][0]['plfile$duration']))
  78.         airDate = common.formatDate(epoch=episode['pubDate']/1000)
  79.         print "vid url",url
  80.         url=episode['media$content'][0]['plfile$url']
  81.         if season <> 0 and episodeNum <> 0:
  82.             displayname = '%sx%s - %s' % (str(season),str(episodeNum),name)
  83.         elif season <> 0:
  84.             displayname = '%S%s - %s' % (str(season),name)
  85.         else:
  86.             displayname = name
  87.         u = sys.argv[0]
  88.         u += '?url="'+urllib.quote_plus(url)+'"'
  89.         u += '&mode="usa"'
  90.         u += '&sitemode="play"'
  91.         infoLabels={ "Title":name,
  92.                      "Season":season,
  93.                      "Episode":episodeNum,
  94.                      "Plot":description,
  95.                      "premiered":airDate,
  96.                      "Duration":duration,
  97.                      "TVShowTitle":common.args.name
  98.                      }
  99.         common.addVideo(u,displayname,thumb,infoLabels=infoLabels)
  100.  
  101. #Get SMIL url and play video
  102. def play():
  103.     smilurl=common.args.url
  104.     swfUrl = 'http://www.usanetwork.com/videos/pdk/swf/flvPlayer.swf'
  105.     if (common.settings['enableproxy'] == 'true'):proxy = True
  106.     else:proxy = False
  107.     #slices 27.04.2013
  108.     smilurl += '&manifest=m3u'
  109.     data = common.getURL(smilurl,proxy=proxy)
  110.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  111.     print tree.prettify()
  112.     rtmpbase = tree.find('meta')
  113.     if rtmpbase:
  114.         rtmpbase = rtmpbase['base']
  115.         items=tree.find('switch').findAll('video')
  116.         hbitrate = -1
  117.         sbitrate = int(common.settings['quality']) * 1024
  118.         for item in items:
  119.             bitrate = int(item['system-bitrate'])
  120.             if bitrate > hbitrate and bitrate <= sbitrate:
  121.                 hbitrate = bitrate
  122.                 playpath = item['src']
  123.                 if '.mp4' in playpath:
  124.                     playpath = 'mp4:'+playpath
  125.                 else:
  126.                     playpath = playpath.replace('.flv','')
  127.                 finalurl = rtmpbase+' playpath='+playpath + " swfurl=" + swfUrl + " swfvfy=true"
  128.     else:
  129.         #items=tree.find('switch').findAll('video')
  130.         item=tree.find('seq').findAll('video')[0]
  131.         #hbitrate = -1
  132.         #sbitrate = int(common.settings['quality']) * 1024
  133.         finalurl = item['src'].split('b__=')[0]+'b__='+common.settings['quality']
  134.         #for item in items:
  135.             #bitrate = int(item['system-bitrate'])
  136.             #if bitrate > hbitrate and bitrate <= sbitrate:
  137.                 #hbitrate = bitrate
  138.             #    finalurl = item['src']
  139.     item = xbmcgui.ListItem(path=finalurl)
  140.     xbmcplugin.setResolvedUrl(pluginhandle, True, item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement