def show_channels_menu(self, channel=None):
     """The VRT NU add-on 'Channels' listing menu"""
     if channel:
         from tvguide import TVGuide
         self._favorites.refresh(ttl=ttl('indirect'))
         self._resumepoints.refresh(ttl=ttl('indirect'))
         channel_items = self._apihelper.list_channels(channels=[channel])  # Live TV
         channel_items.extend(TVGuide().get_channel_items(channel=channel))  # TV guide
         channel_items.extend(self._apihelper.list_youtube(channels=[channel]))  # YouTube
         channel_items.extend(self._apihelper.list_tvshows(channel=channel))  # TV shows
         from data import CHANNELS
         channel_name = find_entry(CHANNELS, 'name', channel).get('label')
         show_listing(channel_items, category=channel_name, sort='unsorted', content='tvshows', cache=False)  # Channel
     else:
         channel_items = self._apihelper.list_channels(live=False)
         show_listing(channel_items, category=30016, cache=False)
    def list_channels(self, channels=None, live=True):
        ''' Construct a list of channel ListItems, either for Live TV or the TV Guide listing '''
        from tvguide import TVGuide
        _tvguide = TVGuide()

        channel_items = []
        for channel in CHANNELS:
            if channels and channel.get('name') not in channels:
                continue

            context_menu = []
            art_dict = dict()

            # Try to use the white icons for thumbnails (used for icons as well)
            if has_addon('resource.images.studios.white'):
                art_dict['thumb'] = 'resource://resource.images.studios.white/{studio}.png'.format(**channel)
            else:
                art_dict['thumb'] = 'DefaultTags.png'

            if not live:
                path = url_for('channels', channel=channel.get('name'))
                label = channel.get('label')
                plot = '[B]%s[/B]' % channel.get('label')
                is_playable = False
                info_dict = dict(title=label, plot=plot, studio=channel.get('studio'), mediatype='video')
                stream_dict = []
            elif channel.get('live_stream') or channel.get('live_stream_id'):
                if channel.get('live_stream_id'):
                    path = url_for('play_id', video_id=channel.get('live_stream_id'))
                elif channel.get('live_stream'):
                    path = url_for('play_url', video_url=channel.get('live_stream'))
                label = localize(30141, **channel)  # Channel live
                playing_now = _tvguide.playing_now(channel.get('name'))
                if playing_now:
                    label += ' [COLOR yellow]| %s[/COLOR]' % playing_now
                # A single Live channel means it is the entry for channel's TV Show listing, so make it stand out
                if channels and len(channels) == 1:
                    label = '[B]%s[/B]' % label
                is_playable = True
                if channel.get('name') in ['een', 'canvas', 'ketnet']:
                    if get_setting('showfanart', 'true') == 'true':
                        art_dict['fanart'] = self.get_live_screenshot(channel.get('name', art_dict.get('fanart')))
                    plot = '%s\n\n%s' % (localize(30142, **channel), _tvguide.live_description(channel.get('name')))
                else:
                    plot = localize(30142, **channel)  # Watch live
                # NOTE: Playcount is required to not have live streams as "Watched"
                info_dict = dict(title=label, plot=plot, studio=channel.get('studio'), mediatype='video', playcount=0, duration=0)
                stream_dict = dict(duration=0)
                context_menu.append((
                    localize(30413),
                    'RunPlugin(%s)' % url_for('delete_cache', cache_file='channel.%s.json' % channel)
                ))
            else:
                # Not a playable channel
                continue

            channel_items.append(TitleItem(
                title=label,
                path=path,
                art_dict=art_dict,
                info_dict=info_dict,
                stream_dict=stream_dict,
                context_menu=context_menu,
                is_playable=is_playable,
            ))

        return channel_items
Esempio n. 3
0
 def send_epg():  # pylint: disable=no-method-argument
     """Return JSONTV formatted information to IPTV Manager"""
     from tvguide import TVGuide
     epg_data = TVGuide().get_epg_data()
     return dict(version=1, epg=epg_data)
Esempio n. 4
0
def tvguide_channel(channel=None, date=None):
    ''' The TV guide menu and listings by channel '''
    from tvguide import TVGuide
    TVGuide().show_tvguide(channel=channel, date=date)
Esempio n. 5
0
def tvguide(date=None, channel=None):
    ''' The TV guide menu and listings by date '''
    from tvguide import TVGuide
    TVGuide().show_tvguide(date=date, channel=channel)
Esempio n. 6
0
class TestTVGuide(unittest.TestCase):

    _tvguide = TVGuide()

    def test_tvguide_date_menu(self):
        ''' Test TV guide main menu '''
        date_items = self._tvguide.get_date_items()
        self.assertEqual(len(date_items), 37)
        date_item = random.choice(date_items)
        print('- %s%s' %
              (kodi_to_ansi(date_item.title), uri_to_path(date_item.path)))
        date_items = self._tvguide.get_date_items('today')
        self.assertEqual(len(date_items), 37)
        date_item = random.choice(date_items)
        print('- %s%s' %
              (kodi_to_ansi(date_item.title), uri_to_path(date_item.path)))

    def test_tvguide_channel_menu(self):
        ''' Test channel menu '''
        channel_items = self._tvguide.get_channel_items(channel='een')
        self.assertTrue(channel_items)
        channel_item = random.choice(channel_items)
        print(
            '- %s%s' %
            (kodi_to_ansi(channel_item.title), uri_to_path(channel_item.path)))

        date = (datetime.now(dateutil.tz.tzlocal()) +
                timedelta(days=-10)).strftime('%Y-%m-%d')
        channel_items = self._tvguide.get_channel_items(date=date)
        self.assertTrue(channel_items)
        channel_item = random.choice(channel_items)
        print(
            '- %s%s' %
            (kodi_to_ansi(channel_item.title), uri_to_path(channel_item.path)))

    def test_tvguide_episode_menu(self):
        ''' Test episode menu '''
        date = (datetime.now(dateutil.tz.tzlocal()) +
                timedelta(days=-10)).strftime('%Y-%m-%d')
        channel = random.choice(channels)
        episode_items = self._tvguide.get_episode_items(date, channel)
        self.assertTrue(episode_items)

    def test_tvguide_invalid_episode_menu(self):
        ''' Test episode menu '''
        date = (datetime.now(dateutil.tz.tzlocal()) +
                timedelta(days=-40)).strftime('%Y-%m-%d')
        channel = random.choice(channels)
        episode_items = self._tvguide.get_episode_items(date, channel)
        self.assertEqual(episode_items, [])

    def test_livetv_description(self):
        description = self._tvguide.live_description('een')
        print(kodi_to_ansi(description))
        description = self._tvguide.live_description('canvas')
        print(kodi_to_ansi(description))
        description = self._tvguide.live_description('ketnet')
        print(kodi_to_ansi(description))

    def test_tvguide_all(self):
        ''' Test episode menu '''
        episode_items = self._tvguide.get_episode_items('yesterday', 'een')
        self.assertTrue(episode_items)
        episode_items = self._tvguide.get_episode_items('today', 'canvas')
        self.assertTrue(episode_items)
        episode_items = self._tvguide.get_episode_items('tomorrow', 'ketnet')
        self.assertTrue(episode_items)

    def test_parse(self):
        now = datetime.now(dateutil.tz.tzlocal())
        date = self._tvguide.parse('2019-05-11', now)
        print(date)