def show_catalog(self): """ Show the catalog """ try: categories = self._vtm_go.get_categories() 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 cat in categories: listing.append( kodiutils.TitleItem( title=cat.title, path=kodiutils.url_for('show_catalog_category', category=cat.category_id), info_dict=dict( plot='[B]{category}[/B]'.format(category=cat.title), ), )) # Sort categories by default like in VTM GO. kodiutils.show_listing(listing, 30003, content='files')
def show_tvguide_channel(self, channel): """ Shows the dates in the tv guide :type channel: str """ listing = [] for day in self._vtm_go_epg.get_dates('%A %d %B %Y'): if day.get('highlight'): title = '[B]{title}[/B]'.format(title=day.get('title')) else: title = day.get('title') listing.append(kodiutils.TitleItem( title=title, path=kodiutils.url_for('show_tvguide_detail', channel=channel, date=day.get('key')), art_dict=dict( icon='DefaultYear.png', thumb='DefaultYear.png', ), info_dict=dict( plot=None, date=day.get('date'), ), )) kodiutils.show_listing(listing, 30013, content='files', sort=['date'])
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')
def show_program(self, program): """ Show a program from the catalog :type program: str """ try: program_obj = self._vtm_go.get_program( program, cache=CACHE_PREVENT ) # Use CACHE_PREVENT since we want fresh data except UnavailableException: kodiutils.ok_dialog( message=kodiutils.localize(30717) ) # This program is not available in the VTM GO catalogue. kodiutils.end_of_directory() return # Go directly to the season when we have only one season if len(program_obj.seasons) == 1: self.show_program_season( program, list(program_obj.seasons.values())[0].number) return studio = CHANNELS.get(program_obj.channel, {}).get('studio_icon') listing = [] # Add an '* All seasons' entry when configured in Kodi if kodiutils.get_global_setting('videolibrary.showallitems') is True: listing.append( kodiutils.TitleItem( title='* %s' % kodiutils.localize(30204), # * All seasons path=kodiutils.url_for('show_catalog_program_season', program=program, season=-1), art_dict=dict( thumb=program_obj.cover, fanart=program_obj.cover, ), info_dict=dict( tvshowtitle=program_obj.name, title=kodiutils.localize(30204), # All seasons tagline=program_obj.description, set=program_obj.name, studio=studio, mpaa=', '.join(program_obj.legal) if hasattr(program_obj, 'legal') and program_obj.legal else kodiutils.localize(30216), # All ages ), )) # Add the seasons for season in list(program_obj.seasons.values()): listing.append( kodiutils.TitleItem( title=kodiutils.localize( 30205, season=season.number), # Season {season} path=kodiutils.url_for('show_catalog_program_season', program=program, season=season.number), art_dict=dict( thumb=season.cover, fanart=program_obj.cover, ), info_dict=dict( tvshowtitle=program_obj.name, title=kodiutils.localize( 30205, season=season.number), # Season {season} tagline=program_obj.description, set=program_obj.name, studio=studio, mpaa=', '.join(program_obj.legal) if hasattr(program_obj, 'legal') and program_obj.legal else kodiutils.localize(30216), # All ages ), )) # Sort by label. Some programs return seasons unordered. kodiutils.show_listing(listing, 30003, content='tvshows', sort=['label'])
def select_profile(self, key=None): # pylint: disable=too-many-return-statements """ Show your profiles :type key: str """ try: profiles = self._auth.get_profiles() except InvalidLoginException: kodiutils.ok_dialog(message=kodiutils.localize( 30203)) # Your credentials are not valid! kodiutils.open_settings() return except InvalidTokenException: self._auth.logout() kodiutils.redirect(kodiutils.url_for('select_profile')) return except LoginErrorException as exc: kodiutils.ok_dialog(message=kodiutils.localize( 30702, code=exc.code)) # Unknown error while logging in: {code} kodiutils.open_settings() return except ApiUpdateRequired: kodiutils.ok_dialog(message=kodiutils.localize( 30705)) # The VTM GO Service has been updated... return except Exception as exc: # pylint: disable=broad-except kodiutils.ok_dialog(message="%s" % exc) return # Show warning when you have no profiles if not profiles: # Your account has no profiles defined. Please login on vtm.be/vtmgo and create a Profile. kodiutils.ok_dialog(message=kodiutils.localize(30703)) kodiutils.end_of_directory() return # Select the first profile when you only have one if len(profiles) == 1: key = profiles[0].key # Save the selected profile if key: profile = [x for x in profiles if x.key == key][0] _LOGGER.debug('Setting profile to %s', profile) kodiutils.set_setting('profile', '%s:%s' % (profile.key, profile.product)) kodiutils.set_setting('profile_name', profile.name) kodiutils.redirect(kodiutils.url_for('show_main_menu')) return # Show profile selection when you have multiple profiles listing = [ kodiutils.TitleItem( title=self._get_profile_name(p), path=kodiutils.url_for('select_profile', key=p.key), art_dict=dict(icon='DefaultUser.png'), info_dict=dict(plot=p.name, ), ) for p in profiles ] kodiutils.show_listing(listing, sort=['unsorted'], category=30057) # Select Profile
def show_channel_menu(self, key): """ Shows a TV channel :type key: str """ # Fetch EPG from API channel = self._vtm_go.get_live_channel(key) channel_data = CHANNELS.get(channel.key) icon = channel.logo fanart = channel.background title = channel.name if channel_data: icon = '{path}/resources/logos/{logo}-white.png'.format(path=kodiutils.addon_path(), logo=channel.key) title = channel_data.get('label') title = kodiutils.localize(30052, channel=title) # Watch live {channel} if channel.epg: label = title + '[COLOR gray] | {title} ({start} - {end})[/COLOR]'.format( title=channel.epg[0].title, start=channel.epg[0].start.strftime('%H:%M'), end=channel.epg[0].end.strftime('%H:%M')) else: label = title # The .pvr suffix triggers some code paths in Kodi to mark this as a live channel listing = [kodiutils.TitleItem( title=label, path=kodiutils.url_for('play', category='channels', item=channel.channel_id) + '?.pvr', art_dict=dict( icon=icon, thumb=icon, fanart=fanart, ), info_dict=dict( plot=Menu.format_plot(channel), playcount=0, mediatype='video', ), stream_dict=dict( codec='h264', height=1080, width=1920, ), is_playable=True, )] if channel_data and channel_data.get('epg'): listing.append( kodiutils.TitleItem( title=kodiutils.localize(30053, channel=channel_data.get('label')), # TV Guide for {channel} path=kodiutils.url_for('show_tvguide_channel', channel=channel_data.get('epg')), art_dict=dict( icon='DefaultAddonTvInfo.png', ), info_dict=dict( plot=kodiutils.localize(30054, channel=channel_data.get('label')), # Browse the TV Guide for {channel} ), ) ) listing.append(kodiutils.TitleItem( title=kodiutils.localize(30055, channel=channel_data.get('label')), # Catalog for {channel} path=kodiutils.url_for('show_catalog_channel', channel=key), art_dict=dict( icon='DefaultMovieTitle.png' ), info_dict=dict( plot=kodiutils.localize(30056, channel=channel_data.get('label')), # Browse the Catalog for {channel} ), )) # Add YouTube channels if channel_data and kodiutils.get_cond_visibility('System.HasAddon(plugin.video.youtube)') != 0: for youtube in channel_data.get('youtube', []): listing.append(kodiutils.TitleItem( title=kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube path=youtube.get('path'), info_dict=dict( plot=kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube ) )) kodiutils.show_listing(listing, 30007, sort=['unsorted'])
def show_channels(self): """ Shows TV channels """ # Fetch EPG from API channels = self._vtm_go.get_live_channels() listing = [] for channel in channels: channel_data = CHANNELS.get(channel.key) icon = channel.logo fanart = channel.background title = channel.name if channel_data: icon = '{path}/resources/logos/{logo}-white.png'.format(path=kodiutils.addon_path(), logo=channel.key) title = channel_data.get('label') context_menu = [( kodiutils.localize(30052, channel=title), # Watch live {channel} 'PlayMedia(%s)' % kodiutils.url_for('play', category='channels', item=channel.channel_id), )] if channel_data and channel_data.get('epg'): context_menu.append(( kodiutils.localize(30053, channel=title), # TV Guide for {channel} 'Container.Update(%s)' % kodiutils.url_for('show_tvguide_channel', channel=channel_data.get('epg')) )) context_menu.append(( kodiutils.localize(30055, channel=title), # Catalog for {channel} 'Container.Update(%s)' % kodiutils.url_for('show_catalog_channel', channel=channel.key) )) if channel.epg: label = title + '[COLOR gray] | {title} ({start} - {end})[/COLOR]'.format( title=channel.epg[0].title, start=channel.epg[0].start.strftime('%H:%M'), end=channel.epg[0].end.strftime('%H:%M')) else: label = title listing.append(kodiutils.TitleItem( title=label, path=kodiutils.url_for('show_channel_menu', channel=channel.key), art_dict=dict( icon=icon, thumb=icon, fanart=fanart, ), info_dict=dict( plot=Menu.format_plot(channel), playcount=0, mediatype='video', studio=channel_data.get('studio_icon') if channel_data else None, ), stream_dict=dict( codec='h264', height=1080, width=1920, ), context_menu=context_menu, )) kodiutils.show_listing(listing, 30007)
def show_mainmenu(self): """ Show the main menu """ listing = [] account = self._auth.login() listing.append( kodiutils.TitleItem( title=kodiutils.localize(30007), # TV Channels path=kodiutils.url_for('show_channels'), art_dict=dict( icon='DefaultAddonPVRClient.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30008), ), )) if account.product == 'VTM_GO': listing.append( kodiutils.TitleItem( title=kodiutils.localize(30015), # Recommendations path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_MAIN), art_dict=dict( icon='DefaultFavourites.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30016), ), )) listing.append( kodiutils.TitleItem( title=kodiutils.localize(30003), # Movies path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_MOVIES), art_dict=dict( icon='DefaultMovies.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30004), ), )) listing.append( kodiutils.TitleItem( title=kodiutils.localize(30005), # Series path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_SERIES), art_dict=dict( icon='DefaultTVShows.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30006), ), )) listing.append( kodiutils.TitleItem( title=kodiutils.localize(30021), # Kids path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_KIDS), art_dict=dict( icon='DefaultFavourites.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30022), ), )) elif account.product == 'VTM_GO_KIDS': listing.append( kodiutils.TitleItem( title=kodiutils.localize(30015), # Recommendations path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_KIDS_MAIN), art_dict=dict( icon='DefaultFavourites.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30016), ), )) listing.append( kodiutils.TitleItem( title=kodiutils.localize(30001), # A-Z path=kodiutils.url_for('show_catalog_all'), art_dict=dict( icon='DefaultMovieTitle.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30002), ), )) # listing.append(kodiutils.TitleItem( # title=kodiutils.localize(30003), # Catalogue # path=kodiutils.url_for('show_catalog'), # art_dict=dict( # icon='DefaultGenre.png', # fanart=kodiutils.get_addon_info('fanart'), # ), # info_dict=dict( # plot=kodiutils.localize(30004), # ), # )) if kodiutils.get_setting_bool( 'interface_show_mylist') and kodiutils.has_credentials(): listing.append( kodiutils.TitleItem( title=kodiutils.localize(30017), # My List path=kodiutils.url_for('show_mylist'), art_dict=dict( icon='DefaultPlaylist.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30018), ), )) if kodiutils.get_setting_bool('interface_show_continuewatching' ) and kodiutils.has_credentials(): listing.append( kodiutils.TitleItem( title=kodiutils.localize(30019), # Continue watching path=kodiutils.url_for('show_continuewatching'), art_dict=dict( icon='DefaultInProgressShows.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30020), ), )) listing.append( kodiutils.TitleItem( title=kodiutils.localize(30009), # Search path=kodiutils.url_for('show_search'), art_dict=dict( icon='DefaultAddonsSearch.png', fanart=kodiutils.get_addon_info('fanart'), ), info_dict=dict(plot=kodiutils.localize(30010), ), )) kodiutils.show_listing(listing, sort=['unsorted'])
def generate_titleitem(cls, item, progress=False): """ Generate a TitleItem based on a Movie, Program or Episode. :type item: Union[Movie, Program, Episode] :type progress: bool :rtype TitleItem """ art_dict = { 'thumb': item.cover, 'cover': item.cover, } info_dict = { 'title': item.name, 'plot': cls.format_plot(item), 'studio': CHANNELS.get(item.channel, {}).get('studio_icon'), 'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else kodiutils.localize(30216), # All ages } prop_dict = {} # # Movie # if isinstance(item, Movie): if item.my_list: context_menu = [( kodiutils.localize(30101), # Remove from My List 'Container.Update(%s)' % kodiutils.url_for('mylist_del', video_type=CONTENT_TYPE_MOVIE, content_id=item.movie_id))] else: context_menu = [( kodiutils.localize(30100), # Add to My List 'Container.Update(%s)' % kodiutils.url_for('mylist_add', video_type=CONTENT_TYPE_MOVIE, content_id=item.movie_id))] art_dict.update({ 'fanart': item.image, }) info_dict.update({ 'mediatype': 'movie', 'duration': item.duration, 'year': item.year, 'aired': item.aired, }) stream_dict = { 'codec': 'h264', 'duration': item.duration, 'height': 1080, 'width': 1920, } return kodiutils.TitleItem( title=item.name, path=kodiutils.url_for('play', category='movies', item=item.movie_id), art_dict=art_dict, info_dict=info_dict, stream_dict=stream_dict, prop_dict=prop_dict, context_menu=context_menu, is_playable=True, ) # # Program # if isinstance(item, Program): if item.my_list: context_menu = [( kodiutils.localize(30101), # Remove from My List 'Container.Update(%s)' % kodiutils.url_for('mylist_del', video_type=CONTENT_TYPE_PROGRAM, content_id=item.program_id))] else: context_menu = [( kodiutils.localize(30100), # Add to My List 'Container.Update(%s)' % kodiutils.url_for('mylist_add', video_type=CONTENT_TYPE_PROGRAM, content_id=item.program_id))] art_dict.update({ 'fanart': item.image, }) info_dict.update({ 'mediatype': 'tvshow', 'season': len(item.seasons), }) prop_dict.update({ 'hash': item.content_hash, }) return kodiutils.TitleItem( title=item.name, path=kodiutils.url_for('show_catalog_program', program=item.program_id), art_dict=art_dict, info_dict=info_dict, prop_dict=prop_dict, context_menu=context_menu, ) # # Episode # if isinstance(item, Episode): context_menu = [] if item.program_id: context_menu = [( kodiutils.localize(30102), # Go to Program 'Container.Update(%s)' % kodiutils.url_for( 'show_catalog_program', program=item.program_id))] art_dict.update({ 'fanart': item.cover, }) info_dict.update({ 'mediatype': 'episode', 'tvshowtitle': item.program_name, 'duration': item.duration, 'season': item.season, 'episode': item.number, 'set': item.program_name, 'aired': item.aired, }) if progress and item.watched: info_dict.update({ 'playcount': 1, }) stream_dict = { 'codec': 'h264', 'duration': item.duration, 'height': 1080, 'width': 1920, } # Add progress info if progress and not item.watched and item.progress: prop_dict.update({ 'ResumeTime': item.progress, 'TotalTime': item.progress + 1, }) return kodiutils.TitleItem( title=info_dict['title'], path=kodiutils.url_for('play', category='episodes', item=item.episode_id), art_dict=art_dict, info_dict=info_dict, stream_dict=stream_dict, prop_dict=prop_dict, context_menu=context_menu, is_playable=True, ) raise Exception('Unknown video_type')
def show_tvguide_detail(self, channel=None, date=None): """ Shows the programs of a specific date in the tv guide :type channel: str :type date: str """ try: epg = self._vtm_go_epg.get_epg(channel=channel, date=date) except UnavailableException as ex: kodiutils.notification(message=str(ex)) kodiutils.end_of_directory() return listing = [] for broadcast in epg.broadcasts: if broadcast.playable_type == 'episodes': context_menu = [( kodiutils.localize(30102), # Go to Program 'Container.Update(%s)' % kodiutils.url_for('show_catalog_program', channel=channel, program=broadcast.program_uuid) )] else: context_menu = None title = '{time} - {title}{live}'.format( time=broadcast.time.strftime('%H:%M'), title=broadcast.title, live=' [I](LIVE)[/I]' if broadcast.live else '' ) if broadcast.airing: title = '[B]{title}[/B]'.format(title=title) path = kodiutils.url_for('play_or_live', channel=broadcast.channel_uuid, category=broadcast.playable_type, item=broadcast.playable_uuid) else: path = kodiutils.url_for('play', category=broadcast.playable_type, item=broadcast.playable_uuid) listing.append(kodiutils.TitleItem( title=title, path=path, art_dict=dict( thumb=broadcast.thumb, ), info_dict=dict( title=title, plot=broadcast.description, duration=broadcast.duration, mediatype='video', ), stream_dict=dict( duration=broadcast.duration, codec='h264', height=1080, width=1920, ), context_menu=context_menu, is_playable=True, )) kodiutils.show_listing(listing, 30013, content='episodes', sort=['unsorted'])