def show_recommendations(self, storefront): """ Show the recommendations. :type storefront: str """ results = self._api.get_storefront(storefront) show_unavailable = kodiutils.get_setting_bool( 'interface_show_unavailable') listing = [] for item in results: if isinstance(item, Category): listing.append( TitleItem( title=item.title, path=kodiutils.url_for('show_recommendations_category', storefront=storefront, category=item.category_id), info_dict=dict(plot='[B]{category}[/B]'.format( category=item.title), ), )) else: if show_unavailable or item.available: listing.append(Menu.generate_titleitem(item)) if storefront == STOREFRONT_SERIES: label = 30005 # Series elif storefront == STOREFRONT_MOVIES: label = 30003 # Movies else: label = 30015 # Recommendations kodiutils.show_listing(listing, label, content='files')
class Search: """ Menu code related to search """ def __init__(self): """ Initialise object """ self._search = SearchApi() self._menu = Menu() def show_search(self, query=None): """ Shows the search dialog :type query: str """ if not query: # Ask for query query = kodiutils.get_search_string( heading=kodiutils.localize(30009)) # Search if not query: kodiutils.end_of_directory() return # Do search try: items = self._search.search(query) except Exception as ex: # pylint: disable=broad-except kodiutils.notification(message=str(ex)) kodiutils.end_of_directory() return # Display results listing = [self._menu.generate_titleitem(item) for item in items] # Sort like we get our results back. kodiutils.show_listing(listing, 30009, content='tvshows')
def show_recommendations_category(self, storefront, category): """ Show the items in a recommendations category. :type storefront: str :type category: str """ try: result = self._vtm_go.get_storefront_category(storefront, category) except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as ex: # pylint: disable=broad-except _LOGGER.error("%s", ex) kodiutils.ok_dialog(message="%s" % ex) return listing = [] for item in result.content: listing.append(Menu.generate_titleitem(item)) if storefront == STOREFRONT_SERIES: content = 'tvshows' elif storefront == STOREFRONT_MOVIES: content = 'movies' else: content = 'tvshows' # Fallback to a list of tvshows kodiutils.show_listing(listing, result.title, content=content, sort=['unsorted', 'label', 'year', 'duration'])
def show_program_season(self, program_id, season_uuid): """ Show the episodes of a program from the catalog :type program_id: str :type season_uuid: str """ try: program = self._api.get_program(program_id) except UnavailableException: kodiutils.ok_dialog(message=kodiutils.localize( 30717)) # This program is not available in the catalogue. kodiutils.end_of_directory() return if season_uuid == "-1": # Show all episodes episodes = program.episodes else: # Show the episodes of the season that was selected episodes = [ e for e in program.episodes if e.season_uuid == season_uuid ] listing = [Menu.generate_titleitem(episode) for episode in episodes] # Sort by episode number by default. Takes seasons into account. kodiutils.show_listing(listing, 30003, content='episodes', sort=['episode', 'duration'])
def show_continuewatching(self): """ Show the items in "Continue Watching" """ try: category = self._vtm_go.get_storefront_category( STOREFRONT_MAIN, 'continue-watching') except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as ex: # pylint: disable=broad-except _LOGGER.error("%s", ex) kodiutils.ok_dialog(message="%s" % ex) return listing = [] for item in category.content: titleitem = Menu.generate_titleitem(item, progress=True) # Add Program Name to title since this list contains episodes from multiple programs title = '%s - %s' % (titleitem.info_dict.get('tvshowtitle'), titleitem.info_dict.get('title')) titleitem.info_dict['title'] = title listing.append(titleitem) # Sort categories by default like in VTM GO. kodiutils.show_listing(listing, 30019, content='episodes', sort='label')
def show_catalog_category(self, category=None): """ Show a category in the catalog :type category: str """ try: items = self._vtm_go.get_items(category) except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as ex: # pylint: disable=broad-except _LOGGER.error("%s", ex) kodiutils.ok_dialog(message="%s" % ex) return listing = [] for item in items: listing.append(Menu.generate_titleitem(item)) # Sort items by label, but don't put folders at the top. # Used for A-Z listing or when movies and episodes are mixed. kodiutils.show_listing(listing, 30003, content='files', sort=['label', 'year', 'duration'])
def show_category(self, uuid): """ Shows a category """ programs = self._api.get_category_content(int(uuid)) listing = [Menu.generate_titleitem(program) for program in programs] kodiutils.show_listing(listing, 30003, content='tvshows')
def show_library_movies(self, movie=None): """ Return a list of the movies that should be exported. """ if movie is None: if kodiutils.get_setting_int( 'library_movies') == LIBRARY_FULL_CATALOG: # Full catalog # Use cache if available, fetch from api otherwise so we get rich metadata for new content items = self._api.get_items(content_filter=Movie, cache=CACHE_AUTO) else: # Only favourites, use cache if available, fetch from api otherwise items = self._api.get_mylist(content_filter=Movie) else: items = [self._api.get_movie(movie)] listing = [] for item in items: title_item = Menu.generate_titleitem(item) # title_item.path = kodiutils.url_for('library_movies', movie=item.movie_id) # We need a trailing / title_item.path = 'plugin://plugin.video.vtm.go/library/movies/?movie=%s' % item.movie_id listing.append(title_item) kodiutils.show_listing(listing, 30003, content='movies', sort=['label', 'year', 'duration'])
def show_search(self, query=None): """ Shows the search dialog. :type query: str """ if not query: # Ask for query query = kodiutils.get_search_string( heading=kodiutils.localize(30009)) # Search Streamz if not query: kodiutils.end_of_directory() return # Do search try: items = self._api.do_search(query) except Exception as ex: # pylint: disable=broad-except kodiutils.notification(message=str(ex)) kodiutils.end_of_directory() return # Display results show_unavailable = kodiutils.get_setting_bool( 'interface_show_unavailable') listing = [] for item in items: if show_unavailable or item.available: listing.append(Menu.generate_titleitem(item)) # Sort like we get our results back. kodiutils.show_listing(listing, 30009, content='tvshows')
def play_asset(self, asset_id): """ Play an asset (can be a program of a live channel). :param string asset_id: The ID of the asset to play. """ # Get asset info asset = self._channel_api.get_asset(asset_id) item = Menu.generate_titleitem(asset) # Get stream info try: stream_info = self._channel_api.get_stream(asset_id) except NotAvailableInOfferException as exc: _LOGGER.error(exc) kodiutils.ok_dialog(message=kodiutils.localize(30712)) return license_key = self._create_license_key( stream_info.drm_license_url, key_headers={'Content-Type': 'application/octet-stream'}) _LOGGER.debug('Starting playing %s with license key %s', stream_info.url, license_key) kodiutils.play(stream_info.url, license_key, item.title, item.art_dict, item.info_dict, item.prop_dict)
def show_library_tvshows(self, program=None): """ Return a list of the series that should be exported. """ if program is None: if kodiutils.get_setting_int( 'library_tvshows') == LIBRARY_FULL_CATALOG: # Full catalog # Use cache if available, fetch from api otherwise so we get rich metadata for new content # NOTE: We should probably use CACHE_PREVENT here, so we can pick up new episodes, but we can't since that would # require a massive amount of API calls for each update. We do this only for programs in 'My list'. items = self._api.get_items(content_filter=Program, cache=CACHE_AUTO) else: # Only favourites, don't use cache, fetch from api # If we use CACHE_AUTO, we will miss updates until the user manually opens the program in the Add-on items = self._api.get_mylist(content_filter=Program, cache=CACHE_PREVENT) else: # Fetch only a single program items = [self._api.get_program(program, cache=CACHE_PREVENT)] listing = [] for item in items: title_item = Menu.generate_titleitem(item) # title_item.path = kodiutils.url_for('library_tvshows', program=item.program_id) # We need a trailing / title_item.path = 'plugin://plugin.video.vtm.go/library/tvshows/?program={program_id}'.format( program_id=item.program_id) listing.append(title_item) kodiutils.show_listing(listing, 30003, content='tvshows', sort=['label', 'year', 'duration'])
def show_program_season(self, program, season): """ Show the episodes of a program from the catalog :type program: str :type season: int """ try: program_obj = self._vtm_go.get_program( program ) # Use CACHE_AUTO since the data is just refreshed in show_program except UnavailableException: kodiutils.ok_dialog( message=kodiutils.localize(30717) ) # This program is not available in the VTM GO catalogue. kodiutils.end_of_directory() return if season == -1: # Show all seasons seasons = list(program_obj.seasons.values()) else: # Show the season that was selected seasons = [program_obj.seasons[season]] listing = [ Menu.generate_titleitem(e) for s in seasons for e in list(s.episodes.values()) ] # Sort by episode number by default. Takes seasons into account. kodiutils.show_listing(listing, program_obj.name, content='episodes', sort=['episode', 'duration'])
def show_recommendations_category(self, storefront, category): """ Show the items in a recommendations category. :type storefront: str :type category: str """ result = self._api.get_storefront_category(storefront, category) show_unavailable = kodiutils.get_setting_bool( 'interface_show_unavailable') listing = [] for item in result.content: if show_unavailable or item.available: listing.append(Menu.generate_titleitem(item)) if storefront == STOREFRONT_SERIES: content = 'tvshows' elif storefront == STOREFRONT_MOVIES: content = 'movies' else: content = 'tvshows' # Fallback to a list of tvshows kodiutils.show_listing(listing, result.title, content=content, sort=['unsorted', 'label', 'year', 'duration'])
def show_mylist(self): """ Show the items in "My List". """ mylist = self._api.get_swimlane('my-list') listing = [] for item in mylist: item.my_list = True listing.append(Menu.generate_titleitem(item)) # Sort categories by default like in Streamz. kodiutils.show_listing(listing, 30017, content='tvshows', sort=['unsorted', 'label', 'year', 'duration'])
def show_catalog(self): """ Show all the programs of all channels """ try: items = self._api.get_programs() except Exception as ex: kodiutils.notification(message=str(ex)) raise listing = [Menu.generate_titleitem(item) for item in items] # Sort items by title # Used for A-Z listing or when movies and episodes are mixed. kodiutils.show_listing(listing, 30003, content='tvshows', sort='title')
def show_recommendations_category(self, uuid): """ Shows the a category of the recommendations """ if uuid == 'meest-bekeken': programs = self._api.get_popular_programs() episodes = [] else: recommendations = self._api.get_recommendation_categories() category = next(category for category in recommendations if category.uuid == uuid) programs = category.programs episodes = category.episodes listing = [] for episode in episodes: title_item = Menu.generate_titleitem(episode) title_item.info_dict[ 'title'] = episode.program_title + ' - ' + title_item.title listing.append(title_item) for program in programs: listing.append(Menu.generate_titleitem(program)) kodiutils.show_listing(listing, 30005, content='tvshows')
def show_catalog_category(self, category=None): """ Show a category in the catalog. :type category: str """ items = self._api.get_items(category) listing = [] for item in items: listing.append(Menu.generate_titleitem(item)) # Sort items by label, but don't put folders at the top. # Used for A-Z listing or when movies and episodes are mixed. kodiutils.show_listing(listing, 30003, content='movies' if category == 'films' else 'tvshows', sort=['label', 'year', 'duration'])
def show_library_tvshows_program(self, program): """ Return a list of the episodes that should be exported. """ program_obj = self._api.get_program(program) listing = [] for season in list(program_obj.seasons.values()): for item in list(season.episodes.values()): title_item = Menu.generate_titleitem(item) # title_item.path = kodiutils.url_for('library_tvshows', program=item.program_id, episode=item.episode_id) title_item.path = 'plugin://plugin.video.streamz/library/tvshows/?program={program_id}&episode={episode_id}'.format(program_id=item.program_id, episode_id=item.episode_id) listing.append(title_item) # Sort by episode number by default. Takes seasons into account. kodiutils.show_listing(listing, 30003, content='episodes', sort=['episode', 'duration'])
def play_from_page(self, path): """ Play the requested item. :type path: string """ if not path: kodiutils.ok_dialog(message=kodiutils.localize(30712)) # The video is unavailable... return # Get episode information episode = self._api.get_episode(path, cache=CACHE_PREVENT) resolved_stream = None if episode is None: kodiutils.ok_dialog(message=kodiutils.localize(30712)) return if episode.stream: # We already have a resolved stream. Nice! # We don't need credentials for these streams. resolved_stream = ResolvedStream( uuid=episode.uuid, url=episode.stream, ) _LOGGER.debug('Already got a resolved stream: %s', resolved_stream) if episode.uuid: # Lookup the stream resolved_stream = self._resolve_stream(episode.uuid) _LOGGER.debug('Resolved stream: %s', resolved_stream) if resolved_stream: titleitem = Menu.generate_titleitem(episode) if resolved_stream.license_url: # Generate license key license_key = self.create_license_key(resolved_stream.license_url, key_headers=dict( customdata=resolved_stream.auth, )) else: license_key = None kodiutils.play(resolved_stream.url, resolved_stream.stream_type, license_key, info_dict=titleitem.info_dict, art_dict=titleitem.art_dict, prop_dict=titleitem.prop_dict)
def show_continuewatching(self): """ Show the items in "Continue Watching". """ mylist = self._api.get_swimlane('continue-watching') listing = [] for item in mylist: titleitem = Menu.generate_titleitem(item, progress=True) # Add Program Name to title since this list contains episodes from multiple programs title = '%s - %s' % ( titleitem.info_dict.get('tvshowtitle'), titleitem.info_dict.get('title')) titleitem.info_dict['title'] = title listing.append(titleitem) # Sort categories by default like in Streamz. kodiutils.show_listing(listing, 30019, content='episodes', sort='label')
def show_program_clips(self, channel, program_id): """ Show the clips of a program from the catalog :type channel: str :type program_id: str """ try: # We need to query the backend, since we don't cache clips. program = self._api.get_program(channel, program_id, extract_clips=True, cache=CACHE_PREVENT) except UnavailableException: kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue. kodiutils.end_of_directory() return listing = [Menu.generate_titleitem(episode) for episode in program.clips] # Sort like we get our results back. kodiutils.show_listing(listing, 30003, content='episodes')
def show_catalog_channel(self, channel): """ Show the programs of a specific channel :type channel: str """ try: items = self._api.get_programs(channel) except Exception as ex: kodiutils.notification(message=str(ex)) raise listing = [] for item in items: listing.append(Menu.generate_titleitem(item)) # Sort items by title # Used for A-Z listing or when movies and episodes are mixed. kodiutils.show_listing(listing, 30003, content='tvshows', sort='title')
def show_recommendations_category(self, storefront, category): """ Show the items in a recommendations category :type storefront: str :type category: str """ recommendations = self._api.get_recommendations(storefront) listing = [] for cat in recommendations: # Only show the requested category if cat.category_id != category: continue for item in cat.content: listing.append(Menu.generate_titleitem(item)) # Sort categories by default like in Streamz. kodiutils.show_listing(listing, 30015, content='tvshows')
def show_search(self, query=None): """ Shows the search dialog :type query: str """ if not query: # Ask for query query = kodiutils.get_search_string(heading=kodiutils.localize(30009)) # Search if not query: kodiutils.end_of_directory() return # Do search items = self._search_api.search(query) # Display results listing = [Menu.generate_titleitem(item) for item in items] # Sort like we get our results back. kodiutils.show_listing(listing, 30009, content='episodes')
def show_continuewatching(self): """ Show the items in "Continue Watching". """ category = self._api.get_storefront_category( STOREFRONT_MAIN, STOREFRONT_PAGE_CONTINUE_WATCHING) listing = [] for item in category.content: titleitem = Menu.generate_titleitem(item, progress=True) # Add Program Name to title since this list contains episodes from multiple programs title = '%s - %s' % (titleitem.info_dict.get('tvshowtitle'), titleitem.info_dict.get('title')) titleitem.info_dict['title'] = title listing.append(titleitem) # Sort categories by default like in Streamz. kodiutils.show_listing(listing, 30019, content='episodes', sort='label')
def show_mylist(self): """ Show all the programs of all channels """ try: mylist, _ = self._auth.get_dataset('myList', 'myList') except Exception as ex: kodiutils.notification(message=str(ex)) raise items = [] if mylist: for item in mylist: program = self._api.get_program_by_uuid(item.get('id')) if program: program.my_list = True items.append(program) listing = [Menu.generate_titleitem(item) for item in items] # Sort items by title # Used for A-Z listing or when movies and episodes are mixed. kodiutils.show_listing(listing, 30011, content='tvshows', sort='title')
def show_recommendations(self, storefront): """ Show the recommendations. :type storefront: str """ try: results = self._vtm_go.get_storefront(storefront) except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as ex: # pylint: disable=broad-except _LOGGER.error("%s", ex) kodiutils.ok_dialog(message="%s" % ex) return listing = [] for item in results: if isinstance(item, Category): listing.append( kodiutils.TitleItem( title=item.title, path=kodiutils.url_for('show_recommendations_category', storefront=storefront, category=item.category_id), info_dict=dict(plot='[B]{category}[/B]'.format( category=item.title), ), )) else: listing.append(Menu.generate_titleitem(item)) if storefront == STOREFRONT_SERIES: label = 30005 # Series elif storefront == STOREFRONT_MOVIES: label = 30003 # Movies else: label = 30015 # Recommendations kodiutils.show_listing(listing, label, content='files')
class Search: """ Menu code related to search """ def __init__(self): """ Initialise object """ self._auth = VtmGoAuth(kodiutils.get_setting('username'), kodiutils.get_setting('password'), 'VTM', kodiutils.get_setting('profile'), kodiutils.get_tokens_path()) self._vtm_go = VtmGo(self._auth) self._menu = Menu() def show_search(self, query=None): """ Shows the search dialog :type query: str """ if not query: # Ask for query query = kodiutils.get_search_string( heading=kodiutils.localize(30009)) # Search VTM GO if not query: kodiutils.end_of_directory() return # Do search try: items = self._vtm_go.do_search(query) except Exception as ex: # pylint: disable=broad-except kodiutils.notification(message=str(ex)) kodiutils.end_of_directory() return # Display results listing = [] for item in items: listing.append(self._menu.generate_titleitem(item)) # Sort like we get our results back. kodiutils.show_listing(listing, 30009, content='tvshows')
def show_mylist(self): """ Show the items in "My List" """ try: mylist = self._vtm_go.get_mylist() except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as ex: # pylint: disable=broad-except _LOGGER.error("%s", ex) kodiutils.ok_dialog(message="%s" % ex) return listing = [] for item in mylist: item.my_list = True listing.append(Menu.generate_titleitem(item)) kodiutils.show_listing(listing, 30017, content='files', sort=['unsorted', 'label', 'year', 'duration'])
class Search: """ Menu code related to search """ def __init__(self, kodi): """ Initialise object :type kodi: resources.lib.kodiwrapper.KodiWrapper """ self._kodi = kodi self._vtm_go = VtmGo(self._kodi) self._menu = Menu(self._kodi) def show_search(self, query=None): """ Shows the search dialog :type query: str """ if not query: # Ask for query query = self._kodi.get_search_string(heading=self._kodi.localize(30009)) # Search VTM GO if not query: self._kodi.end_of_directory() return # Do search try: items = self._vtm_go.do_search(query) except Exception as ex: # pylint: disable=broad-except self._kodi.show_notification(message=str(ex)) self._kodi.end_of_directory() return # Display results listing = [] for item in items: listing.append(self._menu.generate_titleitem(item)) # Sort like we get our results back. self._kodi.show_listing(listing, 30009, content='tvshows')