Exemplo n.º 1
0
def compare_contents(l, r):
    lnetwork = util.get_nested_value(l, ['streams', 0, 'source', 'id'], '')
    rnetwork = util.get_nested_value(r, ['streams', 0, 'source', 'id'], '')
    try:
        lnetwork_sort = NETWORK_ID_SORT_ORDER.index(lnetwork.lower())
    except ValueError:
        lnetwork_sort = 1000
    try:
        rnetwork_sort = NETWORK_ID_SORT_ORDER.index(rnetwork.lower())
    except ValueError:
        rnetwork_sort = 1000
    ltype = l['status'] if 'status' in l else 'clip'
    rtype = r['status'] if 'status' in r else 'clip'
    lscore = l.get('score', 0)
    rscore = r.get('score', 0)
    return compare(get_time(l), lnetwork_sort, ltype, get_time(r),
                   rnetwork_sort, rtype, lscore, rscore)
Exemplo n.º 2
0
def view_espn_plus_details():
    account_details = espnplus.get_bam_account_details()
    email = util.get_nested_value(account_details, ['attributes', 'email'],
                                  'Unknown Email')
    profile_name = util.get_nested_value(account_details,
                                         ['activeProfile', 'profileName'],
                                         'Unknown Profile Name')
    product_details = email + ' - ' + profile_name + '\n'
    sub_details = espnplus.get_bam_sub_details()
    for sub in sub_details:
        if sub['isActive']:
            product_name = ''
            for product in sub['products']:
                product_name = product_name + ' ' + product['name']
            product_details = product_details + product_name + ' ' + sub[
                'expirationDate'] + '\n'
    dialog = xbmcgui.Dialog()
    dialog.ok(get_string(40260), product_details)
Exemplo n.º 3
0
def parse_json(url, bucket_path=None, channel_id=None):
    logging.debug('Looking at url %s %s' % (url, bucket_path))
    selected_bucket = bucket_path
    if selected_bucket is not None:
        selected_bucket = selected_bucket.split('/')
        logging.debug('Looking at bucket %s' % selected_bucket)
    json_data = util.get_url_as_json_cache(get_v3_url(url))
    buckets = []
    header_bucket = None
    if 'header' in json_data['page'] and 'bucket' in json_data['page'][
            'header']:
        description = util.get_nested_value(json_data,
                                            ['page', 'header', 'description'])
        subtitle = util.get_nested_value(json_data,
                                         ['page', 'header', 'subtitle'])
        director = util.get_nested_value(json_data,
                                         ['page', 'header', 'director'])
        plot = ''
        if subtitle is not None:
            plot = '%s\n' % (subtitle)
        if description is not None:
            plot = '%s%s\n' % (plot, description)
        if director is not None:
            plot = '%s%s\n' % (plot, director)
        header_bucket = json_data['page']['header']['bucket']
        header_bucket['contents'][0]['plot'] = plot
    if 'buckets' in json_data['page']:
        buckets = buckets + json_data['page']['buckets']
    was_search = 'name' in json_data['page'] and json_data['page'][
        'name'] == 'Suggestions'
    process_buckets(url,
                    header_bucket,
                    buckets,
                    selected_bucket,
                    list(),
                    channel_filter=channel_id,
                    was_search=was_search)
Exemplo n.º 4
0
def index_v3_vod(content):
    plot = content.get('description', '')

    event_id = content['eventId'] if 'eventId' in content else content['id']

    more_than_one_stream = len(content['streams']) > 1
    for stream in content['streams']:
        duration = parse_duration(stream['duration'])
        duration_seconds = duration.tm_hour * 3600 + duration.tm_min * 60 + duration.tm_sec

        name = content['name']
        if more_than_one_stream:
            name = name + ' - ' + stream['name']

        ename, length = get_item_listing_text(name, None, duration_seconds,
                                              None, '', 'blackoutText'
                                              in content, [])

        source_name = util.get_nested_value(content,
                                            ['stream', 0, 'source', 'name'])

        fanart = util.get_nested_value(content, ['imageHref'])

        info_labels = {
            'title': ename,
            'duration': length,
            'studio': source_name,
            'plot': plot
        }

        addDirectoryItem(
            plugin.handle,
            plugin.url_for(play_vod,
                           event_id=event_id,
                           url=stream['links']['play']),
            make_list_item(ename, info_labels=info_labels, icon=fanart))
