Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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:
            self._kodi.show_ok_dialog(message=self._kodi.localize(30717))  # This program is not available in the VTM GO catalogue.
            self._kodi.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 self._kodi.get_global_setting('videolibrary.showallitems') is True:
            listing.append(TitleItem(
                title='* %s' % self._kodi.localize(30204),  # * All seasons
                path=self._kodi.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=self._kodi.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 self._kodi.localize(30216),  # All ages
                ),
            ))

        # Add the seasons
        for season in list(program_obj.seasons.values()):
            listing.append(TitleItem(
                title=self._kodi.localize(30205, season=season.number),  # Season {season}
                path=self._kodi.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=self._kodi.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 self._kodi.localize(30216),  # All ages
                ),
            ))

        # Sort by label. Some programs return seasons unordered.
        self._kodi.show_listing(listing, 30003, content='tvshows', sort=['label'])
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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,
                        image=broadcast.image)
                    for broadcast in channel.broadcasts
                ])

        return dict(version=1, epg=results)
Exemplo n.º 5
0
    def show_program(self, program):
        """ Show a program from the catalog
        :type program: str
         """
        try:
            program_obj = self._vtm_go.get_program(program)
        except UnavailableException:
            self._kodi.show_ok_dialog(
                message=self._kodi.localize(30717)
            )  # This program is not available in the VTM GO catalogue.
            self._kodi.end_of_directory()
            return

        studio = CHANNELS.get(program_obj.channel, {}).get('studio_icon')

        listing = []

        # Add an '* All seasons' entry when configured in Kodi
        if self._kodi.get_global_setting('videolibrary.showallitems') is True:
            listing.append(
                TitleItem(
                    title='* %s' % self._kodi.localize(30204),  # * All seasons
                    path=self._kodi.url_for('show_catalog_program_season',
                                            program=program,
                                            season=-1),
                    art_dict={
                        'thumb': program_obj.cover,
                        'fanart': program_obj.cover,
                    },
                    info_dict={
                        'tvshowtitle':
                        program_obj.name,
                        'title':
                        self._kodi.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 self._kodi.localize(30216),
                    }))

        # Add the seasons
        for s in program_obj.seasons.values():
            listing.append(
                TitleItem(
                    title=self._kodi.localize(30205,
                                              season=s.number),  # Season X
                    path=self._kodi.url_for('show_catalog_program_season',
                                            program=program,
                                            season=s.number),
                    art_dict={
                        'thumb': s.cover,
                        'fanart': program_obj.cover,
                    },
                    info_dict={
                        'tvshowtitle':
                        program_obj.name,
                        'title':
                        self._kodi.localize(30205, season=s.number),
                        '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 self._kodi.localize(30216),
                    }))

        # Sort by label. Some programs return seasons unordered.
        self._kodi.show_listing(listing,
                                30003,
                                content='tvshows',
                                sort='label')
