Exemplo n.º 1
0
def ROOT_ITEM(refresh):
    if not adobe_activate_api.is_authenticated():
        addDir('[COLOR=FFFF0000]' + translation(30300) + '[/COLOR]',
               dict(MODE=AUTHENTICATE_MODE), defaultreplay)
    current_time = time.strftime("%I:%M %p", time.localtime(time.time()))
    addDir(
        translation(30850) % current_time, dict(MODE=REFRESH_LIVE_MODE),
        defaultlive)
    include_premium = adobe_activate_api.is_authenticated()
    channel_list = events.get_channel_list(include_premium)
    legacy_inst = legacy.Legacy()
    espn_url = list()
    espn_url.append(events.get_live_events_url(channel_list))
    legacy_inst.index_legacy_live_events(dict(ESPN_URL=espn_url))
    if selfAddon.getSetting('ShowAndroidTVMenu') == 'true':
        addDir(translation(30780), dict(MODE='/androidtv/'), defaultlive)
    if selfAddon.getSetting('ShowAppleTVMenu') == 'true':
        addDir(translation(30730), dict(MODE='/appletv/'), defaultlive)
    if selfAddon.getSetting('ShowLegacyMenu') == 'true':
        addDir(translation(30740), dict(MODE='/legacy/'), defaultlive)
    if selfAddon.getSetting('ShowRokuMenu') == 'true':
        addDir(translation(30760), dict(MODE='/roku/'), defaultlive)
    if selfAddon.getSetting('ShowTVOSMenu') == 'true':
        addDir(translation(30750), dict(MODE='/tvos/'), defaultlive)
    if adobe_activate_api.is_authenticated():
        addDir('[COLOR=FF00FF00]' + translation(30380) + '[/COLOR]',
               dict(MODE=AUTHENTICATION_DETAILS_MODE), defaultfanart)
    xbmcplugin.endOfDirectory(pluginhandle,
                              updateListing=refresh,
                              cacheToDisc=False)
Exemplo n.º 2
0
def ROOT_ITEM(refresh):
    if not adobe_activate_api.is_authenticated():
        addDir('[COLOR=FFFF0000]' + translation(30300) + '[/COLOR]',
               dict(MODE=AUTHENTICATE_MODE),
               defaultreplay)
    current_time = time.strftime("%I:%M %p", time.localtime(time.time()))
    addDir(translation(30850) % current_time,
           dict(MODE=REFRESH_LIVE_MODE),
           defaultlive)
    include_premium = adobe_activate_api.is_authenticated()
    channel_list = events.get_channel_list(include_premium)
    legacy_inst = legacy.Legacy()
    espn_url = list()
    espn_url.append(events.get_live_events_url(channel_list))
    legacy_inst.index_legacy_live_events(dict(ESPN_URL=espn_url))
    if selfAddon.getSetting('ShowAndroidTVMenu') == 'true':
        addDir(translation(30780),
               dict(MODE='/androidtv/'),
               defaultlive)
    if selfAddon.getSetting('ShowAppleTVMenu') == 'true':
        addDir(translation(30730),
               dict(MODE='/appletv/'),
               defaultlive)
    if selfAddon.getSetting('ShowLegacyMenu') == 'true':
        addDir(translation(30740),
               dict(MODE='/legacy/'),
               defaultlive)
    if selfAddon.getSetting('ShowRokuMenu') == 'true':
        addDir(translation(30760),
               dict(MODE='/roku/'),
               defaultlive)
    if selfAddon.getSetting('ShowTVOSMenu') == 'true':
        addDir(translation(30750),
               dict(MODE='/tvos/'),
               defaultlive)
    if adobe_activate_api.is_authenticated():
        addDir('[COLOR=FF00FF00]' + translation(30380) + '[/COLOR]',
           dict(MODE=AUTHENTICATION_DETAILS_MODE),
           defaultfanart)
    xbmcplugin.endOfDirectory(pluginhandle, updateListing=refresh, cacheToDisc=False)
Exemplo n.º 3
0
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]
        resource = adobe_activate_api.get_resource(network_name, event_name, event_guid, event_parental_rating)
    else:
        resource = resource[0]

    requires_auth = does_requires_auth(network_name)

    if requires_auth:
        if not adobe_activate_api.is_authenticated():
            dialog = xbmcgui.Dialog()
            dialog.ok(translation(30037), translation(30410))
            return
        media_token = adobe_activate_api.get_short_media_token(resource)
        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, LOG_LEVEL)

    session_json = util.get_url_as_json(start_session_url)
    if check_error(session_json):
        return

    playback_url = session_json['session']['playbackUrls']['default']
    xbmc.log(TAG + 'Playback url %s' % playback_url, LOG_LEVEL)
    stream_quality = str(selfAddon.getSetting('StreamQuality'))
    bitrate_limit = int(selfAddon.getSetting('BitrateLimit'))
    xbmc.log(TAG + 'Stream Quality %s' % stream_quality, LOG_LEVEL)
    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 = 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']), LOG_LEVEL)
                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, LOG_LEVEL)
        item = xbmcgui.ListItem(path=m3u8_obj.playlists[stream_index].uri)
        return xbmcplugin.setResolvedUrl(pluginhandle, success, item)
    else:
        item = xbmcgui.ListItem(path=playback_url)
        return xbmcplugin.setResolvedUrl(pluginhandle, success, item)
Exemplo n.º 4
0
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)