def list_episodes(network, slug, page=1): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setContent(HANDLE, 'songs') xbmcplugin.setPluginCategory(HANDLE, aa.name) per_page = ADDON.getSettingInt('aa.shows_per_page') items = [] for ep in aa.get_show_episodes(slug, page, per_page): tracks = ep.get('tracks', []) if not tracks: continue item = utils.build_track_item(tracks[0]) item = utils.add_aa_art(item, ep.get('show')) items.append((item.getPath(), item, False)) if len(items) >= per_page: items.append(( utils.build_path('episodes', network, slug, page=page + 1), xbmcgui.ListItem(utils.translate(30318)), True, )) utils.list_items(items)
def list_network(network): items = [] aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) xbmcplugin.setContent(HANDLE, 'files') # Channels items.append((utils.build_path('channels', network), xbmcgui.ListItem(utils.translate(30321)), True)) # Shows if aa.network['has_shows']: items.append((utils.build_path('shows', network), xbmcgui.ListItem(utils.translate(30322)), True)) items.append((utils.build_path('shows', network, 'schedule'), xbmcgui.ListItem(utils.translate(30332)), True)) # Playlists if aa.network['has_playlists']: items.append((utils.build_path('playlists', network), xbmcgui.ListItem(utils.translate(30338)), True)) # Search items.append((utils.build_path('search', network), xbmcgui.ListItem(utils.translate(30323)), True)) utils.list_items(items)
def list_shows_schedule(network, page=1): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) shows = aa.get_upcoming() shows = sorted(shows, key=lambda s: s['start_at']) # Shows for "get_upcoming" have "following" always set to False # Have to work around this for now :/ followed_shows = aa.get_shows_followed() followed_slugs = [s.get('slug') for s in followed_shows] now = addict.datetime_now() active = utils.get_playing() or {} utils.log('active item', active) items = [] for show in shows: end_at = addict.parse_datetime(show.get('end_at')) if end_at < now: continue start_at = addict.parse_datetime(show.get('start_at')) show = show.get('show', {}) channel = show.get('channels', [])[0] item = utils.build_show_item(network, show, followed_slugs) item.setPath( utils.build_path('play', 'channel', network, channel.get('key'), live=show.get('now_playing', False))) if show.get('now_playing', False): label_prefix = utils.translate(30333) # Live now item.setProperty('IsPlayable', 'false') if (active.get('is_live', False) and active.get('channel') == channel.get('key')): item.select(True) else: label_prefix = '{} - {}'.format(start_at.strftime('%H:%M'), end_at.strftime('%H:%M')) item.setLabel('[B]{}[/B] - {} [I]({})[/I]'.format( label_prefix, _enc(show.get('name')), _enc(channel.get('name')))) items.append((item.getPath(), item, False)) utils.list_items(items)
def list_listen_history(network, channel): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) xbmcplugin.setContent(HANDLE, 'songs') items = [] for track in aa.get_listen_history(channel): item = utils.build_track_item(track.get('track')) item.setProperty('IsPlayable', 'false') item.setPath(None) items.append((None, item, False)) utils.list_items(items)
def search(network, filter_=None, query=None, page=1): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) per_page = ADDON.getSettingInt('aa.shows_per_page') if not query: k = xbmc.Keyboard(heading=utils.translate(30323)) k.doModal() if not k.isConfirmed(): return False query = k.getText() if not aa.network['has_shows']: filter_ = 'channels' items = [] if not filter_: # Channels items.append((utils.build_path('search', network, 'channels', query), xbmcgui.ListItem(utils.translate(30321)), True)) # Shows items.append((utils.build_path('search', network, 'shows', query), xbmcgui.ListItem(utils.translate(30322)), True)) else: if filter_ == 'channels': channels = aa.search_channels(query, page=page) if channels: items = list_channels(network, channels=channels, do_list=False) elif filter_ == 'shows': for show in aa.search_shows(query, page).get('results', []): item = utils.build_show_item(network, show) items.append((item.getPath(), item, True)) if filter_ and len(items) >= per_page: items.append(( utils.build_path('search', network, query, filter_, page=page + 1), xbmcgui.ListItem(utils.translate(30318)), True, )) utils.list_items(items)
def list_networks(): items = [] for key, data in addict.NETWORKS.items(): item = xbmcgui.ListItem(data['name']) item.setArt({ 'thumb': os.path.join(ADDON_DIR, 'resources', 'assets', key + '.png'), }) item.addContextMenuItems([ (utils.translate(30307), 'RunPlugin({})'.format( utils.build_path('refresh', key))), ], True) items.append((utils.build_path('networks', key), item, True)) utils.list_items(items)
def list_shows_styles(network, field): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) facets = aa.get_show_facets() facets = sorted(facets, key=lambda f: f['name']) items = [] for facet in facets: if facet.get('field') != field: continue item_url = utils.build_path('shows', network, 'facets', facet.get('name')) items.append( (item_url, xbmcgui.ListItem(_enc(facet.get('label'))), True)) utils.list_items(items)
def list_playlist_menu(network): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) items = [] # Popular Playlists items.append((utils.build_path('playlists', network, 'popular'), xbmcgui.ListItem(utils.translate(30339)), True)) # Newest Playlists items.append((utils.build_path('playlists', network, 'newest'), xbmcgui.ListItem(utils.translate(30340)), True)) # Followed Playlists items.append((utils.build_path('playlists', network, 'followed'), xbmcgui.ListItem(utils.translate(30341)), True)) utils.list_items(items)
def list_shows(network, facet='All', page=1): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) per_page = ADDON.getSettingInt('aa.shows_per_page') shows = aa.get_shows(facet, page=page, per_page=per_page) items = [] for show in shows: item = utils.build_show_item(network, show) items.append((item.getPath(), item, True)) if len(items) >= per_page: items.append(( utils.build_path('shows', network, 'followed', page=page + 1), xbmcgui.ListItem(utils.translate(30318)), True, )) utils.list_items(items)
def list_styles(network): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) xbmcplugin.setContent(HANDLE, 'albums') items = [] filters = aa.get_channel_filters() favorites = aa.get_favorite_channels() if favorites: filters.insert( 0, { 'key': 'favorites', 'name': utils.translate(30308), 'channels': favorites, }) for style in filters: item = xbmcgui.ListItem('{} ({})'.format( _enc(style.get('name')), len(style.get('channels', [])))) items.append((utils.build_path('channels', network, style.get('key')), item, True)) utils.list_items(items)
def list_playlists(network, sort, page=1): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setContent(HANDLE, 'songs') xbmcplugin.setPluginCategory(HANDLE, aa.name) # ToDo shows/playlists per page per_page = ADDON.getSettingInt('aa.shows_per_page') if sort == 'popular': callback = aa.get_playlists_popular elif sort == 'newest': callback = aa.get_playlists_newest elif sort == 'followed': callback = aa.get_playlists_followed else: return playlists = callback(page=page, per_page=per_page).get('results', []) items = [] active = utils.get_playing() or {} for pl in playlists: item = utils.build_playlist_item(network, pl) items.append((item.getPath(), item, False)) if active.get('playlist_id') == pl.get('id'): item.select(True) if len(items) >= per_page: items.append(( utils.build_path('playlists', network, sort, page=page + 1), xbmcgui.ListItem(utils.translate(30318)), True, )) utils.list_items(items)
def list_shows_menu(network): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) items = [] # Followed Shows items.append((utils.build_path('shows', network, 'followed'), xbmcgui.ListItem(utils.translate(30324)), True)) # By Style items.append((utils.build_path('shows', network, 'fields', 'channel_filter_name'), xbmcgui.ListItem(utils.translate(30325)), True)) # By Channel items.append((utils.build_path('shows', network, 'fields', 'channel_name'), xbmcgui.ListItem(utils.translate(30316)), True)) # Schedule items.append((utils.build_path('shows', network, 'schedule'), xbmcgui.ListItem(utils.translate(30332)), True)) utils.list_items(items)
def list_channels(network, style=None, channels=None, do_list=True): aa = addict.AudioAddict.get(PROFILE_DIR, network) xbmcplugin.setPluginCategory(HANDLE, aa.name) xbmcplugin.setContent(HANDLE, 'songs') items = [] if not channels: if style == 'favorites': channels = aa.get_favorite_channels() else: channels = aa.get_channels(style) favorites = [f['channel_id'] for f in aa.get_favorites()] # If I ever manage to get label2 to show, that's what we're going to # put there... # playing = { # p['channel_id']: '{} - {}'.format(_enc(p['track']['display_artist']), # _enc(p['track']['display_title'])) # for p in aa.get_currently_playing() # } active = utils.get_playing() or {} for channel in channels: item_url = utils.build_path('play', 'channel', network, channel.get('key')) item = xbmcgui.ListItem(_enc(channel.get('name'))) item.setPath(item_url) # item.setLabel2(playing[channel.get('id')]) item.setProperty('IsPlayable', 'false') item = utils.add_aa_art(item, channel, 'default', 'compact') if active.get('channel') == channel.get('key'): item.select(True) cmenu = [] if channel.get('id') not in favorites: # Add to favorites cmenu.append((utils.translate(30326), 'RunPlugin({})'.format( utils.build_path('favorite', network, channel.get('key'), channel_name=_enc(channel.get('name')))))) else: # Remove from favorites cmenu.append((utils.translate(30327), 'RunPlugin({})'.format( utils.build_path('unfavorite', network, channel.get('key'), channel_name=_enc(channel.get('name')))))) cmenu.append( (utils.translate(30330), 'Container.Update({}, return)'.format( utils.build_path('listen_history', network, channel.get('key'))))) item.addContextMenuItems(cmenu, True) items.append((item_url, item, False)) if not do_list: return items utils.list_items(items)