def play(params): try: import drmhelper if not drmhelper.check_inputstream(drm=False): return except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message('DRM Helper is needed for inputstream.adaptive ' 'playback. For more information, please visit: ' 'http://aussieaddons.com/drm') return try: stream = comm.get_stream(params['video_id']) utils.log('Attempting to play: {0} {1}'.format(stream['name'], stream['url'])) item = xbmcgui.ListItem(label=stream['name'], path=stream['url']) item.setProperty('inputstreamaddon', 'inputstream.adaptive') item.setProperty('inputstream.adaptive.manifest_type', 'hls') item.setMimeType('application/vnd.apple.mpegurl') item.setContentLookup(False) xbmcplugin.setResolvedUrl(pluginhandle, True, listitem=item) except Exception: utils.handle_error('Unable to play video')
def router(paramstring): """ Router function that calls other functions depending on the provided paramstring :param paramstring: """ params = dict(parse_qsl(paramstring)) if params: if params['action'] == 'listcategories': if params['category'] == 'settings': addon.openSettings() else: matches.make_matches_list(params) elif params['action'] == 'listmatches': play.play_video(params) elif params['action'] == 'clearticket': stream_auth.clear_ticket() elif params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'open_ia_settings': try: import drmhelper if drmhelper.check_inputstream(drm=False): ia = drmhelper.get_addon() ia.openSettings() else: utils.dialog_message( "Can't open inputstream.adaptive settings") except Exception: utils.dialog_message( "Can't open inputstream.adaptive settings") else: categories.list_categories()
def router(paramstring): """ Router function that calls other functions depending on the provided paramstring :param paramstring: """ params = dict(parse_qsl(paramstring)) utils.log('Running with params: {0}'.format(params)) if params: if params['action'] == 'listcategories': if params['category'] == 'Live Matches': menu.list_matches(params, live=True) elif params['category'] == 'Settings': addon.openSettings() else: menu.list_videos(params) elif params['action'] in ['listvideos', 'listmatches']: play.play_video(params) elif params['action'] == 'clearticket': stream_auth.clear_ticket() elif params['action'] == 'open_ia_settings': try: import drmhelper if drmhelper.check_inputstream(drm=False): ia = drmhelper.get_addon() ia.openSettings() else: utils.dialog_message( "Can't open inputstream.adaptive settings") except Exception: utils.dialog_message( "Can't open inputstream.adaptive settings") else: menu.list_categories()
def clear_token(): """Remove stored token from cache storage""" try: cache.delete('AFLTOKEN') utils.dialog_message('Login token removed') except AttributeError: pass
def make_list(): try: videos = comm.get_videos() if len(videos) == 0: utils.dialog_message(['No videos found.', 'Please try again later.']) else: for video in videos: url = "%s?video_id=%s" % (sys.argv[0], video['video_id']) listitem = xbmcgui.ListItem(video['name'], iconImage=video['thumbnail'], thumbnailImage=video['thumbnail']) listitem.setProperty('IsPlayable', 'true') listitem.setInfo('video', {'plot': video['name']}) # add the item to the media list xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False, totalItems=len(videos)) xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) except Exception: utils.handle_error('Unable build video list')
def get_stream(program_id): token = get_login_token() if not token: return addon = xbmcaddon.Addon() data_url = config.STREAM_URL.format(VIDEOID=program_id, UNIQUEID=addon.getSetting('unique_id'), AAID=addon.getSetting('ad_id'), OPTOUT='true') video_stream_resp = fetch_protected_url(data_url, token) vs_data = json.loads(video_stream_resp) if vs_data.get('error'): utils.dialog_message( 'Error getting stream info - please log out and log in again') return stream_info = {} for provider in vs_data.get('streamProviders'): if provider.get('providerName') == 'Akamai HLS': stream_info['stream_url'] = provider.get('contentUrl') subtitles = provider.get('subtitles') if subtitles: for subs in subtitles: if subs.get('language') == 'en': stream_info['subtitles'] = subs.get('srt') break return stream_info
def make_list(): try: matches = comm.get_matches() if len(matches) == 0: utils.dialog_message(['No matches are currently being played.', 'Please try again later.']) else: for match in matches: url = "%s?video_id=%s" % (sys.argv[0], match['video_id']) listitem = xbmcgui.ListItem(match['name'], iconImage=match['thumbnail'], thumbnailImage=match['thumbnail']) listitem.setProperty('IsPlayable', 'true') listitem.setInfo('video', {'plot': match['name']}) # add the item to the media list ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False, totalItems=len(matches)) xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) except Exception: utils.handle_error('Unable build match list')
def clear_login_token(show_dialog=True): addon = xbmcaddon.Addon() addon.setSetting('user_token', '') addon.setSetting('unique_id', '') addon.setSetting('ad_id', '') if show_dialog: utils.dialog_message('Login token cleared. Ensure you press OK in ' 'the settings to save this change.')
def play(url): try: params = utils.get_url(url) v = classes.Video() v.parse_xbmc_url(url) if params.get('isdummy'): xbmcgui.Dialog().ok( 'Dummy item', 'This item is not playable, it is used only to display ' 'the upcoming schedule. Please check back once the match ' 'has started. Playable matches will have "LIVE NOW" in ' 'green next to the title.') if 'ooyalaid' in params: login_token = None if params.get('subscription_required') == 'True': login_token = ooyalahelper.get_user_token() stream_data = ooyalahelper.get_m3u8_playlist(params['ooyalaid'], v.live, login_token) else: stream_data = {'stream_url': v.get_url()} listitem = xbmcgui.ListItem(label=v.get_title(), iconImage=v.get_thumbnail(), thumbnailImage=v.get_thumbnail(), path=stream_data.get('stream_url')) inputstream = drmhelper.check_inputstream(drm=v.live) if not inputstream: utils.dialog_message( 'Failed to play stream. Please visit our website at ' 'http://aussieaddons.com/addons/afl/ for more ' 'information.') return widevine_url = stream_data.get('widevine_url') if inputstream and (not v.live or not widevine_url): listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.license_key', stream_data.get('stream_url')) elif v.live: listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'mpd') listitem.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') listitem.setProperty('inputstream.adaptive.license_key', widevine_url + '|Content-Type=application%2F' 'x-www-form-urlencoded|A{SSM}|') listitem.addStreamInfo('video', v.get_kodi_stream_info()) listitem.setInfo('video', v.get_kodi_list_item()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error('Unable to play video')
def main(): params_str = sys.argv[2] params = utils.get_url(params_str) addon = xbmcaddon.Addon() if (len(params) == 0): categories.make_category_list() elif 'action' in params: action = params.get('action') if action in ['program_list', 'livestreams']: play.play(params_str) elif action in ['series_list']: if params.get('type') == 'Series': if params.get('dummy') == 'True': return else: programs.make_programs_list(params) else: play.play(params_str) elif action == 'collect_list': series.make_series_list(params, atoz=False) elif action == 'category_list': category = params.get('category') if category == 'settings': addon.openSettings() elif category == 'livestreams': live.make_livestreams_list() elif category == 'search': search.make_search_history_list() else: if addon.getSetting('SHOW_COLLECTIONS') == '1': collect.make_collect_list(params) else: series.make_series_list(params) elif action == 'searchhistory': if params.get('name') == 'New Search': search.get_search_input() else: search.make_search_list(params) elif action == 'removesearch': search.remove_from_search_history(params.get('name')) elif action == 'sendreport': utils.user_report() elif action == 'open_ia_settings': try: import drmhelper if drmhelper.check_inputstream(drm=False): ia = drmhelper.get_addon() ia.openSettings() else: utils.dialog_message( "Can't open inputstream.adaptive settings") except Exception: utils.dialog_message( "Can't open inputstream.adaptive settings")
def get_favourites_data(config_data): token = get_login_token() if not token: utils.dialog_message('You must be logged in to view favourites') return {} fav_all_url = config_data.get('favourites').get('listAll') json_data = json.loads(fetch_protected_url(fav_all_url, token)) if json_data.get('all').get('status') is True: return json_data else: utils.log(json_data) raise Exception('invalid favourites data')
def main(): addon = xbmcaddon.Addon() if addon.getSetting('firstrun') == 'true': utils.dialog_message( 'Welcome to the new On Demand add-on. An SBS On Demand account ' 'is now required to use this service. Please sign up at ' 'sbs.com.au or in the mobile app, then enter your details in ' 'the add-on settings.') comm.get_login_token() addon.setSetting('firstrun', 'false') params_str = sys.argv[2] params = utils.get_url(params_str) utils.log(str(params)) if len(params) == 0: index.make_index_list() elif params.get('obj_type') == 'Program': play.play(params_str) elif 'feed_url' in params: index.make_entries_list(params) elif 'category' in params or params.get('item_type') in [ 'ProgramGenre', 'FilmGenre', 'Channel' ]: if params.get('category') == 'Search': index.make_search_history_list() else: index.make_category_list(params) elif 'action' in params: action = params.get('action') if action == 'favouritescategories': index.make_favourites_categories_list() elif action == 'addfavourites': comm.add_to_favourites(params) elif action == 'removefavourites': comm.remove_from_favourites(params) xbmc.executebuiltin('Container.Refresh') elif action == 'searchhistory': if params.get('name') == 'New Search': search.get_search_input() else: index.make_search_list(params) elif action == 'removesearch': search.remove_from_search_history(params.get('name')) elif action == 'sendreport': utils.user_report() elif action == 'settings': xbmcaddon.Addon().openSettings() elif action == 'logout': comm.clear_login_token() elif action == 'login': comm.get_login_token() xbmc.executebuiltin('Container.Refresh')
def get_auth(hn, sess): """Calculate signature and build auth URL for a program""" ts = str(int(time.time())) path = config.AUTH_URL + 'ts={0}&hn={1}&d=android-mobile'.format(ts, hn) digest = hmac.new(config.SECRET, msg=path, digestmod=hashlib.sha256).hexdigest() auth_url = config.BASE_URL + path + '&sig=' + digest try: res = sess.get(auth_url) except requests.exceptions.HTTPError as e: if e.response.status_code == 404: utils.dialog_message( 'Accurate system time required for ' 'playback. Please set the correct system ' 'time/date/timezone for your location and try again.') raise exceptions.AussieAddonsException(e) return res.text
def add_to_favourites(params): token = get_login_token() if not token: utils.dialog_message('You must be logged in to add favourites') return conf = get_config() entry_type = params.get('entry_type') url = conf.get('favourites').get('add{0}'.format( config.FAV_DICT[entry_type])) resp = fetch_protected_url(url.replace('[ID]', params.get('program_id')), token) json_data = json.loads(resp) if (json_data.get('add').get('status') == True # noqa: E712 and json_data.get('add').get('response').get('result') == True): return True else: utils.log('Error adding favourite')
def router(paramstring): """ Router function that calls other functions depending on the provided paramstring """ params = dict(parse_qsl(paramstring)) if paramstring: if paramstring != 'content_type=video': if params['action'] == 'listcategories': if params['category'] == 'All Shows': menu.make_series_list(paramstring) elif params['category'] == 'Live TV': menu.make_live_list(paramstring) else: menu.make_series_list(paramstring) elif params['action'] == 'listseries': menu.make_episodes_list(paramstring) elif params['action'] == 'listepisodes': play.play_video(params) elif params['action'] == 'listchannels': play.play_video(params) elif params['action'] == 'settings': xbmcaddon.Addon().openSettings() elif params['action'] == 'reinstall_widevine_cdm': drmhelper.get_widevinecdm() elif params['action'] == 'reinstall_ssd_wv': drmhelper.get_ssd_wv() elif params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'update_ia': addon = drmhelper.get_addon(drm=True) if not drmhelper.is_ia_current(addon, latest=True): if xbmcgui.Dialog().yesno( 'Upgrade?', ('Newer version of inputstream.adaptive ' 'available ({0}) - would you like to ' 'upgrade to this version?'.format( drmhelper.get_latest_ia_ver()))): drmhelper.get_ia_direct(update=True, drm=True) else: ver = addon.getAddonInfo('version') utils.dialog_message('Up to date: Inputstream.adaptive ' 'version {0} installed and enabled.' ''.format(ver)) else: menu.list_categories()
def main(): params_str = sys.argv[2] params = utils.get_url(params_str) utils.log('Loading with params: {0}'.format(params)) if len(params) == 0: index.make_list() elif 'category' in params: if params['category'] == 'Settings': xbmcaddon.Addon().openSettings() elif params['category'] == 'Team Video': teams.make_list() elif params['category'] == 'All Match Replays': index.make_seasons_list() else: videos.make_list(params) elif 'season' in params: rounds.make_rounds(params) elif 'team' in params: videos.make_list(params) elif 'round_id' in params: videos.make_list(params) elif 'title' in params: play.play(params_str) elif 'action' in params: if params['action'] == 'cleartoken': stream_auth.clear_token() elif params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'iap_help': stream_auth.iap_help() elif params['action'] == 'open_ia_settings': try: import drmhelper if drmhelper.check_inputstream(drm=False): ia = drmhelper.get_addon() ia.openSettings() else: utils.dialog_message( "Can't open inputstream.adaptive settings") except Exception: utils.dialog_message( "Can't open inputstream.adaptive settings")
def router(paramstring): """ Router function that calls other functions depending on the provided paramstring """ params = dict(parse_qsl(paramstring)) if paramstring: if paramstring != 'content_type=video': if params['action'] == 'listcategories': if params['category'] == 'Live TV': menu.make_live_list(paramstring) else: menu.make_series_list(paramstring) elif params['action'] == 'listseries': menu.make_episodes_list(paramstring) elif params['action'] in ['listepisodes', 'listchannels']: play.play_video(params) elif params['action'] == 'settings': xbmcaddon.Addon().openSettings() elif params['action'] == 'reinstall_widevine_cdm': drmhelper.get_widevinecdm() elif params['action'] == 'reinstall_ssd_wv': drmhelper.get_ssd_wv() elif params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'update_ia': addon = drmhelper.get_addon(drm=True) if not drmhelper.is_ia_current(addon, latest=True): if xbmcgui.Dialog().yesno( 'Upgrade?', ('Newer version of inputstream.adaptive ' 'available ({0}) - would you like to ' 'upgrade to this version?'.format( drmhelper.get_latest_ia_ver()))): drmhelper.get_ia_direct(update=True, drm=True) else: ver = addon.getAddonInfo('version') utils.dialog_message('Up to date: Inputstream.adaptive ' 'version {0} installed and enabled.' ''.format(ver)) else: menu.list_categories()
def get_stream(program): token = get_login_token() if not token: return addon = xbmcaddon.Addon() data_url = config.STREAM_URL.format( VIDEOID=program.id, UNIQUEID=addon.getSetting('unique_id'), AAID=addon.getSetting('ad_id'), OPTOUT='true') video_stream_resp = fetch_protected_url(data_url, token) vs_data = json.loads(video_stream_resp) if vs_data.get('error'): utils.dialog_message( 'Error getting stream info - please log out and log in again') return stream_info = {} kodi_ver = utils.get_kodi_major_version() if kodi_ver >= 19 and addon.getSetting('DAI') == 'true': try: info = json.loads( fetch_url(config.DAI_URL.format(vid=program.id), post=True)) stream_info['stream_url'] = info.get('stream_manifest') except Exception as e: utils.log('Encountered exception in parsing DAI url: {0}'.format( str(e))) if stream_info.get('stream_url'): program.needs_ia = True return stream_info # fallback/kodi 18 for provider in vs_data.get('streamProviders'): if provider.get('providerName') == 'Akamai HLS': stream_info['stream_url'] = provider.get('contentUrl') subtitles = provider.get('subtitles') if subtitles: for subs in subtitles: if subs.get('language') == 'en': stream_info['subtitles'] = subs.get('srt') break return stream_info
def get_login_token(): addon = xbmcaddon.Addon() encoded_token = addon.getSetting('user_token') if encoded_token: return encoded_token addon.setSetting('unique_id', str(uuid.uuid4())) addon.setSetting('ad_id', str(uuid.uuid4())) username = xbmcgui.Dialog().input('Enter SBS on Demand username/email', type=xbmcgui.INPUT_ALPHANUM) if not username: return False password = xbmcgui.Dialog().input('Enter SBS on Demand password', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT) if not password: return False upresp = fetch_url(config.LOGIN1_URL, data={ 'context': 'android', 'device': 'phone', 'version': config.APP_VERSION, 'loginVersion': '1.0.0', 'user': username, 'pass': password, 'express': '0' }) upresp_json = json.loads(upresp) if upresp_json.get('error', '') == 'invalid_credentials': utils.dialog_message('Invalid username or password. Please check and ' 'try again.') return False access_token = upresp_json.get('access_token') # insert check for email validation?? atresp = fetch_url(config.LOGIN2_URL.format(token=access_token)) session_id = json.loads(atresp)['completelogin']['response'].get( 'sessionid') encoded_token = base64.b64encode( '{0}:android'.format(session_id).encode('utf-8')) addon.setSetting('user_token', encoded_token) return encoded_token.decode('utf-8')
def get_auth(hn, sess): """Calculate signature and build auth URL for a program""" ts = str(int(time.time())) auth_path = config.AUTH_PATH.format( params=config.AUTH_PARAMS.format(ts=ts, hn=hn)) auth_path_bytes = bytes(auth_path) if py2 else bytes(auth_path, 'utf8') secret = bytes(config.SECRET) if py2 else bytes(config.SECRET, 'utf8') digest = hmac.new(secret, msg=auth_path_bytes, digestmod=hashlib.sha256).hexdigest() auth_url = config.API_BASE_URL.format( path='{authpath}&sig={digest}'.format(authpath=auth_path, digest=digest)) try: res = sess.get(auth_url) except requests.exceptions.HTTPError as e: if e.response.status_code == 404: utils.dialog_message( 'Accurate system time required for ' 'playback. Please set the correct system ' 'time/date/timezone for your location and try again.') raise exceptions.AussieAddonsException(e) return res.text
def clear_ticket(): """ Remove stored ticket from cache storage """ cache.delete('NETBALLTICKET') utils.dialog_message('Login token removed')
elif 'category' in params: if params['category'] == 'settings': xbmcaddon.Addon().openSettings() else: series.make_series_list(params_str) elif 'action' in params: if params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'update_ia': try: import drmhelper addon = drmhelper.get_addon(drm=False) if not drmhelper.is_ia_current(addon, latest=True): if xbmcgui.Dialog().yesno( 'Upgrade?', ('Newer version of inputstream.adaptive ' 'available ({0}) - would you like to ' 'upgrade to this version?'.format( drmhelper.get_latest_ia_ver()))): drmhelper.get_ia_direct(update=True, drm=False) else: ver = addon.getAddonInfo('version') utils.dialog_message('Up to date: Inputstream.adaptive ' 'version {0} installed and enabled.' ''.format(ver)) except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message('DRM Helper is needed for this function. ' 'For more information, please visit: ' 'http://aussieaddons.com/drm')
def play(url): try: # Remove cookies.dat for Kodi < 17.0 - causes issues with playback addon = xbmcaddon.Addon() cookies_dat = xbmc.translatePath('special://home/cache/cookies.dat') if os.path.isfile(cookies_dat): os.remove(cookies_dat) p = classes.Program() p.parse_kodi_url(url) stream_data = comm.get_stream_url(p.get_house_number(), p.get_url()) stream_url = stream_data.get('stream_url') if not stream_url: utils.log('Not Playable: {0}'.format(repr(stream_data))) raise AussieAddonsException( 'Not available: {0}\n{1}'.format(stream_data.get('msg'), stream_data.get( 'availability'))) use_ia = addon.getSetting('USE_IA') == 'true' if use_ia: if addon.getSetting('IGNORE_DRM') == 'false': try: import drmhelper if not drmhelper.check_inputstream(drm=False): return except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message( 'DRM Helper is needed for inputstream.adaptive ' 'playback. Disable "Use inputstream.adaptive for ' 'playback" in settings or install drmhelper. For ' 'more information, please visit: ' 'http://aussieaddons.com/drm') return hdrs = stream_url[stream_url.find('|') + 1:] listitem = xbmcgui.ListItem(label=p.get_list_title(), path=stream_url) thumb = p.get_thumb() listitem.setArt({'icon': thumb, 'thumb': thumb}) if use_ia: listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.stream_headers', hdrs) listitem.setProperty('inputstream.adaptive.license_key', stream_url) listitem.setInfo('video', p.get_kodi_list_item()) # Add subtitles if available if p.is_captions(): captions_url = stream_data.get('captions_url') profile = xbmcaddon.Addon().getAddonInfo('profile') path = xbmc.translatePath(profile) if not os.path.isdir(path): os.makedirs(path) caption_file = os.path.join(path, 'subtitles.eng.srt') if os.path.isfile(caption_file): os.remove(caption_file) try: sess = session.Session() webvtt_data = sess.get(captions_url).text if webvtt_data: with io.BytesIO() as buf: webvtt_captions = WebVTTReader().read(webvtt_data) srt_captions = SRTWriter().write(webvtt_captions) srt_unicode = srt_captions.encode('utf-8') buf.write(srt_unicode) with io.open(caption_file, "wb") as f: f.write(buf.getvalue()) if hasattr(listitem, 'setSubtitles'): listitem.setSubtitles([caption_file]) except Exception as e: utils.log( 'Subtitles not available for this program: {0}'.format(e)) if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info()) listitem.addStreamInfo('video', p.get_kodi_video_stream_info()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error('Unable to play video')
def play(url): try: addon = xbmcaddon.Addon() p = classes.Program() p.parse_kodi_url(url) stream_info = comm.get_stream(p) if not stream_info: return stream_url = stream_info.get('stream_url') if p.needs_ia: import drmhelper if not drmhelper.check_inputstream(drm=False): utils.dialog_message( "inputstream.adaptive needed for playback of" "DAI streams, please disable 'Use DAI Streams' in" "SBS add-on settings for playback.") return bandwidth = addon.getSetting('BANDWIDTH') if bandwidth == '0': stream_url = stream_url.replace('&b=0-2000', '&b=400-600') elif bandwidth == '1': stream_url = stream_url.replace('&b=0-2000', '&b=900-1100') elif bandwidth == '2': stream_url = stream_url.replace('&b=0-2000', '&b=1400-1600') listitem = comm.create_listitem(label=p.get_list_title(), path=str(stream_url)) listitem.setArt({'icon': p.thumb, 'thumb': p.thumb}) listitem.setInfo('video', p.get_kodi_list_item()) # Add subtitles if available if 'subtitles' in stream_info: sub_url = stream_info['subtitles'] profile = addon.getAddonInfo('profile') path = xbmc.translatePath(profile) if not os.path.isdir(path): os.makedirs(path) subfile = xbmc.translatePath( os.path.join(path, 'subtitles.eng.srt')) if os.path.isfile(subfile): os.remove(subfile) try: sess = session.Session() data = sess.get(sub_url).text f = open(subfile, 'w') f.write(data) f.close() if hasattr(listitem, 'setSubtitles'): # This function only supported from Kodi v14+ listitem.setSubtitles([subfile]) except Exception: utils.log('Subtitles not available for this program') listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.license_key', stream_url) if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info()) listitem.addStreamInfo('video', p.get_kodi_video_stream_info()) listitem.setProperty('isPlayable', 'true') if utils.get_kodi_major_version() >= 18: listitem.setIsFolder(False) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) np = comm.get_next_program(p) if not isinstance(np, classes.Program): return next_info = OrderedDict(current_episode=OrderedDict( episodeid=p.id, tvshowid=p.get_tvshowid(), title=p.get_title(), art={ 'thumb': p.get_thumb(), 'tvshow.fanart': p.get_fanart(), }, season=p.get_season_no(), episode=p.get_episode_no(), showtitle=p.get_series_title(), plot=p.get_description(), playcount=0, rating=None, firstaired=p.get_date(), runtime=p.get_duration(), ), next_episode=OrderedDict( episodeid=np.id, tvshowid=np.get_tvshowid(), title=np.get_title(), art={ 'thumb': np.get_thumb(), 'tvshow.fanart': np.get_fanart(), }, season=np.get_season_no(), episode=np.get_episode_no(), showtitle=np.get_series_title(), plot=np.get_description(), playcount=0, rating=None, firstaired=np.get_date(), runtime=np.get_duration(), ), play_url='{0}?{1}'.format( sys.argv[0], np.make_kodi_url()), notification_offset=p.get_credits_time()) upnext_signal('plugin.video.sbs', next_info) except Exception: utils.handle_error("Unable to play video")
programs.make_programs_list(params_str) elif 'category' in params: if params['category'] == 'settings': xbmcaddon.Addon().openSettings() else: series.make_series_list(params_str) elif 'action' in params: if params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'update_ia': try: import drmhelper addon = drmhelper.get_addon(drm=False) if not drmhelper.is_ia_current(addon, latest=True): if xbmcgui.Dialog().yesno( 'Upgrade?', ('Newer version of inputstream.adaptive ' 'available ({0}) - would you like to ' 'upgrade to this version?'.format( drmhelper.get_latest_ia_ver()))): drmhelper.get_ia_direct(update=True, drm=False) else: ver = addon.getAddonInfo('version') utils.dialog_message('Up to date: Inputstream.adaptive ' 'version {0} installed and enabled.' ''.format(ver)) except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message('DRM Helper is needed for this function. ' 'For more information, please visit: ' 'http://aussieaddons.com/drm')
def play(url): try: # Remove cookies.dat for Kodi < 17.0 - causes issues with playback addon = xbmcaddon.Addon() cookies_dat = xbmc.translatePath('special://home/cache/cookies.dat') if os.path.isfile(cookies_dat): os.remove(cookies_dat) p = classes.Program() p.parse_xbmc_url(url) stream = comm.get_stream_url(p.get_house_number(), p.get_url()) use_ia = addon.getSetting('use_ia') == 'true' if use_ia: if addon.getSetting('ignore_drm') == 'false': try: import drmhelper if not drmhelper.check_inputstream(drm=False): return except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message( 'DRM Helper is needed for inputstream.adaptive ' 'playback. Disable "Use inputstream.adaptive for ' 'playback" in settings or install drmhelper. For ' 'more information, please visit: ' 'http://aussieaddons.com/drm') return hdrs = stream[stream.find('|') + 1:] listitem = xbmcgui.ListItem(label=p.get_list_title(), iconImage=p.thumbnail, thumbnailImage=p.thumbnail, path=stream) if use_ia: listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.stream_headers', hdrs) listitem.setProperty('inputstream.adaptive.license_key', stream) listitem.setInfo('video', p.get_kodi_list_item()) # Add subtitles if available if p.subtitle_url: profile = xbmcaddon.Addon().getAddonInfo('profile') path = xbmc.translatePath(profile).decode('utf-8') if not os.path.isdir(path): os.makedirs(path) subfile = xbmc.translatePath( os.path.join(path, 'subtitles.eng.srt')) if os.path.isfile(subfile): os.remove(subfile) try: webvtt_data = urllib2.urlopen( p.subtitle_url).read().decode('utf-8') if webvtt_data: with open(subfile, 'w') as f: webvtt_subtitle = WebVTTReader().read(webvtt_data) srt_subtitle = SRTWriter().write(webvtt_subtitle) srt_unicode = srt_subtitle.encode('utf-8') f.write(srt_unicode) if hasattr(listitem, 'setSubtitles'): listitem.setSubtitles([subfile]) except Exception as e: utils.log( 'Subtitles not available for this program {0}'.format(e)) if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info()) listitem.addStreamInfo('video', p.get_kodi_video_stream_info()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error('Unable to play video')
index.make_seasons_list() else: videos.make_list(params) elif 'season' in params: rounds.make_rounds(params) elif 'team' in params: videos.make_list(params) elif 'round_id' in params: videos.make_list(params) elif 'title' in params: play.play(params_str) elif 'action' in params: if params['action'] == 'cleartoken': ooyalahelper.clear_token() elif params['action'] == 'sendreport': utils.user_report() elif params['action'] == 'iap_help': ooyalahelper.iap_help() elif params['action'] == 'open_ia_settings': try: import drmhelper if drmhelper.check_inputstream(drm=False): ia = drmhelper.get_addon() ia.openSettings() else: utils.dialog_message( "Can't open inputstream.adaptive settings") except Exception as e: utils.dialog_message( "Can't open inputstream.adaptive settings")
def get_entries(params): """ Deal with everything else that isn't the main index or a category/genre! :) :param url: :return: """ listing = [] sort = False multi_page = False begin = int(params.get('page_begin', 1)) size = int(params.get('page_size', 50)) feed_url_no_range = params.get('feed_url') if params.get('item_type') == 'Collection': sort = True feed_url = append_range(feed_url_no_range, begin, size) if params.get('require_login') == 'True': token = get_login_token() if not token: utils.dialog_message('You must be logged in to view this') return listing resp = fetch_protected_url(feed_url, token) else: resp = fetch_url(feed_url) json_data = json.loads(resp) if params.get('multi_series') == 'True': thumb = json_data.get('program').get('thumbnailUrl') seasons = get_attr(json_data.get('rows'), 'name', 'Seasons', default=[]) for season in create_seasons_list(seasons, thumb): listing.append(season) else: if params.get('single_series') == 'True': # flatten single series seasons = get_attr(json_data.get('rows'), 'name', 'Seasons', 'feeds', default=[]) if not seasons: # new series but no episodes yet return listing season = seasons[0] json_data = json.loads(fetch_url(season.get('feedUrl'))) total_items = int(json_data.get('totalNumberOfItems')) if total_items > begin + size - 1: multi_page = True for entry in json_data.get('itemListElement'): try: if params.get('item_type') == 'genre': p = create_genre_index(entry) elif entry.get('type') == 'TVSeries': p = create_series(entry) elif entry.get('type') == 'Channel': p = create_channel(entry) p.item_type = 'Channel' elif params.get('item_type') == 'hero': if entry.get('type') == 'Program': p = create_series(entry.get('program')) elif entry.get('type') == 'VideoCarouselItem': p = create_program(entry.get('video')) elif params.get('item_type') == 'collection': p = create_collection(entry) else: p = create_program(entry) listing.append(p) except Exception: raise # remove once stable utils.log('Error parsing entry') if sort: listing = sorted(listing) if multi_page: begin += size listing.append(create_page(begin, size, feed_url_no_range)) return listing
def test_dialog_message(self, mock_ok_dialog): utils.dialog_message('bar', 'foo') mock_ok_dialog.assert_called_once_with('foo', 'bar')
if params['title'] == 'Live TV': live.make_live_list(params_str) elif params['title'] == 'Settings': xbmcaddon.Addon().openSettings() else: series.make_series_list(params) elif action == 'list_series': programs.make_programs_list(params) elif action == 'list_programs': play.play(params) elif action == 'sendreport': utils.user_report() elif action == 'reinstall_widevine_cdm': drmhelper.get_widevinecdm() elif action == 'reinstall_ssd_wv': drmhelper.get_ssd_wv() elif action == 'update_ia': addon = drmhelper.get_addon(drm=True) if not drmhelper.is_ia_current(addon, latest=True): if xbmcgui.Dialog().yesno( 'Upgrade?', ('Newer version of inputstream.adaptive ' 'available ({0}) - would you like to ' 'upgrade to this version?'.format( drmhelper.get_latest_ia_ver()))): drmhelper.get_ia_direct(update=True, drm=True) else: ver = addon.getAddonInfo('version') utils.dialog_message('Up to date: Inputstream.adaptive ' 'version {0} installed and enabled.' ''.format(ver))