adobe_activate_api.authenticate() dialog.ok(translation(30310), translation(30370)) except urllib2.HTTPError as e: dialog.ok(translation(30037), translation(30420) % e) mode = None refresh = True elif mode is not None and mode[0] == AUTHENTICATION_DETAILS_MODE: dialog = xbmcgui.Dialog() ok = dialog.yesno(translation(30380), translation(30390) % adobe_activate_api.get_authentication_expires(), translation(30700) % (player_config.get_dma(), player_config.get_timezone()), translation(30710) % (player_config.get_can_sso(), player_config.get_sso_abuse()), nolabel = translation(30360), yeslabel = translation(30430)) if ok: adobe_activate_api.deauthorize() mode = None refresh = True if mode is not None: paths = mode[0].split('/') if len(paths) > 2: root = paths[1] path = paths[2] xbmc.log(TAG + 'root: %s path: %s' % (root, path), xbmc.LOGDEBUG) for class_def in (appletv.AppleTV, legacy.Legacy, tvos.TVOS, roku.Roku, androidtv.AndroidTV): class_root = getattr(getattr(class_def, '__init__'), 'mode') xbmc.log(TAG + 'class root: %s' % class_root, xbmc.LOGDEBUG) if root == class_root: for method_name in dir(class_def):
def PLAY_TV(args): resource = args.get(ADOBE_RSS, None) network_name = args.get(NETWORK_NAME)[0] if resource is None: event_name = args.get(EVENT_NAME)[0] event_guid = args.get(EVENT_GUID)[0] event_parental_rating = args.get(EVENT_PARENTAL_RATING)[0] channel_resource_id = args.get(CHANNEL_RESOURCE_ID)[0] resource = adobe_activate_api.get_resource(channel_resource_id, event_name, event_guid, event_parental_rating) else: resource = resource[0] requires_auth = does_requires_auth(network_name) if not requires_auth: xbmc.log(TAG + ' Forcing auth', xbmc.LOGDEBUG) requires_auth = adobe_activate_api.is_authenticated() if requires_auth: if not adobe_activate_api.is_authenticated(): dialog = xbmcgui.Dialog() dialog.ok(translation(30037), translation(30410)) return try: # testing code raise urllib2.HTTPError(url='test', code=403, msg='no', hdrs=dict(), fp=None) xbmc.log(TAG + ' getting media token for resource %s' % resource, xbmc.LOGDEBUG) media_token = adobe_activate_api.get_short_media_token(resource) except urllib2.HTTPError as http_exception: xbmc.log(TAG + ' error getting media token %s' % http_exception, xbmc.LOGDEBUG) if http_exception.code == 410 or http_exception.code == 404 or http_exception.code == 401: dialog = xbmcgui.Dialog() dialog.ok(translation(30037), translation(30840)) adobe_activate_api.deauthorize() xbmcplugin.endOfDirectory(pluginhandle, succeeded=False, updateListing=True) return elif http_exception.code == 403: # Check for blackout dialog = xbmcgui.Dialog() ok = dialog.yesno(translation(30037), translation(30900)) if ok: setting = get_setting_from_channel(network_name) if setting is not None: selfAddon.setSetting(setting, 'false') return else: raise http_exception except adobe_activate_api.AuthorizationException as exception: xbmc.log(TAG + ' Error authorizating media token %s' % exception, xbmc.LOGDEBUG) dialog = xbmcgui.Dialog() dialog.ok(translation(30037), translation(30840)) adobe_activate_api.deauthorize() xbmcplugin.endOfDirectory(pluginhandle, succeeded=False, updateListing=True) return token_type = 'ADOBEPASS' else: media_token = adobe_activate_api.get_device_id() token_type = 'DEVICE' # see aHR0cDovL2FwaS1hcHAuZXNwbi5jb20vdjEvd2F0Y2gvY2xpZW50cy93YXRjaGVzcG4tdHZvcw== for details # see aHR0cDovL2VzcG4uZ28uY29tL3dhdGNoZXNwbi9hcHBsZXR2L2ZlYXR1cmVk for details start_session_url = args.get(SESSION_URL)[0] params = urllib.urlencode({ 'partner': 'watchespn', 'playbackScenario': 'HTTP_CLOUD_HIGH', 'platform': 'chromecast_uplynk', 'token': media_token, 'tokenType': token_type, 'resource': base64.b64encode(resource), 'v': '2.0.0' }) start_session_url += '&' + params xbmc.log('ESPN3: start_session_url: ' + start_session_url, xbmc.LOGDEBUG) try: session_json = util.get_url_as_json(start_session_url) except urllib2.HTTPError as exception: if exception.code == 403: session_json = json.load(exception) xbmc.log(TAG + 'checking for errors in %s' % session_json) else: raise exception if check_error(session_json): return playback_url = session_json['session']['playbackUrls']['default'] xbmc.log(TAG + 'Playback url %s' % playback_url, xbmc.LOGDEBUG) stream_quality = str(selfAddon.getSetting('StreamQuality')) bitrate_limit = int(selfAddon.getSetting('BitrateLimit')) xbmc.log(TAG + 'Stream Quality %s' % stream_quality, xbmc.LOGDEBUG) try: m3u8_obj = m3u8.load(playback_url) except: playback_url += '|Connection=keep-alive&User-Agent=' + urllib.quote(UA_PC) + '&Cookie=_mediaAuth=' +\ urllib.quote(session_json['session']['token']) item = xbmcgui.ListItem(path=playback_url) return xbmcplugin.setResolvedUrl(pluginhandle, True, item) success = True if m3u8_obj.is_variant: stream_options = list() bandwidth_key = 'bandwidth' m3u8_obj.playlists.sort( key=lambda playlist: playlist.stream_info.bandwidth, reverse=True) m3u8_obj.data['playlists'].sort( key=lambda playlist: int(playlist['stream_info'][bandwidth_key]), reverse=True) stream_quality_index = str(selfAddon.getSetting('StreamQualityIndex')) stream_index = None should_ask = False try: stream_index = int(stream_quality_index) if stream_index < 0 or stream_index >= len(m3u8_obj.playlists): should_ask = True except: should_ask = True if '0' == stream_quality: # Best stream_index = 0 should_ask = False for playlist in m3u8_obj.data['playlists']: stream_info = playlist['stream_info'] bandwidth = int(stream_info[bandwidth_key]) / 1024 if bandwidth <= bitrate_limit: break stream_index += 1 elif '2' == stream_quality: #Ask everytime should_ask = True if should_ask: for playlist in m3u8_obj.data['playlists']: stream_info = playlist['stream_info'] resolution = stream_info['resolution'] frame_rate = stream_info['frame_rate'] bandwidth = int(stream_info[bandwidth_key]) / 1024 if 'average_bandwidth' in stream_info: xbmc.log( TAG + 'bandwidth: %s average bandwidth: %s' % (stream_info['bandwidth'], stream_info['average_bandwidth']), xbmc.LOGDEBUG) stream_options.append( translation(30450) % (resolution, frame_rate, bandwidth)) dialog = xbmcgui.Dialog() stream_index = dialog.select(translation(30440), stream_options) if stream_index < 0: success = False else: selfAddon.setSetting(id='StreamQualityIndex', value=str(stream_index)) xbmc.log(TAG + 'Chose stream %d' % stream_index, xbmc.LOGDEBUG) item = xbmcgui.ListItem(path=m3u8_obj.playlists[stream_index].uri) xbmcplugin.setResolvedUrl(pluginhandle, success, item) else: item = xbmcgui.ListItem(path=playback_url) xbmcplugin.setResolvedUrl(pluginhandle, success, item)
dialog.ok(translation(30037), translation(30420) % e) mode = None refresh = True elif mode is not None and mode[0] == AUTHENTICATION_DETAILS_MODE: dialog = xbmcgui.Dialog() ok = dialog.yesno( translation(30380), translation(30390) % adobe_activate_api.get_authentication_expires(), translation(30700) % (player_config.get_dma(), player_config.get_timezone()), translation(30710) % (player_config.get_can_sso(), player_config.get_sso_abuse()), nolabel=translation(30360), yeslabel=translation(30430)) if ok: adobe_activate_api.deauthorize() mode = None refresh = True if mode is not None: paths = mode[0].split('/') if len(paths) > 2: root = paths[1] path = paths[2] xbmc.log(TAG + 'root: %s path: %s' % (root, path), xbmc.LOGDEBUG) for class_def in (appletv.AppleTV, legacy.Legacy, tvos.TVOS, roku.Roku, androidtv.AndroidTV): class_root = getattr(getattr(class_def, '__init__'), 'mode') xbmc.log(TAG + 'class root: %s' % class_root, xbmc.LOGDEBUG) if root == class_root: for method_name in dir(class_def):
def check_auth_status(auth_types, packages, resource, network_name): logging.debug('Checking auth of %s and %s' % (auth_types, packages)) if requires_adobe_auth(auth_types): # Adobe auth if not adobe_activate_api.is_authenticated(): dialog = xbmcgui.Dialog() ret = dialog.yesno(get_string(30038), get_string(30050), yeslabel=get_string(30051), nolabel=get_string(30360)) if ret: authed = auth_routes.login_tv_provider() if not authed: return None else: return None try: # testing code raise HTTPError(url='test', code=403, msg='no', hdrs=dict(), fp=None) logging.debug('getting media token for resource %s' % resource) return adobe_activate_api.get_short_media_token(resource) except HTTPError as http_exception: logging.debug('error getting media token %s' % http_exception) if http_exception.code == 410 or http_exception.code == 404 or http_exception.code == 401: dialog = xbmcgui.Dialog() dialog.ok(get_string(30037), get_string(30840)) adobe_activate_api.deauthorize() return None elif http_exception.code == 403: # Check for blackout dialog = xbmcgui.Dialog() ok = dialog.yesno(get_string(30037), get_string(30900) % http_exception) if ok: setting = get_setting_from_channel(network_name) if setting is not None: set_setting(setting, False) return None else: return None except adobe_activate_api.AuthorizationException as exception: logging.debug('Error authorizating media token %s' % exception) if 'message' in exception.resp and 'details' in exception.resp: message = exception.resp['message'] details = exception.resp['details'] if 'noAuthz' == message: # Channel likely not supported dialog = xbmcgui.Dialog() ok = dialog.yesno(get_string(30037), get_string(30900) % details) if ok: setting = get_setting_from_channel(network_name) if setting is not None: set_setting(setting, False) return None dialog = xbmcgui.Dialog() dialog.ok(get_string(30037), get_string(30840)) adobe_activate_api.deauthorize() return None elif 'direct' in auth_types: # bam authentication if not espnplus.can_we_access_without_prompt(): logging.debug('Invalid token') dialog = xbmcgui.Dialog() ret = dialog.yesno(get_string(30038), get_string(30060), yeslabel=get_string(30061), nolabel=get_string(30360)) if ret: authed = auth_routes.login_espn_plus() if not authed: return None else: return None espnplus.ensure_valid_access_token() # Check packages entitlements = espnplus.get_entitlements() has_entitlement = is_entitled(packages, entitlements) if not has_entitlement: missing_packages = get_missing_packages(packages, entitlements) dialog = xbmcgui.Dialog() dialog.ok(get_string(40000), get_string(40270) % ', '.join(missing_packages)) return espnplus.get_bam_account_access_token() elif 'isp' in auth_types: return adobe_activate_api.get_device_id() logging.error('Unable to handle auth types') return None
def logout_tv_provider(): dialog = xbmcgui.Dialog() ok = dialog.yesno(get_string(30381), get_string(30382)) if ok: adobe_activate_api.deauthorize() set_setting('LoggedInToTvProvider', False)
def PLAY_TV(args): resource = args.get(ADOBE_RSS, None) network_name = args.get(NETWORK_NAME)[0] if resource is None: event_name = args.get(EVENT_NAME)[0] event_guid = args.get(EVENT_GUID)[0] event_parental_rating = args.get(EVENT_PARENTAL_RATING)[0] channel_resource_id = args.get(CHANNEL_RESOURCE_ID)[0] resource = adobe_activate_api.get_resource(channel_resource_id, event_name, event_guid, event_parental_rating) else: resource = resource[0] requires_auth = does_requires_auth(network_name) if not requires_auth: xbmc.log(TAG + ' Forcing auth', xbmc.LOGDEBUG) requires_auth = adobe_activate_api.is_authenticated() if requires_auth: if not adobe_activate_api.is_authenticated(): dialog = xbmcgui.Dialog() dialog.ok(translation(30037), translation(30410)) return try: # testing code raise urllib2.HTTPError(url='test', code=403, msg='no', hdrs=dict(), fp=None) xbmc.log(TAG + ' getting media token for resource %s' % resource, xbmc.LOGDEBUG) media_token = adobe_activate_api.get_short_media_token(resource) except urllib2.HTTPError as http_exception: xbmc.log(TAG + ' error getting media token %s' % http_exception, xbmc.LOGDEBUG) if http_exception.code == 410 or http_exception.code == 404: dialog = xbmcgui.Dialog() dialog.ok(translation(30037), translation(30840)) adobe_activate_api.deauthorize() xbmcplugin.endOfDirectory(pluginhandle, succeeded=False, updateListing=True) return elif http_exception.code == 403: # Check for blackout dialog = xbmcgui.Dialog() ok = dialog.yesno(translation(30037), translation(30900)) if ok: setting = get_setting_from_channel(network_name) if setting is not None: selfAddon.setSetting(setting, 'false') return else: raise http_exception token_type = 'ADOBEPASS' else: media_token = adobe_activate_api.get_device_id() token_type = 'DEVICE' # see aHR0cDovL2FwaS1hcHAuZXNwbi5jb20vdjEvd2F0Y2gvY2xpZW50cy93YXRjaGVzcG4tdHZvcw== for details # see aHR0cDovL2VzcG4uZ28uY29tL3dhdGNoZXNwbi9hcHBsZXR2L2ZlYXR1cmVk for details start_session_url = args.get(SESSION_URL)[0] params = urllib.urlencode({'partner':'watchespn', 'playbackScenario':'HTTP_CLOUD_HIGH', 'platform':'chromecast_uplynk', 'token':media_token, 'tokenType':token_type, 'resource':base64.b64encode(resource), 'v': '2.0.0' }) start_session_url += '&' + params xbmc.log('ESPN3: start_session_url: ' + start_session_url, xbmc.LOGDEBUG) try: session_json = util.get_url_as_json(start_session_url) except urllib2.HTTPError as exception: if exception.code == 403: session_json = json.load(exception) xbmc.log(TAG + 'checking for errors in %s' % session_json) else: raise exception if check_error(session_json): return playback_url = session_json['session']['playbackUrls']['default'] xbmc.log(TAG + 'Playback url %s' % playback_url, xbmc.LOGDEBUG) stream_quality = str(selfAddon.getSetting('StreamQuality')) bitrate_limit = int(selfAddon.getSetting('BitrateLimit')) xbmc.log(TAG + 'Stream Quality %s' % stream_quality, xbmc.LOGDEBUG) try: m3u8_obj = m3u8.load(playback_url) except: playback_url += '|Connection=keep-alive&User-Agent=' + urllib.quote(UA_PC) + '&Cookie=_mediaAuth=' +\ urllib.quote(session_json['session']['token']) item = xbmcgui.ListItem(path=playback_url) return xbmcplugin.setResolvedUrl(pluginhandle, True, item) success = True if m3u8_obj.is_variant: stream_options = list() bandwidth_key = 'bandwidth' m3u8_obj.playlists.sort(key=lambda playlist: playlist.stream_info.bandwidth, reverse=True) m3u8_obj.data['playlists'].sort(key=lambda playlist: int(playlist['stream_info'][bandwidth_key]), reverse=True) stream_quality_index = str(selfAddon.getSetting('StreamQualityIndex')) stream_index = None should_ask = False try: stream_index = int(stream_quality_index) if stream_index < 0 or stream_index >= len(m3u8_obj.playlists): should_ask = True except: should_ask = True if '0' == stream_quality: # Best stream_index = 0 should_ask = False for playlist in m3u8_obj.data['playlists']: stream_info = playlist['stream_info'] bandwidth = int(stream_info[bandwidth_key]) / 1024 if bandwidth <= bitrate_limit: break stream_index += 1 elif '2' == stream_quality: #Ask everytime should_ask = True if should_ask: for playlist in m3u8_obj.data['playlists']: stream_info = playlist['stream_info'] resolution = stream_info['resolution'] frame_rate = stream_info['frame_rate'] bandwidth = int(stream_info[bandwidth_key]) / 1024 if 'average_bandwidth' in stream_info: xbmc.log(TAG + 'bandwidth: %s average bandwidth: %s' % (stream_info['bandwidth'], stream_info['average_bandwidth']), xbmc.LOGDEBUG) stream_options.append(translation(30450) % (resolution, frame_rate, bandwidth)) dialog = xbmcgui.Dialog() stream_index = dialog.select(translation(30440), stream_options) if stream_index < 0: success = False else: selfAddon.setSetting(id='StreamQualityIndex', value=str(stream_index)) xbmc.log(TAG + 'Chose stream %d' % stream_index, xbmc.LOGDEBUG) item = xbmcgui.ListItem(path=m3u8_obj.playlists[stream_index].uri) xbmcplugin.setResolvedUrl(pluginhandle, success, item) else: item = xbmcgui.ListItem(path=playback_url) xbmcplugin.setResolvedUrl(pluginhandle, success, item)