alexdunlop81

aetv.py sig fix

Jun 22nd, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.36 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import xbmcplugin
  4. import xbmc
  5. import xbmcgui
  6. import urllib
  7. import urllib2
  8. import sys
  9. import os
  10. import re
  11. import httplib
  12. import base64
  13. import random
  14. import binascii
  15. import time
  16. import hmac
  17. try:
  18.     import hashlib.sha1 as sha1
  19. except:
  20.     import sha as sha1
  21.  
  22.  
  23. from BeautifulSoup import BeautifulSoup
  24. from BeautifulSoup import BeautifulStoneSoup
  25. import resources.lib._common as common
  26. from pyamf import remoting
  27.  
  28. pluginhandle = int(sys.argv[1])
  29.  
  30. BASEURL = 'http://www.aetv.com/videos/display.jsp'
  31. SHOWSURL = 'http://www.aetv.com/allshows.jsp'
  32. BASE = 'http://www.aetv.com'
  33.  
  34. def masterlist():
  35.     return showlist(db=True)
  36.  
  37. def rootlist(db=False):
  38.     common.addDirectory('Shows'    , 'aetv', 'showlist', '')
  39.     common.addDirectory('Lifestyle', 'aetv', 'lifesytlelist', 'season_url')
  40.     common.addDirectory('Classic'  , 'aetv', 'classiclist', 'season_url')
  41.  
  42. def lifesytlelist():
  43.     droplist('/lifestyle/')
  44.  
  45. def classiclist():
  46.     droplist('/classic/')
  47.    
  48. def droplist(homedir):
  49.     url  = 'http://www.aetv.com/minisite/videoajx.jsp'
  50.     url += '?homedir='+homedir
  51.     url += '&pfilter=ALL%20VIDEOS'
  52.     url += '&sfilter=All%20Categories'
  53.     url += '&seriesfilter=ALL%20SERIES'
  54.     data = common.getURL(url)
  55.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  56.     shows = tree.find('div',attrs={'id':'series_filter'}).findAll('li',attrs={'class':None})
  57.     for show in shows:
  58.         name = show.find('a').string
  59.         url  = 'http://www.aetv.com/minisite/videoajx.jsp'
  60.         url += '?homedir='+homedir
  61.         url += '&seriesfilter='+name.replace(' ','%20')
  62.         common.addShow(name, 'aetv', 'show_primary_filter', url)
  63.  
  64. def show_primary_filter(url=common.args.url):
  65.     data = common.getURL(url)
  66.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  67.     primary_filter = tree.find('div',attrs={'id':'primary_filter'})
  68.     if primary_filter:
  69.         filters = primary_filter.findAll('li',attrs={'class':None})
  70.         if len(filters) > 1:
  71.             for filter in filters:
  72.                 link = filter.find('a')
  73.                 item_url = url + '&pfilter='+link.string.strip().replace(' ','%20')
  74.                 common.addDirectory(link.string.title(), 'aetv', 'show_secondary_filter', item_url)
  75.         else:
  76.             showsubThePlatform(url.replace(' ','%20'),tree=tree)
  77.     else:
  78.         showsubThePlatform(url.replace(' ','%20'),tree=tree)
  79.     xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  80.     common.setView('seasons')
  81.  
  82. def show_secondary_filter(url=common.args.url):
  83.     data = common.getURL(url)
  84.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  85.     second_filter = tree.find('div',attrs={'id':'secondary_filter'})
  86.     if second_filter:
  87.         filters = second_filter.findAll('li')
  88.         if len(filters) > 1:
  89.             for filter in filters:
  90.                 link = filter.find('a')
  91.                 if link.string == 'All Categories':
  92.                     item_url = url
  93.                 else:
  94.                     item_url = url + '&sfilter='+link.string.strip().replace(' ','%20')
  95.                 common.addDirectory(link.string.title(), 'aetv', 'showsubThePlatform', item_url)
  96.         else:
  97.             showsubThePlatform(url.replace(' ','%20'),tree=tree)
  98.     else:
  99.         showsubThePlatform(url.replace(' ','%20'),tree=tree)
  100.     xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  101.     common.setView('seasons')
  102.    
  103. def showlist(db=False):
  104.     data = common.getURL(BASEURL)
  105.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  106.     menu=tree.find(attrs={'id':'av-list1','class':'all-videos_unordered'}).findAll('a')
  107.     db_shows = []
  108.     blackListShows = ["Kirstie Alley's Big Life","The Sopranos®","Coma"]
  109.     for item in menu:
  110.         name = item.string.encode('utf-8')
  111.         url = item['href']
  112.         if 'http://' not in item['href']:
  113.             url = BASE + url
  114.         if name in blackListShows:
  115.             continue
  116.  
  117.         if db==True:
  118.             db_shows.append((name, 'aetv', 'show_cats', url))
  119.         else:
  120.             common.addShow(name, 'aetv', 'show_cats', url)
  121.     if db==True:
  122.         return db_shows
  123.     else:
  124.         common.setView('tvshows')
  125.  
  126. def show_cats(url=common.args.url):
  127.     #print "showcats",url,len(url.split('/'))
  128.     #make sure we are on video page not main site
  129.     if len(url.split('/'))<6:
  130.         url=url+'/video'
  131.     data = common.getURL(url.replace(' ','%20'))
  132.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  133.     homedir = tree.find('div',attrs={'id':'video_home_dir','style':'display : none'}).string
  134.     series_base  = 'http://www.aetv.com/minisite/videoajx.jsp'
  135.     series_base += '?homedir='+homedir
  136.     #full_series_url = series_url+'&pfilter=FULL%20EPISODES'
  137.     #clips_series_url = series_url+'&pfilter=CLIPS'
  138.     if homedir == '/lifestyle/' or homedir == '/classic/':
  139.         series = url.split('=')[-1].replace(' ','%20')
  140.         series_url = series_base + '&seriesfilter='+series
  141.     else:
  142.         series_url = series_base
  143.     data = common.getURL(series_url)
  144.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  145.     seasons = tree.find('div',attrs={'id':'primary_filter'}).findAll('li',attrs={'class':None})
  146.     if len(seasons) > 0:
  147.         for season in seasons:
  148.             link = season.find('a')
  149.             if '?' in series_base:
  150.                 season_url = series_base + '&pfilter='+link.string.strip().replace(' ','%20')
  151.             else:
  152.                 season_url = series_base + '?pfilter='+link.string.strip().replace(' ','%20')
  153.             if homedir == '/lifestyle/' or homedir == '/classic/':
  154.                 series = url.split('=')[-1].replace(' ','%20')
  155.                 season_url += '&seriesfilter='+series
  156.             common.addDirectory(link.string.title(), 'aetv', 'showseasonThePlatform', season_url)
  157.         xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  158.         common.setView('seasons')
  159.     else:
  160.         showseasonThePlatform(url.replace(' ','%20'),tree=tree)
  161.     common.setView('seasons')
  162.  
  163. def showseasonThePlatform(url=common.args.url,tree=False):
  164.     if not tree:
  165.         data = common.getURL(url)
  166.         tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  167.     seasons = tree.find('div',attrs={'id':'secondary_filter'}).findAll('li')
  168.     if len(seasons) > 1:
  169.         for season in seasons:
  170.             link = season.find('a')
  171.             if link.string == 'All Categories':
  172.                 season_url = url
  173.             else:
  174.                 season_url = url+'&sfilter='+link.string.strip().replace(' ','%20')
  175.             common.addDirectory(link.string, 'aetv', 'showsubThePlatform', season_url)
  176.         xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL)
  177.         common.setView('seasons')
  178.     else:
  179.         showsubThePlatform(url.replace(' ','%20'),tree=tree)
  180.    
  181.  
  182. def showsubThePlatform(url=common.args.url,tree=False):
  183.     if not tree:
  184.         data = common.getURL(url)
  185.         tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  186.     videos=tree.findAll('li',attrs={'class':'selected'})
  187.     try:season = int(tree.findAll('li',attrs={'class':'selected'})[1].find('a').string.replace('Season ',''))
  188.     except:season = 0
  189.     videos=tree.findAll('div',attrs={'class':'video_playlist-item'})
  190.     for video in videos:
  191.         print video
  192.         infoLabels={'Season':season}
  193.         video_details = video.find('div',attrs={'class':'video_details'})
  194.         infoLabels['Title'] = video_details.find('p',attrs={'class':'video_details-title'}).string.encode('utf-8').replace(' / ','/') #clean title
  195.         thumb = video.find('img')['realsrc']
  196.         if 'http://' not in thumb:
  197.             thumb = BASE + thumb
  198.         url = 'http'+video.find('a')['onclick'].split("'http")[1].split("'")[0]
  199.         infoLabels['Plot'] = video_details.find('p',attrs={'class':'video_details-synopsis'}).string.encode('utf-8')
  200.         displayname=infoLabels['Title']
  201.         print displayname
  202.         for p in video_details.findAll('p',attrs={'class':None}):
  203.             if p.find('span'):
  204.                 infoLabels['Duration'] = p.find('span').string
  205.             else:
  206.                 if 'Premiere Date: ' in p.string:
  207.                     infoLabels['premiered'] = p.string.replace('Premiere Date: ','')
  208.                 elif 'Episode: ' in p.string:
  209.                     try:
  210.                         infoLabels['Episode'] = int(p.string.replace('Episode: ',''))
  211.                         if common.settings['enablestrictnames'] == 'false':
  212.                             if infoLabels['Season'] <> 0:
  213.                                 displayname = '%sx%s - %s' % (str(infoLabels['Season']),str(infoLabels['Episode']),infoLabels['Title'])
  214.                             else:
  215.                                 displayname = str(infoLabels['Episode'])+' - '+infoLabels['Title']
  216.                     except:
  217.                         infoLabels['Episode'] = 0
  218.                         displayname = infoLabels['Title']
  219.         u = sys.argv[0]
  220.         u += '?url="'+urllib.quote_plus(url)+'"'
  221.         u += '&mode="aetv"'
  222.         u += '&sitemode="playThePlatform"'
  223.         common.addVideo(u,displayname,thumb,infoLabels=infoLabels)
  224.     common.setView('episodes')
  225.  
  226. def playThePlatform():
  227.     if (common.settings['enableproxy'] == 'true'):proxy = True
  228.     else:proxy = False
  229.     data = common.getURL(common.args.url)
  230.     #print "data",data #slices debug
  231.     #mrss = urllib.unquote_plus(base64.b64decode(re.compile('{ mrss: "(.+?)",').findall(data)[0]))
  232.     smil_url=re.compile('releaseURL: +"(.*?)"').findall(data)[0]
  233.     #print releaseUrl
  234.     #try:mrss = urllib.unquote_plus(base64.b64decode(re.compile('{ mrss: "(.+?)",').findall(data)[0]))
  235.     #except:mrss = urllib.unquote_plus(base64.b64decode(re.compile('"mrss=(.+?)&').findall(data)[0]))
  236.     #tree=BeautifulStoneSoup(mrss, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  237.     #for item in tree.findAll('item'):
  238.        # link = item.find('link').string
  239.      #   if link == common.args.url:
  240.       #      smil_url = item.find('media:text',text=re.compile('smilUrl=')).string.split('smilUrl=')[1]
  241.     #smil_url = re.compile('<media:text>smilUrl=(.+?)</media:text>').findall(mrss)[0]
  242.     #signUrl  = 'http://www.history.com/components/get-signed-signature'
  243.     #signUrl += '?url='+smil_url.split('/s/')[1].split('?')[0]
  244.     #signUrl += '&cache='+str(random.randint(100, 999))
  245.     #sig = str(common.getURL(signUrl))
  246.     sig = sign_url(smil_url) #switch to hls
  247.     smil_url += '&sig='+sig
  248.     data = common.getURL(smil_url.replace('switch=hds&',''),proxy=proxy)
  249.     print data
  250.     tree=BeautifulStoneSoup(data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  251.     #rtmp_base = tree.find('meta')['base']
  252.     filenames = tree.findAll('video')
  253.     hbitrate = -1
  254.     sbitrate = int(common.settings['quality'])
  255.     for filename in filenames:
  256.         bitrate = int(filename['system-bitrate'])/1024
  257.         if bitrate > hbitrate and bitrate <= sbitrate:
  258.             hbitrate = bitrate
  259.             playpath = filename['src']
  260.     swfUrl = 'http://www.aetv.com/js/minisite4g/VideoPlayer.swf'
  261.     #rtmpurl = rtmp_base+' playpath='+playpath + " swfurl=" + swfUrl + " swfvfy=true"
  262.     item = xbmcgui.ListItem(path=playpath)
  263.     xbmcplugin.setResolvedUrl(pluginhandle, True, item)
  264.  
  265. def sign_url_old(url):
  266.     hmac_key = 'crazyjava'
  267.     SEC_HEX = '733363723374' #'s3cr3t'
  268.     expiration = get_expiration()
  269.     path = url.split('http://link.theplatform.com/s/')[1].split('?')[0]
  270.     sign_data = binascii.unhexlify('00'+expiration+binascii.hexlify(path).lower())
  271.     sig = hmac.new(hmac_key, sign_data, sha1)
  272.     sigHEX = sig.hexdigest()
  273.     signature = '00' + expiration + sigHEX + SEC_HEX
  274.     #finalUrl = url+'?sig='+signature+'&format=SMIL&Tracking=true&Embedded=true&mbr=true'
  275.     return signature
  276.  
  277. def sign_url(url):
  278.     print "new sig"
  279.     #slices - changed ro use url
  280.     #http://www.tbs.com/processors/cvp/token.jsp
  281.     sig=common.getURL('http://www.history.com/components/get-signed-signature?url='+re.compile('/[sz]/(.+)\?').findall(url)[0])
  282.     #hmac_key = 'crazyjava'
  283.     #http://link.theplatform.com/s/xc6n8B/Uk9Iewei0eId/tracker.log?type=qos&ver=2&d=1367950641769&rid0=28489795528&t0=Ancient%20Aliens%3A%20The%20Time%20Travelers&tc0=1&lp0=0&lt0=3&pb0=100&pp0=0&pr0=0&nocache=1367950646788
  284.     #http://link.theplatform.com/s/xc6n8B/Uk9Iewei0eId?mbr=true&sig=005189478ac93e8e252247688d9fe43e80a0ceabf57e46df32733363723374&metafile=true&assetTypes=medium%5Fvideo%5Fs3&switch=rtmp&format=SMIL&Tracking=true&Embedded=true
  285.     #SEC_HEX = '733363723374' #'s3cr3t'
  286.     #expiration = get_expiration()
  287.     #print expiration
  288.     #path = url.split('http://link.theplatform.com/s/')[1]
  289.     #sign_data = binascii.unhexlify('00'+expiration+binascii.hexlify(path).lower())
  290.     #print "Sign data",sign_data
  291.     #sig = hmac.new(hmac_key, sign_data, sha1)
  292.     #sigHEX = sig.hexdigest()
  293.     #signature = '00' + expiration + sigHEX + SEC_HEX
  294.     #finalUrl = url+'&sig='+sig+'&format=SMIL&Tracking=true&Embedded=true&mbr=true&auth=daEbfbTdjaccacMd9aHd_ccdLbad6cjdSdg-brIOlw-cOW-ooHzv'
  295.     #print "fu",finalUrl
  296.     return sig
  297.  
  298. def get_expiration(auth_length = 600):
  299.     current_time = time.mktime(time.gmtime())+auth_length
  300.     expiration = ('%0.2X' % current_time).lower()
  301.     return expiration
Advertisement
Add Comment
Please, Sign In to add comment