def __init__(self, addon_id, channels_uri, epg_uri): self.addon_id = addon_id self.channels_uri = channels_uri self.epg_uri = epg_uri addon = kodiutils.get_addon(addon_id) self.addon_path = kodiutils.addon_path(addon)
def show_channels(): """ Shows TV channels """ listing = [] for i, key in enumerate(CHANNELS): # pylint: disable=unused-variable channel = CHANNELS[key] # Lookup the high resolution logo based on the channel name icon = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel.get('logo')) fanart = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel.get('background')) context_menu = [ ( kodiutils.localize(30053, channel=channel.get('name')), # TV Guide for {channel} 'Container.Update(%s)' % kodiutils.url_for('show_tvguide_channel', channel=channel.get('epg')) ) ] listing.append( TitleItem( title=channel.get('name'), path=kodiutils.url_for('show_channel_menu', channel=key), art_dict={ 'icon': icon, 'thumb': icon, 'fanart': fanart, }, info_dict={ 'plot': None, 'playcount': 0, 'mediatype': 'video', 'studio': channel.get('studio_icon'), }, stream_dict=STREAM_DICT, context_menu=context_menu ), ) kodiutils.show_listing(listing, 30007)
def show_channel_menu(key): """ Shows a TV channel :type key: str """ channel = CHANNELS[key] # Lookup the high resolution logo based on the channel name fanart = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel.get('background')) listing = [ TitleItem( title=kodiutils.localize(30053, channel=channel.get('name')), # TV Guide for {channel} path=kodiutils.url_for('show_tvguide_channel', channel=key), art_dict={ 'icon': 'DefaultAddonTvInfo.png', 'fanart': fanart, }, info_dict={ 'plot': kodiutils.localize(30054, channel=channel.get('name')), # Browse the TV Guide for {channel} } ), TitleItem( title=kodiutils.localize(30055, channel=channel.get('name')), # Catalog for {channel} path=kodiutils.url_for('show_catalog_channel', channel=key), art_dict={ 'icon': 'DefaultMovieTitle.png', 'fanart': fanart, }, info_dict={ 'plot': kodiutils.localize(30056, channel=channel.get('name')), # Browse the Catalog for {channel} } ) ] # Add YouTube channels if kodiutils.get_cond_visibility('System.HasAddon(plugin.video.youtube)') != 0: for youtube in channel.get('youtube', []): listing.append( TitleItem( title=kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube path=youtube.get('path'), info_dict={ 'plot': kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube } ) ) kodiutils.show_listing(listing, 30007, sort=['unsorted'])
def get_iptv_addons(): """ Find add-ons that provide IPTV channel data """ result = kodiutils.jsonrpc(method="Addons.GetAddons", params={ 'installed': True, 'enabled': True, 'type': 'xbmc.python.pluginsource' }) addons = [] for row in result['result']['addons']: addon = kodiutils.get_addon(row['addonid']) addon_path = kodiutils.addon_path(addon) addon_iptv_config = os.path.join(addon_path, IPTV_FILENAME) # Check if this addon has an iptv.json if not os.path.exists(addon_iptv_config): continue # Read iptv.json with open(addon_iptv_config) as fdesc: data = json.load(fdesc) # Check version if data.get('version', 1) > IPTV_VERSION: _LOGGER.warning( 'Skipping %s since it uses an unsupported version of iptv.json: %d', row['addonid'], data.get('version')) continue if not data.get('channels'): _LOGGER.warning('Skipping %s since it has no channels defined', row['addonid']) continue addons.append( Addon( addon_id=row['addonid'], channels_uri=data.get('channels'), epg_uri=data.get('epg'), )) return addons
def _get_data_from_addon(self, uri): """ Request data from the specified URI """ if uri.startswith('plugin://'): # Plugin path # Make request _, temp_file = tempfile.mkstemp() uri = uri.replace('$FILE', temp_file) kodiutils.execute_builtin('RunPlugin', uri) # Wait for data self._wait_for_data(temp_file, 30) # Load data _LOGGER.info('Loading reply from %s', temp_file) with open(temp_file) as fdesc: data = json.load(fdesc) # Remove temp file os.unlink(temp_file) return data if uri.startswith('http://') or uri.startswith('https://'): # HTTP(S) path # TODO: implement requests to fetch data return None # Local path addon = kodiutils.get_addon(self.addon_id) addon_path = kodiutils.addon_path(addon) filename = os.path.join(addon_path, uri) if not os.path.exists(filename): raise Exception('File %s does not exist' % filename) # Read file _LOGGER.info('Loading fixed reply from %s', filename) with open(filename) as fdesc: data = json.load(fdesc) return data
def _get_data_from_addon(self, uri): """ Request data from the specified URI """ # Plugin path if uri.startswith('plugin://'): # Prepare data sock = self._prepare_for_data() uri = update_qs(uri, port=sock.getsockname()[1]) _LOGGER.info('Executing RunPlugin(%s)...', uri) kodiutils.execute_builtin('RunPlugin', uri) # Wait for data result = self._wait_for_data(sock) # Load data data = json.loads(result) return data # HTTP(S) path if uri.startswith(('http://', 'https://')): # TODO: implement requests to fetch data return None # Local path addon = kodiutils.get_addon(self.addon_id) addon_path = kodiutils.addon_path(addon) filename = os.path.join(addon_path, uri) if not os.path.exists(filename): raise Exception('File %s does not exist' % filename) # Read file _LOGGER.info('Loading fixed reply from %s', filename) with open(filename) as fdesc: data = json.load(fdesc) return data
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)