alexdunlop81

crackle dropping xios fix

May 19th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.96 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. from BeautifulSoup import BeautifulSoup
  11. from BeautifulSoup import BeautifulStoneSoup
  12. import demjson
  13. import resources.lib._common as common
  14.  
  15. pluginhandle = int (sys.argv[1])
  16.  
  17. def masterlist():
  18.     showlist=shows(db=True)
  19.     return showlist
  20.  
  21. def rootlist():
  22.     common.addDirectory('Movies', 'crackle', 'movieGenres', '')
  23.     common.addDirectory('Television', 'crackle', 'showGenres', '')
  24.     common.addDirectory('Originals', 'crackle', 'originals', '')
  25.     #common.addDirectory('Collections', 'crackle', 'collections', '')
  26.     common.setView('seasons')
  27.  
  28. def build_api_url(list_type,content_type,video_type='all',genres='all',sort='alpha',region='US',format='json',limit=50,ID='',ios=False):
  29.     #LIST TYPES:    browse, popular, recent, details, channel
  30.     #CONTENT TYPES: movies, shows, originals, collections
  31.     #VIDOE TYPES:   all, full, clips, trailers
  32.     #GENRES:        Action_Comedy_Crime_Horror_Sci-Fi_Thriller
  33.     if ios:
  34.         base = 'http://ios-api.crackle.com/Service.svc/'
  35.     else:
  36.         base = 'http://api.crackle.com/Service.svc/'
  37.     if list_type == 'browse':
  38.         api_url = base+list_type+'/'+content_type+'/'+video_type+'/'+genres+'/'+sort+'/'+region+'?format='+format
  39.     elif list_type == 'popular' or list_type == 'recent':
  40.         api_url = base+list_type+'/'+content_type+'/'+video_type+'/'+genres+'/all/'+region+'/'+str(limit)+'?format='+format
  41.     elif list_type == 'channel':
  42.         api_url = base+list_type+'/'+str(ID)+'/folders/'+region+'?format='+format
  43.     elif list_type == 'details':
  44.         #channel or media type
  45.         api_url = base+list_type+'/media/'+str(ID)+'/'+region+'?format='+format
  46.     return api_url
  47.  
  48. def showGenres(genre=common.args.url):
  49.     #GENRES:        Action_Comedy_Crime_Horror_Sci-Fi_Thriller
  50.     common.addDirectory('All Shows', 'crackle', 'showsByGenre', 'all')
  51.     common.addDirectory('Action', 'crackle', 'showsByGenre', 'Action')
  52.     common.addDirectory('Comedy', 'crackle', 'showsByGenre', 'Comedy')
  53.     common.addDirectory('Crime', 'crackle', 'showsByGenre', 'Crime')
  54.     common.addDirectory('Horror', 'crackle', 'showsByGenre', 'Horror')
  55.     common.addDirectory('Sci-Fi', 'crackle', 'showsByGenre', 'Sci-Fi')
  56.     common.addDirectory('Thriller', 'crackle', 'showsByGenre', 'Thriller')
  57.     common.setView('seasons')
  58.  
  59. def showsByGenre(genre=common.args.url):
  60.     shows(genre)
  61.  
  62. def shows(genre,db=False):
  63.     url = build_api_url('browse','shows','all',genre)
  64.     return listCatType(url,db)
  65.  
  66. def movieGenres(genre=common.args.url):
  67.     #GENRES:        Action_Comedy_Crime_Horror_Sci-Fi_Thriller
  68.     common.addDirectory('All Movies', 'crackle', 'moviesByGenre', 'all')
  69.     common.addDirectory('Action', 'crackle', 'moviesByGenre', 'Action')
  70.     common.addDirectory('Comedy', 'crackle', 'moviesByGenre', 'Comedy')
  71.     common.addDirectory('Crime', 'crackle', 'moviesByGenre', 'Crime')
  72.     common.addDirectory('Horror', 'crackle', 'moviesByGenre', 'Horror')
  73.     common.addDirectory('Sci-Fi', 'crackle', 'moviesByGenre', 'Sci-Fi')
  74.     common.addDirectory('Thriller', 'crackle', 'moviesByGenre', 'Thriller')
  75.     common.setView('seasons')
  76.  
  77. def moviesByGenre(genre=common.args.url):
  78.     movies(genre)
  79.  
  80. def movies(genre,db=False):
  81.     url = build_api_url('browse','movies','full',genre)
  82.     return listCatType(url,db,False)
  83.  
  84. def originals(db=False):
  85.     url = build_api_url('browse','originals')
  86.     return listCatType(url,db)
  87.  
  88. def collections(db=False):
  89.     url = build_api_url('browse','collections')
  90.     return listCatType(url,db,False)
  91.  
  92. def listCatType(url,db,showtype=True):
  93.     data = common.getURL(url)
  94.     db_shows=[]
  95.     if data:
  96.         items = demjson.decode(data)['Entries']
  97.         for item in items:
  98.             show_id=str(item['ID'])
  99.             name=item['Name']
  100.             if db==True:
  101.                 db_shows.append((name, 'crackle', 'showroot', show_id))
  102.             else:
  103.                 if showtype:
  104.                     common.addShow(name, 'crackle', 'showroot', show_id)
  105.                 else:
  106.                     plot=item['Description']
  107.                     genre=item['Genre']
  108.                     thumb=item['ChannelArtTileLarge']
  109.                     fanart=item['ChannelArtLandscape']
  110.                     common.addDirectory(name, 'crackle', 'showroot', show_id, thumb, '', plot, '',genre)
  111.     if db==True:
  112.         return db_shows
  113.     elif showtype:
  114.         common.setView('tvshows')
  115.     else:
  116.         common.setView('seasons')
  117.        
  118. def showroot(id=common.args.url):
  119.     url = build_api_url('channel','',ID=id)
  120.     data = common.getURL(url)
  121.     if data:
  122.         items = demjson.decode(data)['FolderList']
  123.         for item in items:
  124.             if 'Full Episodes'==item['Name'] or 'Television Clips & Trailers'==item['Name'] or 'Minisodes'==item['Name'] or 'Original Series'==item['Name'] or 'Movie'==item['Name'] or 'Movie Clips & Trailers'==item['Name']:
  125.                 for season in item['PlaylistList']:
  126.                     for video in season['MediaList']:
  127.                         thumb=video['ThumbnailExternal']
  128.                         ID=str(video['ID'])
  129.                         url = video['DetailsURL']
  130.                         infoLabels={}
  131.                         infoLabels['Title']=video['Title']
  132.                         infoLabels['Duration']=video['Duration']
  133.                         try:infoLabels['Season']=int(video['Season'])
  134.                         except:pass
  135.                         try:infoLabels['Episode']=int(video['Episode'])
  136.                         except:pass
  137.                         infoLabels['MPAA']=video['Rating']
  138.                         infoLabels['Genre']=video['Genre']
  139.                         infoLabels['TVShowTitle']=video['ParentChannelName']
  140.                         infoLabels['Plot']=video['Description']
  141.                         try:infoLabels['AirDate']=common.formatDate(video['ReleaseDate'],'%m/%d/%Y')
  142.                         except: print video['ReleaseDate']
  143.                         displayname=infoLabels['Title']
  144.                         if infoLabels.has_key('Season') or infoLabels.has_key('Episode'):
  145.                             displayname = str(infoLabels['Season'])+'x'+str(infoLabels['Episode'])+' - '+infoLabels['Title']
  146.                         u = sys.argv[0]
  147.                         u += '?url="'+urllib.quote_plus(ID)+'"'
  148.                         u += '&mode="crackle"'
  149.                         u += '&sitemode="play"'
  150.                         common.addVideo(u,displayname,thumb,infoLabels=infoLabels)
  151.     common.setView('episodes')
  152.  
  153. def make_auth(url):
  154.     hmac_key = 'WEUEVWJPCLTCQQDI'
  155.     sig = hmac.new(hmac_key, url)
  156.     return sig.hexdigest()
  157.  
  158. def play(url=common.args.url,playrtmp=False):
  159.     # GET DETAILS FROM API
  160.     #url = build_api_url('details','',ID=id,ios=True)
  161.     #data = common.getURL(url)
  162.     #if data:
  163.     #    for mediaUrl in demjson.decode(data)['MediaURLs']:
  164.     #        if mediaUrl['type'] == '480p_1mbps.mp4':
  165.     #            finalurl=mediaUrl['path']
  166.  
  167.     # GET ID FROM HTTP PAGE
  168.     #data = common.getURL(url)
  169.     #id,paremeters=re.compile("StartPlayer \((.+?), '(.+?)',").findall(data)[0]
  170.    
  171.     #Get file path
  172.     vidwall = 'http://www.crackle.com/app/vidwall.ashx?flags=-1&fm=%s&partner=20' % url
  173.     data = common.getURL(vidwall)
  174.     tree = BeautifulStoneSoup(data, convertEntities=BeautifulStoneSoup.XML_ENTITIES)
  175.     filepath = tree.find('i')['p']
  176.  
  177.     if playrtmp:
  178.         # RTMP STREAMING
  179.         rtmpbase = tree.find('channel')['strrtmpcdnurl']
  180.         swfUrl = 'http://www.crackle.com/flash/ReferrerRedirect.ashx'
  181.         finalurl = 'rtmp://'+rtmpbase+'/'+filepath+'480p_1mbps.mp4'+' swfurl='+swfUrl+" swfvfy=true"
  182.     else:
  183.         # HTTP STREAMING
  184.         finalurl = 'http://media-us-am.crackle.com/'+filepath+'480p_1mbps.mp4'
  185.  
  186.     item = xbmcgui.ListItem(path=finalurl)
  187.     return xbmcplugin.setResolvedUrl(pluginhandle, True, item)
Add Comment
Please, Sign In to add comment