def list_trakt_tvshows(results, pages, page): genres_dict = dict([(x['slug'], x['name']) for x in Trakt.get_genres('shows')]) try: shows = [ meta_info.get_tvshow_metadata_trakt(item['show'], genres_dict) for item in results ] except KeyError: shows = [ meta_info.get_tvshow_metadata_trakt(item, genres_dict) for item in results ] items = [make_tvshow_item(show) for show in shows if show.get('tvdb_id')] page = int(page) pages = int(pages) if pages > 1: args = nav_base.caller_args() args['page'] = page + 1 args['confirm'] = 'yes' items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (page + 1, pages + 1), 'path': plugin.url_for(nav_base.caller_name(), **args), 'thumbnail': plugin.get_media_icon('item_next'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORT)
def tv_trakt_popular(page, raw=False): results, pages = Trakt.get_popular_shows_paginated(page) if raw: return results else: genres_dict = dict([(x['slug'], x['name']) for x in Trakt.get_genres('shows')]) shows = [ meta_info.get_tvshow_metadata_trakt(item, genres_dict) for item in results ] items = [ make_tvshow_item(show) for show in shows if show.get('tvdb_id') ] page = int(page) pages = int(pages) if pages > 1: items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (page + 1, pages + 1), 'path': plugin.url_for('tv_trakt_popular', page=page + 1), 'thumbnail': plugin.get_media_icon('item_next'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORT)
def list_trakt_movies(results, pages=1, page=1): genres_dict = dict([(x['slug'], x['name']) for x in Trakt.get_genres('movies')]) try: movies = [ meta_info.get_trakt_movie_metadata(item['movie'], genres_dict) for item in results ] except KeyError: movies = [ meta_info.get_trakt_movie_metadata(item, genres_dict) for item in results ] items = [make_movie_item(movie) for movie in movies] page = int(page) pages = int(pages) if pages > 1: args = nav_base.caller_args() args['page'] = page + 1 args['confirm'] = 'yes' items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (page, pages + 1), 'path': plugin.url_for(nav_base.caller_name(), **args), 'thumbnail': plugin.get_media_icon('item_next'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORTRAKT)
def lists_trakt_liked_tv_lists(page): lists, pages = Trakt.get_liked_lists(page) items = [] for list in lists: info = list['list'] name = info['name'] user = info['user']['username'] slug = info['ids']['slug'] items.append({ 'label': name, 'path': plugin.url_for('lists_trakt_show_tv_list', user=user, slug=slug), 'thumbnail': plugin.get_media_icon('traktlikedlists'), 'fanart': plugin.get_addon_fanart() }) nextpage = int(page) + 1 if pages > page: items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (nextpage, pages), 'path': plugin.url_for('lists_trakt_liked_tv_lists', page=int(page) + 1), 'thumbnail': plugin.get_media_icon('item_next'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORT)
def list_tmdb_movies(result): genres_dict = nav_base.get_base_genres() movies = [ meta_info.get_movie_metadata(item, genres_dict) for item in result['results'] ] items = [make_movie_item(movie) for movie in movies] if 'page' in result: page = int(result['page']) pages = int(result['total_pages']) args = nav_base.caller_args() if pages > page: args['page'] = page + 1 args['confirm'] = 'yes' items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (page, pages + 1), 'path': plugin.url_for(nav_base.caller_name(), **args), 'thumbnail': plugin.get_media_icon('item_next'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORT)
def tmdb_movies_genres(): genres = nav_base.get_base_genres() items = sorted([ { 'label': name, 'path': plugin.url_for('tmdb_movies_genre', id=id, page=1), 'thumbnail': nav_base.get_genre_icon(id), 'fanart': plugin.get_addon_fanart(), 'context_menu': [ ('Play (random)', 'RunPlugin(%s)' % plugin.url_for('tmdb_movies_play_random_genre', id = id))] } for id, name in genres.items()], key=lambda k: k['label']) return plugin.finish(items=items, sort_methods=SORT)
def lists_search_for_lists_term(term, page): lists, pages = Trakt.search_for_list(term, page) items = [] for list in lists: if 'list' in list: list_info = list['list'] else: continue name = list_info['name'] user = list_info['username'] slug = list_info['ids']['slug'] total = list_info['item_count'] info = {} info['title'] = name if 'description' in list_info: info['plot'] = list_info['description'] else: info['plot'] = 'No description available' if user != None and total != None and total != 0: items.append({ 'label': '%s - %s (%s)' % (text.to_utf8(name), text.to_utf8(user), total), 'path': plugin.url_for('lists_trakt_show_list', user=user, slug=slug), 'thumbnail': plugin.get_media_icon('traktlikedlists'), 'context_menu': [('Play (random)', 'RunPlugin(%s)' % plugin.url_for( 'lists_trakt_play_random', user=user, slug=slug))], 'info': info }) for item in items: item['properties'] = { 'fanart_image': plugin.get_addon_fanart() } nextpage = int(page) + 1 if pages > page: items.append({ 'label': '%s/%s [I]Next page[/I] >>' % (nextpage, pages), 'path': plugin.url_for('lists_search_for_lists_term', term=term, page=int(page) + 1), 'thumbnail': plugin.get_media_icon('item_next'), 'properties': { 'fanart_image': plugin.get_addon_fanart() } }) return plugin.finish(items=items, sort_methods=SORT)
def lists_trakt_my_movie_lists(): lists = Trakt.get_lists() items = [] for list in lists: name = list['name'] user = list['user']['username'] slug = list['ids']['slug'] items.append( { 'label': name, 'path': plugin.url_for('lists_trakt_show_movie_list', user=user, slug=slug), 'thumbnail': plugin.get_media_icon('traktmylists'), 'fanart': plugin.get_addon_fanart() }) return plugin.finish(items=items, sort_methods=SORT)
def tv_tvshow(id): flatten = plugin.get_setting('flatten.tvshows', int) if flatten == 2: plugin.set_content('episodes') action = 'all' elif flatten == 1: id = int(id) show = TVDB[id] if len(show.items()) == 1 or (len(show.items()) == 2 and show.items()[1][0] == 1): plugin.set_content('episodes') action = 'one' else: plugin.set_content('seasons') action = 'none' else: plugin.set_content('seasons') action = 'none' return plugin.finish(items=list_seasons_tvdb(id, action), sort_methods=SORT)
def list_trakt_episodes(result): genres_dict = dict([(x['slug'], x['name']) for x in Trakt.get_genres('shows')]) items = [] for item in result: if 'episode' in item: episode = item['episode'] else: episode = item if 'show' in item: show = item['show'] try: show_id = item['show']['ids']['tvdb'] except: show_id = item['ids'].get('tvdb') try: id = episode['show']['ids']['tvdb'] except: id = episode['ids'].get('tvdb') if not id: continue try: season_num = episode['season'] except: season_num = episode.get('season') try: episode_num = episode['number'] except: episode_num = episode.get('number') if show: tvshow_title = show.get('title').encode('utf-8') else: try: tvshow_title = (episode['show']['title']).encode('utf-8') except: tvshow_title = str(episode.get('title')).encode('utf-8') if episode['title'] != None: try: episode_title = episode['title'].encode('utf-8') except: episode_title = episode.get('title').encode('utf-8') else: episode_title = 'TBA' info = meta_info.get_tvshow_metadata_trakt(item['show'], genres_dict) episode_info = meta_info.get_episode_metadata_trakt(info, episode) episode_info['title'] = '%s (%02dx%02d): %s' % ( tvshow_title, season_num, episode_num, episode_title) context_menu = [] showdata = TVDB[int(show_id)] # extradata = play_tvshows.get_episode_parameters(showdata, season_num, episode_num) properties = {} try: if traktenabled and countenabled: playdata = get_show_play_count(info['trakt_id']) season_index = nav_base.get_play_count_info( playdata, season_num) properties = { 'TotalSeasons': len(playdata['seasons']), 'TotalEpisodes': playdata['seasons'][season_index]['aired'], # 'WatchedEpisodes': playdata['seasons'][season_index]['completed'], # 'UnWatchedEpisodes': playdata['seasons'][season_index]['aired'] - playdata['seasons'][season_index]['completed'] } episode_info.update({ 'playcount': nav_base.get_play_count_info(playdata, season_num, episode_num) }) except: pass episodeitem = { 'label': episode_info['title'], 'path': plugin.url_for('tv_play', id=id, season=season_num, episode=episode_num, usedefault=True), 'context_menu': context_menu, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'stream_info': { 'video': {} }, 'properties': properties, 'thumbnail': episode_info['fanart'], 'poster': episode_info['poster'], 'fanart': episode_info['fanart'] } if enablefanart: try: art = get_fanarttv_art(info['tvdb_id'], query='episode', season=season_num) art = checkart(art) episodeitem.update(art) except: pass items.append(episodeitem) return plugin.finish(items=items, sort_methods=SORTRAKT, cache_to_disc=False)
def tv_season(id, season_num): plugin.set_content('episodes') return plugin.finish(items=list_episodes_tvdb(id, season_num), sort_methods=SORT)
def list_trakt_episodes(result): genres_dict = dict([(x['slug'], x['name']) for x in Trakt.get_genres('shows')]) items = [] for item in result: if 'episode' in item: episode = item['episode'] else: episode = item if 'show' in item: show = item['show'] try: id = episode['show']['ids']['tvdb'] except: id = episode['ids'].get('tvdb') if not id: continue try: season_num = episode['season'] except: season_num = episode.get('season') try: episode_num = episode['number'] except: episode_num = episode.get('number') if show: tvshow_title = show.get('title').encode('utf-8') else: try: tvshow_title = (episode['show']['title']).encode('utf-8') except: tvshow_title = str(episode.get('title')).encode('utf-8') if episode['title'] != None: try: episode_title = episode['title'].encode('utf-8') except: episode_title = episode.get('title').encode('utf-8') else: episode_title = 'TBA' info = meta_info.get_tvshow_metadata_trakt(item['show'], genres_dict) episode_info = meta_info.get_episode_metadata_trakt(info, episode) episode_info['title'] = '%s (%02dx%02d): %s' % ( tvshow_title, season_num, episode_num, episode_title) if xbmc.getCondVisibility('system.hasaddon(script.extendedinfo)'): context_menu = [( 'OpenInfo', 'RunScript(script.extendedinfo,info=extendedepisodeinfo,tvshow=%s,season=%s,episode=%s)' % (tvshow_title, season_num, episode_num))] else: context_menu = [] items.append({ 'label': episode_info['title'], 'path': plugin.url_for('tv_play', id=id, season=season_num, episode=episode_num), 'context_menu': context_menu, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'stream_info': { 'video': {} }, 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': episode_info['fanart'] }) return plugin.finish(items=items, sort_methods=SORTRAKT, cache_to_disc=False)
def tv_tvshow(id): plugin.set_content('seasons') return plugin.finish(items=list_seasons_tvdb(id), sort_methods=SORT)