Esempio n. 1
0
def update_token(sess):
    """Update token

    This functions performs a HTTP POST to the token URL and it will update
    the requests session with a token required for API calls
    """
    res = sess.post(config.TOKEN_URL)
    try:
        token = json.loads(res.text).get('token')
    except Exception as e:
        raise exceptions.AussieAddonsException(
            'Failed to retrieve API token: {0}\n'
            'Service may be currently unavailable.'.format(e))
    sess.headers.update({'x-media-mis-token': token})
Esempio n. 2
0
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
Esempio n. 3
0
def parse_json_live(video_data):
    """Parse JSON live stream data

    Parse the JSON data for live match and construct a video object from it
    for a list of videos
    """
    streams = video_data.get('videoStreams')
    video_stream = None
    for stream in streams:
        for attrib in stream.get('customAttributes'):
            if attrib.get('attrName') in [
                    'brightcove_videoid', 'brightcove_videoid_VIC'
            ]:
                video_stream = stream
                break
        if video_stream:
            break
    if not video_stream:
        return

    attrs = video_stream.get('customAttributes')

    video = classes.Video()
    title = utils.ensure_ascii(video_data.get('title'))
    video.title = '[COLOR green][LIVE NOW][/COLOR] {0}'.format(title)
    video.thumbnail = get_attr(attrs, 'imageURL')

    if get_attr(attrs, 'entitlement') == 'true':
        video.subscription_required = True

    # Look for 'national' stream (e.g. Foxtel)
    video_id = get_attr(attrs, 'brightcove_videoid')
    if not video_id:
        video_id = get_attr(attrs, 'brightcove_videoid_VIC')
    if not video_id:
        utils.log(
            'Unable to find video ID from stream data: {0}'.format(video_data))
        raise exceptions.AussieAddonsException('Unable to find video '
                                               'ID from stream data.')

    video.video_id = video_id
    video.live = True
    video.type = 'B'
    return video
def parse_json_live(video_data):
    """Parse JSON live stream data

    Parse the JSON data for live match and construct a video object from it
    for a list of videos
    """
    video_stream = video_data.get('videoStream')
    if not video_stream:
        return

    attrs = video_stream.get('customAttributes')
    if not attrs:
        return

    video = classes.Video()
    title = utils.ensure_ascii(video_data.get('title'))
    video.title = '[COLOR green][LIVE NOW][/COLOR] {0}'.format(title)
    video.thumbnail = video_stream.get('thumbnailURL')

    if video_stream.get('entitlement'):
        video.subscription_required = True

    # Look for 'national' stream (e.g. Foxtel)
    video_id = get_attr(attrs, 'ooyala embed code')

    if not video_id:
        # Look for configured state stream
        state = ADDON.getSetting('STATE')
        video_id = get_attr(attrs, 'state-' + state)

    if not video_id:
        # Fall back to the VIC stream
        video_id = get_attr(attrs, 'state-VIC')

    if not video_id:
        utils.log(
            'Unable to find video ID from stream data: {0}'.format(video_data))
        raise exceptions.AussieAddonsException('Unable to find video '
                                               'ID from stream data.')

    video.ooyalaid = video_id
    video.live = True
    return video
Esempio n. 5
0
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