Exemplo n.º 5
0
def index_v3_content(content):
    logging.debug('Indexing %s' % content)
    content_type = content['type']
    if content_type == 'show' or content_type == 'film' or content_type == 'product':
        index_v3_show(content)
        return
    if content_type == 'vod':
        index_v3_vod(content)
        return

    status = content['status']

    subtitle = content.get('subtitle', '')
    plot = subtitle
    if 'event' in content:
        event = content['event']
        if event['type'] == 'tvt':
            plot = '%s\n%s vs. %s\n%s - %s\n%s%s' % \
                   (subtitle,
                    get_team_name(event, 'One'),
                    get_team_name(event, 'Two'),
                    event['teamOneScore'], event['teamTwoScore'],
                    get_possesion_text(event),
                    event['statusTextOne'])
    if 'plot' in content:
        plot = content['plot']

    starttime = get_time(content)
    if 'date' in content and 'time' in content:
        plot = content['date'] + ' ' + content['time'] + '\n' + plot

    event_id = content['eventId'] if 'eventId' in content else content['id']

    more_than_one_stream = len(content['streams']) > 1
    for stream in content['streams']:
        if 'duration' in stream:
            duration = parse_duration(stream['duration'])
            duration_seconds = duration.tm_hour * 3600 + duration.tm_min * 60 + duration.tm_sec
        else:
            duration_seconds = 0

        name = content['name']
        if more_than_one_stream:
            name = name + ' - ' + stream['name']

        entitlements = espnplus.get_entitlements()
        packages = util.get_nested_value(stream, ['packages'], [])
        has_entitlement = is_entitled(packages, entitlements)
        ename, length = get_item_listing_text(
            name,
            starttime,
            duration_seconds,
            content['status'],
            stream['source']['name'],
            'blackoutText' in content,
            stream['authTypes'],
            requires_package=not has_entitlement)

        source_name = util.get_nested_value(stream, ['source', 'name'], '')

        fanart = util.get_nested_value(content, ['imageHref'])

        info_labels = {
            'title': ename,
            'genre': subtitle,
            'duration': length,
            'studio': source_name,
            'plot': plot
        }

        logging.debug('Checking to include %s' % source_name.lower())
        if include_item(source_name.lower()):
            if status == 'upcoming':
                starttime_text = time.strftime("%m/%d/%Y %I:%M %p", starttime)
                addDirectoryItem(
                    plugin.handle,
                    plugin.url_for(upcoming_event,
                                   event_id=event_id,
                                   event_name=quote_plus(name.encode('utf-8')),
                                   starttime=starttime_text,
                                   packages='|'.join(packages)),
                    make_list_item(ename, info_labels=info_labels))
            else:
                addDirectoryItem(
                    plugin.handle,
                    plugin.url_for(play_event,
                                   event_id=event_id,
                                   event_url=stream['links']['play'],
                                   auth_types='|'.join(stream['authTypes']),
                                   packages='|'.join(packages)),
                    make_list_item(ename, info_labels=info_labels,
                                   icon=fanart))
        else:
            logger.debug('Skipping item because of settings')
Exemplo n.º 6
0
def index_bucket_content(url, bucket, channel_filter):
    if 'contents' in bucket:
        bucket['contents'].sort(key=functools.cmp_to_key(compare_contents))
        grouped_events = dict()
        source_id_data = dict()
        content_indexed = 0
        for content in bucket['contents']:
            content_type = content['type']
            if content_type in [
                    'network', 'subcategory', 'category', 'program'
            ]:
                content_url = content['links']['self']
                if 'imageHref' in content:
                    fanart = content['imageHref']
                else:
                    fanart = None
                listitem = ListItem(content['name'])
                listitem.setArt({'icon': fanart})
                addDirectoryItem(plugin.handle,
                                 plugin.url_for(page_api_url, url=content_url),
                                 listitem, True)
            else:
                setContent(plugin.handle, 'episodes')
                source_id = util.get_nested_value(
                    content, ['streams', 0, 'source', 'id'])
                source_name = util.get_nested_value(
                    content, ['streams', 0, 'source', 'name'])
                channel_id = make_channel_id(source_id, source_name)
                if channel_filter is None:
                    source_type = util.get_nested_value(
                        content, ['streams', 0, 'source', 'type'])
                    if source_type == 'online':
                        if channel_id not in grouped_events:
                            grouped_events[channel_id] = []
                        grouped_events[channel_id].append(content)
                        source_id_data[channel_id] = {
                            'name': source_name,
                            'id': source_id
                        }
                    else:
                        index_content(content)
                        content_indexed = content_indexed + 1
                elif channel_filter == channel_id:
                    index_content(content)
                    content_indexed = content_indexed + 1

        # Handle grouped contents
        group_source_ids = list(grouped_events.keys())
        group_source_ids.sort(key=functools.cmp_to_key(compare_network_ids))
        for group_source_id in group_source_ids:
            contents = grouped_events[group_source_id]
            source_data = source_id_data[group_source_id]
            # Index the content directly if he haven't indexed a lot of things
            if content_indexed <= 3:
                for content in contents:
                    index_content(content)
            else:
                name = source_data['name']
                channel_id = source_data['id']
                if len(name) == 0 and channel_id == 'ESPN_PPV':
                    name = 'ESPN+ PPV'
                elif len(name) == 0:
                    name = channel_id
                addDirectoryItem(
                    plugin.handle,
                    plugin.url_for(page_api_channel,
                                   channel_id=group_source_id,
                                   url=url), ListItem(name), True)