Beispiel #1
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)
Beispiel #2
0
        ROOT_ITEM(refresh)
    except IOError as exception:
        xbmc.log('SSL certificate failure %s' % exception, xbmc.LOGDEBUG)
        xbmc.log(
            '%s-%s-%s' %
            (exception.errno, exception.message, exception.strerror),
            xbmc.LOGDEBUG)
        xbmc.log('err: %s' % err, xbmc.LOGDEBUG)
        xbmc.log('repr(err): %s ' % repr(err), xbmc.LOGDEBUG)
        xbmc.log('err.reason: %s' % err.reason, xbmc.LOGDEBUG)
        xbmc.log('repr(err.reason): %s' % repr(err.reason), xbmc.LOGDEBUG)
        if '[SSL: CERTIFICATE_VERIFY_FAILED]' in str(exception.strerror):
            dialog = xbmcgui.Dialog()
            ok = dialog.yesno(translation(30037), translation(30910))
            if ok:
                selfAddon.setSetting('DisableSSL', 'true')
                ROOT_ITEM(refresh)
            else:
                raise exception
        else:
            raise exception

elif mode[0] == PLAY_ITEM_MODE:
    PLAY_ITEM(args)
elif mode[0] == PLAY_TV_MODE:
    PLAY_TV(args)
elif mode[0] == UPCOMING_MODE:
    xbmc.log("Upcoming", xbmc.LOGDEBUG)
    dialog = xbmcgui.Dialog()
    dialog.ok(translation(30035), translation(30036))
    xbmcplugin.endOfDirectory(pluginhandle,
Beispiel #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]
        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)
Beispiel #4
0
    try:
        adobe_activate_api.clean_up_authorization_tokens()
    except:
        xbmc.log(TAG + 'Unable to clean up')
        adobe_activate_api.reset_settings()
    xbmc.log("Generate Main Menu", xbmc.LOGDEBUG)
    try:
        ROOT_ITEM(refresh)
    except IOError as exception:
        xbmc.log('SSL certificate failure %s' % exception, xbmc.LOGDEBUG)
        xbmc.log('%s-%s-%s' % (exception.errno, exception.message, exception.strerror), xbmc.LOGDEBUG)
        if '[SSL: CERTIFICATE_VERIFY_FAILED]' in str(exception.strerror):
            dialog = xbmcgui.Dialog()
            ok = dialog.yesno(translation(30037), translation(30910))
            if ok:
                selfAddon.setSetting('DisableSSL', 'true')
                ROOT_ITEM(refresh)
            else:
                raise exception
        else:
            raise exception

elif mode[0] == PLAY_ITEM_MODE:
    PLAY_ITEM(args)
elif mode[0] == PLAY_TV_MODE:
    PLAY_TV(args)
elif mode[0] == UPCOMING_MODE:
    xbmc.log("Upcoming", xbmc.LOGDEBUG)
    dialog = xbmcgui.Dialog()
    dialog.ok(translation(30035), translation(30036))
    xbmcplugin.endOfDirectory(pluginhandle, succeeded=False, updateListing=True)