Exemplo n.º 6
0
    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'])
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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')
Exemplo n.º 9
0
    def generate_titleitem(self, 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,
        }
        info_dict = {
            'title': item.name,
            'plot': item.description,
        }
        prop_dict = {}

        #
        # Movie
        #
        if isinstance(item, Movie):
            if item.my_list:
                context_menu = [(
                    self._kodi.localize(30101),  # Remove from My List
                    'XBMC.Container.Update(%s)' % self._kodi.url_for(
                        'mylist_del',
                        kids=self._kodi.kids_mode(),
                        video_type=self._vtm_go.CONTENT_TYPE_MOVIE,
                        content_id=item.movie_id))]
            else:
                context_menu = [(
                    self._kodi.localize(30100),  # Add to My List
                    'XBMC.Container.Update(%s)' % self._kodi.url_for(
                        'mylist_add',
                        kids=self._kodi.kids_mode(),
                        video_type=self._vtm_go.CONTENT_TYPE_MOVIE,
                        content_id=item.movie_id))]

            art_dict.update({
                'fanart': item.cover,
            })
            info_dict.update({
                'mediatype':
                'movie',
                'plot':
                self.format_plot(item),
                'duration':
                item.duration,
                'year':
                item.year,
                'aired':
                item.aired,
                'studio':
                CHANNELS.get(item.channel, {}).get('studio_icon'),
                'mpaa':
                ', '.join(item.legal) if hasattr(item, 'legal') and item.legal
                else self._kodi.localize(30216),
            })

            return TitleItem(title=item.name,
                             path=self._kodi.url_for('play',
                                                     category='movies',
                                                     item=item.movie_id),
                             art_dict=art_dict,
                             info_dict=info_dict,
                             stream_dict={
                                 'codec': 'h264',
                                 'height': 1080,
                                 'width': 1920,
                             },
                             context_menu=context_menu,
                             is_playable=True)

        #
        # Program
        #
        if isinstance(item, Program):
            if item.my_list:
                context_menu = [(
                    self._kodi.localize(30101),  # Remove from My List
                    'XBMC.Container.Update(%s)' % self._kodi.url_for(
                        'mylist_del',
                        kids=self._kodi.kids_mode(),
                        video_type=self._vtm_go.CONTENT_TYPE_PROGRAM,
                        content_id=item.program_id))]
            else:
                context_menu = [(
                    self._kodi.localize(30100),  # Add to My List
                    'XBMC.Container.Update(%s)' % self._kodi.url_for(
                        'mylist_add',
                        kids=self._kodi.kids_mode(),
                        video_type=self._vtm_go.CONTENT_TYPE_PROGRAM,
                        content_id=item.program_id))]

            art_dict.update({
                'fanart': item.cover,
                'banner': item.cover,
            })
            info_dict.update({
                'mediatype':
                None,
                'title':
                item.name,
                'plot':
                self.format_plot(item),
                'studio':
                CHANNELS.get(item.channel, {}).get('studio_icon'),
                'mpaa':
                ', '.join(item.legal) if hasattr(item, 'legal') and item.legal
                else self._kodi.localize(30216),
                'season':
                len(item.seasons),
            })

            return TitleItem(title=item.name,
                             path=self._kodi.url_for('show_catalog_program',
                                                     program=item.program_id),
                             art_dict=art_dict,
                             info_dict=info_dict,
                             context_menu=context_menu)

        #
        # Episode
        #
        if isinstance(item, Episode):
            context_menu = [(
                self._kodi.localize(30102),  # Go to Program
                'XBMC.Container.Update(%s)' % self._kodi.url_for(
                    'show_catalog_program', program=item.program_id))]

            info_dict.update({
                'tvshowtitle':
                item.program_name,
                'title':
                item.name,
                'plot':
                self.format_plot(item),
                'duration':
                item.duration,
                'season':
                item.season,
                'episode':
                item.number,
                'mediatype':
                'episode',
                'set':
                item.program_name,
                'studio':
                item.channel,
                'aired':
                item.aired,
                'mpaa':
                ', '.join(item.legal) if hasattr(item, 'legal') and item.legal
                else self._kodi.localize(30216),
            })

            if progress and item.watched:
                info_dict.update({
                    'playcount': 1,
                })

            stream_dict = {
                'codec': 'h264',
                'duration': item.duration,
                'height': 1080,
                'width': 1920,
            }

            # Get program and episode details from cache
            program = self._vtm_go.get_program(item.program_id, cache=True)
            if program:
                episode = self._vtm_go.get_episode_from_program(
                    program, item.episode_id)
                if episode:
                    art_dict.update({
                        'fanart': episode.cover,
                        'banner': episode.cover,
                    })
                    info_dict.update({
                        'tvshowtitle':
                        program.name,
                        'title':
                        episode.name,
                        'plot':
                        self.format_plot(episode),
                        'duration':
                        episode.duration,
                        'season':
                        episode.season,
                        'episode':
                        episode.number,
                        'set':
                        program.name,
                        'studio':
                        episode.channel,
                        'aired':
                        episode.aired,
                        'mpaa':
                        ', '.join(episode.legal) if hasattr(episode, 'legal')
                        and episode.legal else self._kodi.localize(30216),
                    })

                    if progress and item.watched:
                        info_dict.update({
                            'playcount': 1,
                        })

                    stream_dict.update({
                        'duration': episode.duration,
                    })

            # Add progress info
            if progress and not item.watched and item.progress:
                prop_dict.update({
                    'ResumeTime': item.progress,
                    'TotalTime': item.progress + 1,
                })

            return TitleItem(title=info_dict['title'],
                             path=self._kodi.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')