def __init__(self, port): """ Initialise object :type port: int """ self._vtm_go = VtmGo() self._vtm_go_epg = VtmGoEpg() self.port = port
def __init__(self, kodi): """ Initialise object :type kodi: KodiWrapper """ self._kodi = kodi self._vtm_go_epg = VtmGoEpg(self._kodi) self._menu = Menu(self._kodi)
def __init__(self, kodi, port): """ Initialise object :type kodi: resources.lib.kodiwrapper.KodiWrapper """ self._kodi = kodi self._vtm_go = VtmGo(self._kodi) self._vtm_go_epg = VtmGoEpg(self._kodi) self.port = port
def play_epg_datetime(channel, timestamp): """ Play a program based on the channel and the timestamp when it was aired. """ _vtmGoEpg = VtmGoEpg(kodi) broadcast = _vtmGoEpg.get_broadcast(channel, timestamp) if not broadcast: kodi.show_ok_dialog( heading=kodi.localize(30711), message=kodi.localize( 30713)) # The requested video was not found in the guide. return play_epg(channel, broadcast.playable_type, broadcast.uuid)
def __init__(self, port): """ Initialise object :type port: int """ 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._vtm_go_epg = VtmGoEpg() self.port = port
def play_epg(channel, program_type, epg_id): """ Play a program based on the channel and information from the EPG. """ _vtmGoEpg = VtmGoEpg(kodi) details = _vtmGoEpg.get_details(channel=channel, program_type=program_type, epg_id=epg_id) if not details: kodi.show_ok_dialog( heading=kodi.localize(30711), message=kodi.localize( 30713)) # The requested video was not found in the guide. return play(details.playable_type, details.playable_uuid)
def show_tvguide_detail(channel=None, date=None): """ Shows the programs of a specific date in the tv guide """ try: _vtmGoEpg = VtmGoEpg(kodi) epg = _vtmGoEpg.get_epg(channel=channel, date=date) except Exception as ex: kodi.show_notification(message=str(ex)) raise listing = [] for broadcast in epg.broadcasts: 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) listing.append( TitleItem(title=title, path=routing.url_for( play_epg, channel=channel, program_type=broadcast.playable_type, epg_id=broadcast.uuid), art_dict={ 'icon': broadcast.image, 'thumb': broadcast.image, }, info_dict={ 'title': title, 'plot': broadcast.description, 'duration': broadcast.duration, 'mediatype': 'video', }, stream_dict={ 'duration': broadcast.duration, 'codec': 'h264', 'height': 1080, 'width': 1920, }, is_playable=True)) kodi.show_listing(listing, 30013, content='tvshows')
def show_tvguide_channel(channel): """ Shows the dates in the tv guide """ listing = [] for day in VtmGoEpg(kodi).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( TitleItem(title=title, path=routing.url_for(show_tvguide_detail, channel=channel, date=day.get('date')), art_dict={ 'icon': 'DefaultYear.png', 'thumb': 'DefaultYear.png', }, info_dict={ 'plot': None, })) kodi.show_listing(listing, 30013, content='files')
def __init__(self): """ Initialise object """ self._vtm_go_epg = VtmGoEpg()
class TvGuide: """ Menu code related to the TV Guide """ def __init__(self): """ Initialise object """ self._vtm_go_epg = VtmGoEpg() 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_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']) def play_epg_datetime(self, channel, timestamp): """ Play a program based on the channel and the timestamp when it was aired :type channel: str :type timestamp: str """ broadcast = self._vtm_go_epg.get_broadcast(channel, timestamp) if not broadcast: kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize(30713)) # The requested video was not found in the guide. kodiutils.end_of_directory() return kodiutils.redirect( kodiutils.url_for('play', category=broadcast.playable_type, item=broadcast.playable_uuid))
class TvGuide: """ Menu code related to the TV Guide """ EPG_NO_BROADCAST = 'Geen Uitzending' def __init__(self, kodi): """ Initialise object :type kodi: resources.lib.kodiwrapper.KodiWrapper """ self._kodi = kodi self._vtm_go_epg = VtmGoEpg(self._kodi) 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( TitleItem(title=title, path=self._kodi.url_for('show_tvguide_detail', channel=channel, date=day.get('key')), art_dict={ 'icon': 'DefaultYear.png', 'thumb': 'DefaultYear.png', }, info_dict={ 'plot': None, 'date': day.get('date'), })) self._kodi.show_listing(listing, 30013, content='files', sort=['date']) 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: self._kodi.show_notification(message=str(ex)) self._kodi.end_of_directory() return listing = [] for broadcast in epg.broadcasts: if broadcast.playable_type == 'episodes': context_menu = [( self._kodi.localize(30102), # Go to Program 'XBMC.Container.Update(%s)' % self._kodi.url_for('show_program_from_epg', channel=channel, program=broadcast.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) if broadcast.title == self.EPG_NO_BROADCAST: title = '[COLOR gray]' + title + '[/COLOR]' listing.append( TitleItem(title=title, path=self._kodi.url_for( 'play_epg_program', channel=channel, program_type=broadcast.playable_type, epg_id=broadcast.uuid, airing=epg.uuid if broadcast.airing else None), art_dict={ 'icon': broadcast.image, 'thumb': broadcast.image, }, info_dict={ 'title': title, 'plot': broadcast.description, 'duration': broadcast.duration, 'mediatype': 'video', }, stream_dict={ 'duration': broadcast.duration, 'codec': 'h264', 'height': 1080, 'width': 1920, }, context_menu=context_menu, is_playable=True)) self._kodi.show_listing(listing, 30013, content='episodes', sort=['unsorted']) def show_program_from_epg(self, channel, program): """ Show a program based on the channel and information from the EPG :type channel: str :type program: str """ details = self._vtm_go_epg.get_details(channel=channel, program_type='episodes', epg_id=program) if not details: self._kodi.show_ok_dialog( heading=self._kodi.localize(30711), message=self._kodi.localize( 30713)) # The requested video was not found in the guide. self._kodi.end_of_directory() return # Show the program with our freshly obtained program_uuid self._kodi.redirect( self._kodi.url_for('show_catalog_program', program=details.program_uuid).replace( 'plugin://plugin.video.vtm.go', '')) def play_epg_datetime(self, channel, timestamp): """ Play a program based on the channel and the timestamp when it was aired :type channel: str :type timestamp: str """ broadcast = self._vtm_go_epg.get_broadcast(channel, timestamp) if not broadcast: self._kodi.show_ok_dialog( heading=self._kodi.localize(30711), message=self._kodi.localize( 30713)) # The requested video was not found in the guide. self._kodi.end_of_directory() return self.play_epg_program(channel, broadcast.playable_type, broadcast.uuid) def play_epg_program(self, channel, program_type, epg_id, airing=None): """ Play a program based on the channel and information from the EPG :type channel: str :type program_type: str :type epg_id: str :type airing: str """ if airing: res = self._kodi.show_context_menu( [self._kodi.localize(30103), self._kodi.localize(30105)]) # Watch Live | Play from Catalog if res == -1: # user has cancelled return if res == 0: # user selected "Watch Live" self._kodi.redirect( self._kodi.url_for('play', category='channels', item=airing)) return details = self._vtm_go_epg.get_details(channel=channel, program_type=program_type, epg_id=epg_id) if not details: self._kodi.show_ok_dialog( heading=self._kodi.localize(30711), message=self._kodi.localize( 30713)) # The requested video was not found in the guide. self._kodi.end_of_directory() return # Play this program self._kodi.redirect( self._kodi.url_for('play', category=details.playable_type, item=details.playable_uuid))
class IPTVManager: """ Code related to the Kodi PVR integration """ def __init__(self, port): """ Initialise object :type port: int """ self._vtm_go = VtmGo() self._vtm_go_epg = VtmGoEpg() self.port = port def via_socket(func): # pylint: disable=no-self-argument """Send the output of the wrapped function to socket""" def send(self): """Decorator to send over a socket""" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('127.0.0.1', self.port)) try: sock.sendall(json.dumps(func(self)).encode()) # pylint: disable=not-callable finally: sock.close() return send @via_socket def send_channels(self): """ Report channel data """ # Fetch EPG from API channels = self._vtm_go.get_live_channels() results = [] for channel in channels: channel_data = CHANNELS.get(channel.key) if not channel_data: _LOGGER.warning( 'Skipping %s since we don\'t know this channel', channel.key) continue results.append( dict( name=channel_data.get('label') if channel_data else channel.name, id=channel_data.get('iptv_id'), preset=channel_data.get('iptv_preset'), logo= 'special://home/addons/{addon}/resources/logos/{logo}.png'. format(addon=kodiutils.addon_id(), logo=channel.key) if channel_data else channel.logo, stream=kodiutils.url_for('play', category='channels', item=channel.channel_id), vod=kodiutils.url_for('play_epg_datetime', channel=channel.key, timestamp='{date}'), )) return dict(version=1, streams=results) @via_socket def send_epg(self): """ Report EPG data """ results = dict() # Fetch EPG data for date in ['yesterday', 'today', 'tomorrow']: channels = self._vtm_go_epg.get_epgs(date) for channel in channels: # Lookup channel data in our own CHANNELS dict channel_data = next((c for c in CHANNELS.values() if c.get('epg') == channel.key), None) if not channel_data: _LOGGER.warning( 'Skipping EPG for %s since we don\'t know this channel', channel.key) continue key = channel_data.get('iptv_id') # Create channel in dict if it doesn't exists if key not in results.keys(): results[key] = [] results[key].extend([ dict( start=broadcast.time.isoformat(), stop=( broadcast.time + timedelta(seconds=broadcast.duration)).isoformat(), title=broadcast.title, description=broadcast.description, # subtitle=None, # Not available in the API # season=None, # Not available in the API # epsiode=None, # Not available in the API genre=broadcast.genre, image=broadcast.thumb, stream=kodiutils.url_for( 'play', category=broadcast.playable_type, item=broadcast.playable_uuid) if broadcast.playable_uuid else None) for broadcast in channel.broadcasts ]) return dict(version=1, epg=results)