class Channels: """ Menu code related to channels """ 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_channels(self): """ Shows TV channels """ product = self._vtm_go.get_product() kids = (product == 'VTM_GO_KIDS') # Fetch EPG from API channel_infos = self._vtm_go.get_live_channels() listing = [] for i, key in enumerate(CHANNELS): # pylint: disable=unused-variable channel = CHANNELS[key] if kids and channel.get('kids') is False: continue # Find this channel in the list channel_info = next(c for c in channel_infos if c.key == key) # Lookup the high resolution logo based on the channel name icon = '{path}/resources/logos/{logo}-white.png'.format( path=self._kodi.get_addon_path(), logo=channel.get('logo')) fanart = '{path}/resources/logos/{logo}.png'.format( path=self._kodi.get_addon_path(), logo=channel.get('logo')) context_menu = [ ( self._kodi.localize( 30052, channel=channel.get('label')), # Watch live {channel} 'XBMC.PlayMedia(%s)' % self._kodi.url_for('play', category='channels', item=channel_info.channel_id)), ( self._kodi.localize(30053, channel=channel.get( 'label')), # TV Guide for {channel} 'XBMC.Container.Update(%s)' % self._kodi.url_for( 'show_tvguide_channel', channel=channel.get('epg'))) ] if self._kodi.get_setting_as_bool('metadata_update'): context_menu.append(( self._kodi.localize( 30055, channel=channel.get('label')), # Catalog for {channel} 'XBMC.Container.Update(%s)' % self._kodi.url_for('show_catalog_channel', channel=key))) title = channel.get('label') if channel_info and channel_info.epg: title += '[COLOR gray] | {title} ({start} - {end})[/COLOR]'.format( title=channel_info.epg[0].title, start=channel_info.epg[0].start.strftime('%H:%M'), end=channel_info.epg[0].end.strftime('%H:%M')) listing.append( TitleItem(title=title, path=self._kodi.url_for('show_channel_menu', channel=key), art_dict={ 'icon': icon, 'thumb': icon, 'fanart': fanart, }, info_dict={ 'plot': self._menu.format_plot(channel), 'playcount': 0, 'mediatype': 'video', 'studio': channel.get('studio_icon'), }, stream_dict={ 'codec': 'h264', 'height': 1080, 'width': 1920, }, context_menu=context_menu), ) self._kodi.show_listing(listing, 30007) def show_channel_menu(self, key): """ Shows a TV channel :type key: str """ channel = CHANNELS[key] # Fetch EPG from API channel_info = self._vtm_go.get_live_channel(key) title = self._kodi.localize( 30052, channel=channel.get('label')) # Watch live {channel} if channel_info.epg: title += '[COLOR gray] | {title} ({start} - {end})[/COLOR]'.format( title=channel_info.epg[0].title, start=channel_info.epg[0].start.strftime('%H:%M'), end=channel_info.epg[0].end.strftime('%H:%M')) # Lookup the high resolution logo based on the channel name icon = '{path}/resources/logos/{logo}-white.png'.format( path=self._kodi.get_addon_path(), logo=channel.get('logo')) fanart = '{path}/resources/logos/{logo}.png'.format( path=self._kodi.get_addon_path(), logo=channel.get('logo')) listing = [ TitleItem(title=title, path=self._kodi.url_for('play', category='channels', item=channel_info.channel_id) + '?.pvr', art_dict={ 'icon': icon, 'thumb': icon, 'fanart': fanart, }, info_dict={ 'plot': self._menu.format_plot(channel_info), 'playcount': 0, 'mediatype': 'video', }, stream_dict={ 'codec': 'h264', 'height': 1080, 'width': 1920, }, is_playable=True), TitleItem( title=self._kodi.localize( 30053, channel=channel.get('label')), # TV Guide for {channel} path=self._kodi.url_for('show_tvguide_channel', channel=channel.get('epg')), art_dict={'icon': 'DefaultAddonTvInfo.png'}, info_dict={ 'plot': self._kodi.localize(30054, channel=channel.get( 'label')), # Browse the TV Guide for {channel} }), ] if self._kodi.get_setting_as_bool('metadata_update'): listing.append( TitleItem( title=self._kodi.localize( 30055, channel=channel.get('label')), # Catalog for {channel} path=self._kodi.url_for('show_catalog_channel', channel=key), art_dict={'icon': 'DefaultMovieTitle.png'}, info_dict={ 'plot': self._kodi.localize(30056, channel=channel.get('label')), })) # Add YouTube channels if self._kodi.get_cond_visibility( 'System.HasAddon(plugin.video.youtube)') != 0: for youtube in channel.get('youtube', []): listing.append( TitleItem( title=self._kodi.localize( 30206, label=youtube.get( 'label')), # Watch {label} on YouTube path=youtube.get('path'), info_dict={ 'plot': self._kodi.localize( 30206, label=youtube.get( 'label')), # Watch {label} on YouTube })) self._kodi.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_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'])
class Channels: """ Menu code related to channels """ 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_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=self._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_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=self._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'])