def list_sports(): espn_url = arg_as_string('espn_url') if 'action=replay' in espn_url: image = defaultreplay elif 'action=upcoming' in espn_url: image = defaultupcoming else: image = None addDirectoryItem(plugin.handle, plugin.url_for(live_events_mode, espn_url=espn_url), make_list_item(get_string(30034), icon=image), True) sports = [] sport_elements = util.get_url_as_xml_cache(espn_url).findall( './/sportDisplayValue') for sport in sport_elements: sport = sport.text.encode('utf-8') if sport not in sports: sports.append(sport) for sport in sports: addDirectoryItem( plugin.handle, plugin.url_for(live_sport_events_mode, sport=sport, espn_url=espn_url), make_list_item(sport, icon=image), True) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE) xbmcplugin.endOfDirectory(plugin.handle)
def appletv_root_menu(): trending_mode() addDirectoryItem(plugin.handle, plugin.url_for(appletv_featured), make_list_item(get_string(30680)), True) addDirectoryItem(plugin.handle, plugin.url_for(appletv_sports), make_list_item(get_string(30550)), True) addDirectoryItem(plugin.handle, plugin.url_for(appletv_channels), make_list_item(get_string(30560)), True) endOfDirectory(plugin.handle)
def tvos_root_menu(): page_api.parse_json(TV_OS_HOME) addDirectoryItem(plugin.handle, plugin.url_for(page_api.page_api_url, url=TV_OS_SPORTS), make_list_item(get_string(30550)), True) addDirectoryItem(plugin.handle, plugin.url_for(page_api.page_api_url, url=TV_OS_CHANNELS), make_list_item(get_string(30560)), True) endOfDirectory(plugin.handle)
def process_item_list(item_list): stashes = list() for item in item_list: stash_element = item.find('./stash/json') if item.get('id').startswith('loadMore'): method_info = util.parse_method_call(item.get('onSelect')) if method_info[0] == 'espn.page.loadMore': label = item.find('./label') label2 = item.find('./label2') menu_label = '' if label is not None: menu_label = label.text if label2 is not None: menu_label = menu_label + ' ' + label2.text if label is None and label2 is None: menu_label = get_string(30570) url = method_info[3] nav_id = method_info[2] url = url + '&navigationItemId=' + nav_id logging.debug('Load more url %s' % url) addDirectoryItem(plugin.handle, plugin.url_for(appletv_showcase, url=url), make_list_item(menu_label), True) elif not item.get('id') == 'no-event': if stash_element is None: # Assume goes to another onPlay with a url name = item.get('accessibilityLabel') image = item.find('./image').get('src') url = util.parse_url_from_method(item.get('onPlay')) addDirectoryItem(plugin.handle, plugin.url_for(appletv_showcase, url=url), make_list_item(name, image), True) else: stash = stash_element.text.encode('utf-8') # Some of the json is baddly formatted stash = re.sub(r'\s+"', '"', stash) stash_json = json.loads(stash, 'utf-8') stash_json['internal_item'] = item stashes.append(stash_json) logging.debug('sorting %s items' % len(stashes)) stashes.sort(key=functools.cmp_to_key(compare_appletv)) for stash_json in stashes: if stash_json['type'] == 'upcoming': index_tv_shelf(stash_json, True) elif 'sessionUrl' in stash_json: index_tv_shelf(stash_json, False) else: index_item_shelf(stash_json)
def appletv_showcase(): url = arg_as_string('url') selected_nav_id = arg_as_string('nav_id') et = util.get_url_as_xml_cache(get_url(url)) navigation_items = et.findall('.//navigation/navigationItem') logging.debug('Found %s items' % len(navigation_items)) if selected_nav_id == '' and len(navigation_items) > 0: for navigation_item in navigation_items: name = navigation_item.find('./title').text nav_id = navigation_item.get('id') menu_item = navigation_item.find('.//twoLineMenuItem') if menu_item is None: menu_item = navigation_item.find('.//twoLineEnhancedMenuItem') if menu_item is not None and not menu_item.get('id') == 'no-event': addDirectoryItem( plugin.handle, plugin.url_for(appletv_showcase, url=url, nav_id=nav_id), make_list_item(name), True) elif len(navigation_items) > 0: for navigation_item in navigation_items: if str(navigation_item.get('id')) == selected_nav_id: logging.debug('Found nav item %s' % selected_nav_id) process_item_list( navigation_item.findall('.//twoLineMenuItem')) process_item_list( navigation_item.findall('.//twoLineEnhancedMenuItem')) setContent(plugin.handle, 'episodes') else: # If there are no navigation items then just dump all of the menu entries logging.debug('Dumping all menu items') process_item_list(et.findall('.//twoLineMenuItem')) process_item_list(et.findall('.//twoLineEnhancedMenuItem')) setContent(plugin.handle, 'episodes') endOfDirectory(plugin.handle)
def index_v3_show(content): content_url = content['links']['self'] name = content['name'] fanart = content['imageHref'] addDirectoryItem(plugin.handle, plugin.url_for(page_api_url, url=content_url), make_list_item(name, icon=fanart), True)
def appletv_featured(): et = util.get_url_as_xml_cache(get_url(APPLE_TV_FEATURED)) for showcase in et.findall('.//showcase/items/showcasePoster'): name = showcase.get('accessibilityLabel') image = showcase.find('./image').get('src') url = util.parse_url_from_method(showcase.get('onPlay')) addDirectoryItem(plugin.handle, plugin.url_for(appletv_showcase, url=url), make_list_item(name, image), True) collections = et.findall('.//collectionDivider') shelfs = et.findall('.//shelf') for i in range(0, len(collections)): collection_divider = collections[i] shelf = shelfs[i] title = collection_divider.find('title').text name = shelf.get('id') addDirectoryItem(plugin.handle, plugin.url_for(appletv_shelf, shelf_id=name), make_list_item(title), True) endOfDirectory(plugin.handle)
def appletv_channels(): et = util.get_url_as_xml_cache(get_url(APPLE_TV_CHANNELS)) for channel in et.findall('.//oneLineMenuItem'): name = channel.get('accessibilityLabel') image = channel.find('.//image').text url = util.parse_url_from_method(channel.get('onSelect')) addDirectoryItem(plugin.handle, plugin.url_for(appletv_showcase, url=url), make_list_item(name, image), True) setContent(plugin.handle, 'episodes') endOfDirectory(plugin.handle, updateListing=False)
def appletv_sports(): et = util.get_url_as_xml_cache(get_url(APPLE_TV_SPORTS)) images = et.findall('.//image') sports = et.findall('.//oneLineMenuItem') for i in range(0, min(len(images), len(sports))): sport = sports[i] image = images[i] name = sport.get('accessibilityLabel') image = image.text url = util.parse_url_from_method(sport.get('onSelect')) addDirectoryItem(plugin.handle, plugin.url_for(appletv_showcase, url=url), make_list_item(name, image), True) endOfDirectory(plugin.handle, updateListing=False)
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))
def legacy_root_menu(): include_premium = adobe_activate_api.is_authenticated() channel_list = events.get_channel_list(include_premium) curdate = datetime.utcnow() upcoming = get_setting_as_int('upcoming') + 1 days = (curdate + timedelta(days=upcoming)).strftime("%Y%m%d") # Live addDirectoryItem( plugin.handle, plugin.url_for(live_events_mode, espn_url=events.get_live_events_url(channel_list)), make_list_item(get_string(30029)), True) # Upcoming espn_url = events.get_upcoming_events_url(channel_list) + '&endDate=' + days \ + '&startDate=' + curdate.strftime("%Y%m%d") addDirectoryItem(plugin.handle, plugin.url_for(list_sports, espn_url=espn_url), make_list_item(get_string(30030)), True) enddate = '&endDate=' + (curdate + timedelta(days=1)).strftime("%Y%m%d") replays1 = [5, 10, 15, 20, 25] replays1 = replays1[get_setting_as_int('replays1')] start1 = (curdate - timedelta(days=replays1)).strftime("%Y%m%d") replays2 = [10, 20, 30, 40, 50] replays2 = replays2[get_setting_as_int('replays2')] start2 = (curdate - timedelta(days=replays2)).strftime("%Y%m%d") replays3 = [30, 60, 90, 120] replays3 = replays3[get_setting_as_int('replays3')] start3 = (curdate - timedelta(days=replays3)).strftime("%Y%m%d") replays4 = [60, 90, 120, 240] replays4 = replays4[get_setting_as_int('replays4')] start4 = (curdate - timedelta(days=replays4)).strftime("%Y%m%d") start_all = (curdate - timedelta(days=365)).strftime("%Y%m%d") addDirectoryItem( plugin.handle, plugin.url_for(list_sports, espn_url=events.get_replay_events_url(channel_list) + enddate + '&startDate=' + start1), make_list_item(get_string(30031) % replays1), True) addDirectoryItem( plugin.handle, plugin.url_for(list_sports, espn_url=events.get_replay_events_url(channel_list) + enddate + '&startDate=' + start2), make_list_item(get_string(30031) % replays2), True) addDirectoryItem( plugin.handle, plugin.url_for(list_sports, espn_url=events.get_replay_events_url(channel_list) + enddate + '&startDate=' + start3), make_list_item(get_string(30031) % replays3), True) addDirectoryItem( plugin.handle, plugin.url_for(list_sports, espn_url=events.get_replay_events_url(channel_list) + '&endDate=' + start3 + '&startDate=' + start4), make_list_item(get_string(30033) % (replays3, replays4)), True) addDirectoryItem( plugin.handle, plugin.url_for(list_sports, espn_url=events.get_replay_events_url(channel_list) + enddate + '&startDate=' + start_all), make_list_item(get_string(30032)), True) xbmcplugin.endOfDirectory(plugin.handle)
def index_legacy_live_events(espn_url, sport=None, network_id=None): chosen_sport = sport chosen_network = network_id live = 'action=live' in espn_url upcoming = 'action=upcoming' in espn_url replay = 'action=replay' in espn_url if live: data = events.get_events(espn_url) else: data = util.get_url_as_xml_cache( espn_url, encoding='ISO-8859-1').findall(".//event") num_espn3 = 0 num_secplus = 0 num_accextra = 0 num_events = 0 for event in data: sport = event.find('sportDisplayValue').text.encode('utf-8') if chosen_sport != sport and chosen_sport is not None: continue networkid = event.find('networkId').text if chosen_network != networkid and chosen_network is not None: continue if networkid == ESPN3_ID and chosen_network is None and live: num_espn3 += 1 elif networkid == SECPLUS_ID and chosen_network is None and live: num_secplus += 1 elif networkid == ACC_EXTRA_ID and chosen_network is None and live: num_accextra += 1 else: num_events += 1 _index_event(event, live, upcoming, replay, chosen_sport) # Don't show ESPN3 folder if there are no premium events if num_events == 0: for event in data: sport = event.find('sportDisplayValue').text.encode('utf-8') if chosen_sport != sport and chosen_sport is not None: continue _index_event(event, live, upcoming, replay, chosen_sport) # Dir for ESPN3/SECPlus/ACC Extra elif chosen_network is None: if num_espn3 > 0 and get_setting_as_bool('ShowEspn3'): translation_number = 30191 if num_espn3 == 1 else 30190 name = (get_string(translation_number) % num_espn3) addDirectoryItem( plugin.handle, plugin.url_for(live_network_events_mode, espn_url=espn_url, network_id=ESPN3_ID), make_list_item(name), True) if num_secplus > 0 and get_setting_as_bool('ShowSecPlus'): translation_number = 30201 if num_secplus == 1 else 30200 name = (get_string(translation_number) % num_secplus) addDirectoryItem( plugin.handle, plugin.url_for(live_network_events_mode, espn_url=espn_url, network_id=SECPLUS_ID), make_list_item(name), True) if num_accextra > 0 and get_setting_as_bool('ShowAccExtra'): translation_number = 30203 if num_accextra == 1 else 30202 name = (get_string(translation_number) % num_accextra) addDirectoryItem( plugin.handle, plugin.url_for(live_network_events_mode, espn_url=espn_url, network_id=ACC_EXTRA_ID), make_list_item(name), True)
def index_item(args): if args['type'] == 'over': return sport = args['sport'] ename = args['eventName'] sport2 = args['subcategory'] if 'subcategory' in args else sport if sport != sport2 and len(sport2) > 0: sport += ' (' + sport2 + ')' starttime = args['starttime'] if 'starttime' in args else None length = int(args['duration']) etime = time.time() if starttime is not None: now = time.time() etime = time.strftime("%I:%M %p", starttime) if 'replay' in args['type']: etime_local = starttime if etime_local.tm_hour == 0 and etime_local.tm_min == 0: etime = time.strftime("%m/%d/%Y", starttime) else: etime = time.strftime("%m/%d %I:%M %p", starttime) ename = etime + ' - ' + ename elif args['type'] == 'live': starttime_time = time.mktime(starttime) length -= (time.time() - starttime_time) ename += ' - ' + etime else: now_time = time.localtime(now) if now_time.tm_year == starttime.tm_year and \ now_time.tm_mon == starttime.tm_mon and \ now_time.tm_mday == starttime.tm_mday: etime = time.strftime("%I:%M %p", starttime) else: etime = time.strftime("%m/%d %I:%M %p", starttime) ename = etime + ' - ' + ename aired = time.strftime("%Y-%m-%d", starttime) else: aired = 0 network_id = args['networkId'] if 'networkId' in args else '' if 'networkName' in args: network = args['networkName'] else: network = network_id logging.debug('network_id ' + network_id) if network_id in NETWORK_ID_TO_NETWORK_NAME: network = get_string(NETWORK_ID_TO_NETWORK_NAME[network_id]) blackout = args['blackout'] if 'blackout' in args else False blackout_text = '' if blackout: blackout_text = get_string(30580) if len(blackout_text) > 0: ename = blackout_text + ' ' + ename if len(network) > 0: if get_setting_as_bool('NoColors'): ename = network + ' ' + ename else: ename = '[B]%s[/B] ' % (network) + ename description = args['description'] auth_types = get_auth_types_from_network(network_id) requires_auth = check_auth_types(auth_types) if requires_auth and not adobe_activate_api.is_authenticated(): ename = '*' + ename logging.debug('Duration %s' % length) mpaa = args['parentalRating'] if 'parentRating' in args else 'U' info_labels = { 'title': ename, 'genre': sport, 'duration': length, 'studio': network, 'mpaa': mpaa, 'plot': description, 'aired': aired, 'premiered': aired } fanart = args['imageHref'] if args['type'] == 'upcoming': addDirectoryItem( plugin.handle, plugin.url_for(upcoming_event, event_id=args['eventId'], starttime=etime, event_name=quote_plus(ename.encode('utf-8'))), make_list_item(ename, icon=fanart, info_labels=info_labels)) else: adobe_rss = args['adobeRSS'] if 'adobeRSS' in args else None guid = args['guid'] if 'guid' in args else None if adobe_rss is None and guid is None: addDirectoryItem( plugin.handle, plugin.url_for(play_item, url=args['sessionUrl'], event_id=args['eventId']), make_list_item(ename, icon=fanart, info_labels=info_labels)) else: if 'adobeRSS' in args: adobe_rss = args['adobeRSS'] else: adobe_rss = adobe_activate_api.get_resource( args['channelResourceId'], args['eventName'], args['guid'], mpaa) if include_item(network_id): logging.debug('Adding %s with handle %d and id %s' % (ename, plugin.handle, args['eventId'])) logging.debug(adobe_rss) addDirectoryItem( plugin.handle, plugin.url_for(play_tv, event_id=args['eventId'], session_url=args['sessionUrl'], network_name=args['networkId'], resource=quote_plus( adobe_rss.encode('utf-8'))), make_list_item(ename, icon=fanart, info_labels=info_labels)) else: logging.debug('Skipping %s' % args['networkId'])
def roku_url_mode(): url = arg_as_string('url') category_id = arg_as_string(ID) json_data = util.get_url_as_json_cache(get_url(url)) if 'listings' in json_data: json_data['listings'].sort(key=functools.cmp_to_key(compare_roku)) for listing in json_data['listings']: index_listing(listing) setContent(plugin.handle, 'episodes') if 'videos' in json_data: for video in json_data['videos']: index_video(video) setContent(plugin.handle, 'episodes') if 'categories' in json_data: for category in json_data['categories']: if category_id is None or category_id == '': if 'api' in category[ 'links'] and 'subcategories' not in category: addDirectoryItem( plugin.handle, plugin.url_for( roku_url_mode, url=category['links']['api']['video']['href']), make_list_item(category['name'], get_thumbnail(category)), True) elif 'subcategories' in category: # Collapse sub categories for subcategory in category['subcategories']: if 'api' in subcategory['links']: addDirectoryItem( plugin.handle, plugin.url_for(roku_url_mode, url=subcategory['links']['api'] ['video']['href']), make_list_item( category['name'] + ' - ' + subcategory['name'], get_thumbnail(category)), True) elif category_id == str(category['id']): if 'api' in category['links']: addDirectoryItem( plugin.handle, plugin.url_for( roku_url_mode, url=category['links']['api']['video']['href']), make_list_item(category['name'] + ' - Clips', get_thumbnail(category)), True) if 'subcategories' in category: for subcategory in category['subcategories']: if 'api' in subcategory['links']: addDirectoryItem( plugin.handle, plugin.url_for(roku_url_mode, url=subcategory['links']['api'] ['video']['href']), make_list_item(subcategory['name'], get_thumbnail(category)), True) if 'clients' in json_data: for client in json_data['clients']: for channel in client['channels']: addDirectoryItem( plugin.handle, plugin.url_for( roku_url_mode, url=channel['links']['api']['listings']['href']), make_list_item(channel['name'], get_thumbnail(channel)), True) endOfDirectory(plugin.handle)
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')