From c1d47845e3922d3dff065d1003e647442bacf473 Mon Sep 17 00:00:00 2001 From: eracknaphobia Date: Sat, 27 Jan 2018 10:10:19 -0500 Subject: [plugin.video.crackle] 2018.1.27 --- plugin.video.crackle/addon.xml | 9 +- plugin.video.crackle/main.py | 45 +++++----- plugin.video.crackle/resources/lib/globals.py | 116 +++++++++++++++----------- 3 files changed, 94 insertions(+), 76 deletions(-) diff --git a/plugin.video.crackle/addon.xml b/plugin.video.crackle/addon.xml index fe8b2cb..9caaf50 100644 --- a/plugin.video.crackle/addon.xml +++ b/plugin.video.crackle/addon.xml @@ -1,7 +1,8 @@ - + - + + video @@ -11,6 +12,10 @@ Crackle delivers popular, award-winning TV, movies and originals. With no limit to how much you can watch across all your devices, you can binge all you want, wherever you want. Crackle is a video streaming distributor of original web shows, Hollywood movies, and TV shows. Founded in the early 2000s as Grouper, and rebranded in 2007, Crackle is owned by Sony Pictures Entertainment. + + - Added support for inputstream adaptive + - Code clean up + en all GNU GENERAL PUBLIC LICENSE. Version 2, June 1991 diff --git a/plugin.video.crackle/main.py b/plugin.video.crackle/main.py index 27674bd..28be0aa 100644 --- a/plugin.video.crackle/main.py +++ b/plugin.video.crackle/main.py @@ -1,10 +1,10 @@ from resources.lib.globals import * -params=get_params() -media_id=None -name=None -mode=None -stream_type=None +params = get_params() +media_id = None +name = None +mode = None +stream_type = None try: media_id=urllib.unquote_plus(params["id"]) @@ -23,24 +23,21 @@ try: except: pass -if mode==None: - #test() - #or url==None or len(url)<1 - mainMenu() -elif mode==100: - listShows() - -elif mode==101: - listMovies() - -elif mode==102: - getEpisodes(media_id) - -elif mode==103: - if stream_type == "movies": media_id = getMovieID(media_id) - getStream(media_id) - -elif mode==999: - deauthorize() +if mode is None: + main_menu() + +elif mode == 100: + list_shows() + +elif mode == 101: + list_movies() + +elif mode == 102: + get_episodes(media_id) + +elif mode == 103: + if stream_type == "movies": media_id = get_movie_id(media_id) + get_stream(media_id) + xbmcplugin.endOfDirectory(addon_handle) \ No newline at end of file diff --git a/plugin.video.crackle/resources/lib/globals.py b/plugin.video.crackle/resources/lib/globals.py index d9bc030..c4ce2c6 100644 --- a/plugin.video.crackle/resources/lib/globals.py +++ b/plugin.video.crackle/resources/lib/globals.py @@ -1,46 +1,43 @@ import sys, os -import xbmc, xbmcplugin, xbmcgui, xbmcaddon -import urllib, urllib2 -import json +import urllib, requests import base64, hmac, hashlib -from datetime import datetime +from time import gmtime, strftime +import xbmc, xbmcplugin, xbmcgui, xbmcaddon addon_handle = int(sys.argv[1]) ADDON = xbmcaddon.Addon() ROOTDIR = ADDON.getAddonInfo('path') -FANART = ROOTDIR+"/resources/media/fanart.jpg" -ICON = os.path.join(ROOTDIR,"/resources/media/icon.png") +FANART = os.path.join(ROOTDIR,"resources","media","fanart.jpg") +ICON = os.path.join(ROOTDIR,"resources","media","icon.png") -#Addon Settings +# Addon Settings LOCAL_STRING = ADDON.getLocalizedString UA_CRACKLE = 'Crackle/7.60 CFNetwork/808.3 Darwin/16.3.0' UA_WEB = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36' UA_ANDROID = 'Android 4.1.1; E270BSA; Crackle 4.4.5.0' -PRIVATE_KEY = 'MIRNPSEZYDAQASLX' +PRIVATE_KEY = 'TUlSTlBTRVpZREFRQVNMWA==' VENDOR_ID = '25' BASE_URL = 'http://android-tv-api-us.crackle.com/Service.svc' -def mainMenu(): - addDir('Movies','/movies',101,ICON) - addDir('TV','/tv',100,ICON) +def main_menu(): + add_dir('Movies', '/movies', 101, ICON) + add_dir('TV', '/tv', 100, ICON) -def listMovies(): +def list_movies(): url = '/browse/movies/full/all/alpha-asc/US' url += '?pageSize=500' url += '&pageNumber=1' url += '&format=json' - json_source = jsonRequest(url) - + json_source = json_request(url) for movie in json_source['Entries']: title = movie['Title'] url = str(movie['ID']) icon = movie['ChannelArtTileLarge'] fanart = movie['Images']['Img_1920x1080'] - info = None info = {'plot':movie['Description'], 'genre':movie['Genre'], 'year':movie['ReleaseYear'], @@ -50,23 +47,21 @@ def listMovies(): 'duration':movie['DurationInSeconds'] } - addStream(title,url,'movies',icon,fanart,info) - + add_stream(title,url,'movies',icon,fanart,info) -def listShows(): +def list_shows(): url = '/browse/shows/full/all/alpha-asc/US' url += '?pageSize=500' url += '&pageNumber=1' url += '&format=json' - json_source = jsonRequest(url) + json_source = json_request(url) for show in json_source['Entries']: title = show['Title'] url = str(show['ID']) icon = show['ChannelArtTileLarge'] fanart = show['Images']['Img_1920x1080'] - info = None info = {'plot':show['Description'], 'genre':show['Genre'], 'year':show['ReleaseYear'], @@ -76,12 +71,12 @@ def listShows(): 'duration':show['DurationInSeconds'] } - addDir(title,url,102,icon,fanart,info) + add_dir(title,url,102,icon,fanart,info) -def getEpisodes(channel): +def get_episodes(channel): url = '/channel/'+channel+'/playlists/all/US?format=json' - json_source = jsonRequest(url) + json_source = json_request(url) for episode in json_source['Playlists'][0]['Items']: episode = episode['MediaInfo'] @@ -101,20 +96,19 @@ def getEpisodes(channel): 'episode':episode['Episode'] } - addStream(title,id,'tvshows',icon,fanart,info) + add_stream(title,id,'tvshows',icon,fanart,info) -def getMovieID(channel): +def get_movie_id(channel): url = '/channel/'+str(channel)+'/playlists/all/US?format=json' - json_source = jsonRequest(url) + json_source = json_request(url) return str(json_source['Playlists'][0]['Items'][0]['MediaInfo']['Id']) -def getStream(id): +def get_stream(id): url = '/details/media/'+id+'/US?format=json' - json_source = jsonRequest(url) - + json_source = json_request(url) for stream in json_source['MediaURLs']: if 'AppleTV' in stream['Type']: @@ -122,13 +116,23 @@ def getStream(id): stream_url = stream_url[0:stream_url.index('.m3u8')]+'.m3u8' break - stream_url += '|User-Agent='+UA_CRACKLE - listitem = xbmcgui.ListItem(path=stream_url) + headers = '|User-Agent='+UA_CRACKLE + listitem = xbmcgui.ListItem() + if xbmc.getCondVisibility('System.HasAddon(inputstream.adaptive)'): + listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') + listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') + listitem.setProperty('inputstream.adaptive.stream_headers', headers) + listitem.setProperty('inputstream.adaptive.license_key', headers) + else: + stream_url += headers + + listitem.setPath(stream_url) xbmcplugin.setResolvedUrl(addon_handle, True, listitem) -def jsonRequest(url): +def json_request(url): url = BASE_URL + url + ''' req = urllib2.Request(url) req.add_header("Connection", "keep-alive") req.add_header("User-Agent", UA_ANDROID) @@ -137,44 +141,56 @@ def jsonRequest(url): response = urllib2.urlopen(req) json_source = json.load(response) response.close() + ''' + + headers = { + 'Connection': 'keep-alive', + 'User-Agent': UA_ANDROID, + 'Authorization': get_auth(url) + } + + r = requests.get(url,headers=headers) - return json_source + return r.json() -def calcHmac(src): - return hmac.new(PRIVATE_KEY, src, hashlib.md5).hexdigest() +def calc_hmac(src): + return hmac.new(base64.b64decode(PRIVATE_KEY), src, hashlib.md5).hexdigest() -def getAuth(url): - timestamp = datetime.utcnow().strftime('%Y%m%d%H%M') - encoded_url = str(calcHmac(url+"|"+timestamp)).upper() + "|" + timestamp + "|" + VENDOR_ID +def get_auth(url): + timestamp = strftime('%Y%m%d%H%M', gmtime()) + encoded_url = str(calc_hmac(url+"|"+timestamp)).upper() + "|" + timestamp + "|" + VENDOR_ID return encoded_url -def addStream(name, id, stream_type, icon,fanart,info=None): - ok=True +def add_stream(name, id, stream_type, icon, fanart, info=None): + ok = True u=sys.argv[0]+"?id="+urllib.quote_plus(id)+"&mode="+str(103)+"&type="+urllib.quote_plus(stream_type) liz=xbmcgui.ListItem(name) - liz.setArt({'icon': ICON, 'thumb': icon, 'fanart': fanart}) + if fanart == None: fanart = FANART + liz.setArt({'icon': icon, 'thumb': icon, 'fanart': fanart}) liz.setProperty("IsPlayable", "true") - liz.setInfo( type="Video", infoLabels={ "Title": name } ) - if info != None: + liz.setInfo(type="Video", infoLabels={"Title": name}) + if info is not None: liz.setInfo( type="Video", infoLabels=info) - ok=xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=liz,isFolder=False) + ok = xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=liz,isFolder=False) xbmcplugin.setContent(addon_handle, stream_type) return ok -def addDir(name,id,mode,iconimage,fanart=None,info=None): - params = get_params() - ok=True +def add_dir(name,id,mode,icon,fanart=None,info=None): + xbmc.log(ROOTDIR) + xbmc.log("ICON IMAGE = "+icon) + ok = True u=sys.argv[0]+"?id="+urllib.quote_plus(id)+"&mode="+str(mode) liz=xbmcgui.ListItem(name) - liz.setArt({'icon': ICON, 'thumb': iconimage, 'fanart': fanart}) - if info != None: + if fanart == None: fanart = FANART + liz.setArt({'icon': icon, 'thumb': icon, 'fanart': fanart}) + if info is not None: liz.setInfo( type="Video", infoLabels=info) - ok=xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=liz,isFolder=True) + ok = xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=liz,isFolder=True) xbmcplugin.setContent(addon_handle, 'tvshows') return ok -- cgit v1.2.3