Beispiel #1
0
    def generate_titleitem(item):
        """ Generate a TitleItem based on a Program or Episode.
        :type item: Union[Program, Episode]
        :rtype TitleItem
        """
        art_dict = {
            'thumb': item.cover,
            'cover': item.cover,
        }
        info_dict = {
            'title': item.title,
            'plot': item.description,
            'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
            'aired': item.aired.strftime('%Y-%m-%d') if item.aired else None,
        }
        prop_dict = {}

        #
        # Program
        #
        if isinstance(item, Program):
            art_dict.update({
                'fanart': item.background,
            })
            info_dict.update({
                'mediatype':
                None,
                'season':
                len(item.seasons) if item.seasons else None,
            })

            if isinstance(item.episodes, list) and not item.episodes:
                # We know that we don't have episodes
                title = '[COLOR gray]' + item.title + '[/COLOR]'
            else:
                # We have episodes, or we don't know it
                title = item.title

            return TitleItem(title=title,
                             path=kodiutils.url_for('show_catalog_program',
                                                    channel=item.channel,
                                                    program=item.path),
                             art_dict=art_dict,
                             info_dict=info_dict)

        #
        # Episode
        #
        if isinstance(item, Episode):
            art_dict.update({
                'fanart': item.cover,
            })
            info_dict.update({
                'mediatype': 'episode',
                'tvshowtitle': item.program_title,
                'duration': item.duration,
                'season': item.season,
                'episode': item.number,
            })

            stream_dict = STREAM_DICT.copy()
            stream_dict.update({
                'duration': item.duration,
            })

            return TitleItem(title=info_dict['title'],
                             path=kodiutils.url_for('play', uuid=item.uuid),
                             art_dict=art_dict,
                             info_dict=info_dict,
                             stream_dict=stream_dict,
                             prop_dict=prop_dict,
                             is_playable=True)

        raise Exception('Unknown video_type')
    def generate_titleitem(item):
        """ Generate a TitleItem based on a Program or Episode.
        :type item: Union[Program, Episode]
        :rtype TitleItem
        """
        info_dict = {
            'title': item.title,
            'plot': item.description,
            'aired': item.aired.strftime('%Y-%m-%d') if item.aired else None,
        }
        prop_dict = {}

        #
        # Program
        #
        if isinstance(item, Program):
            info_dict.update({
                'mediatype':
                None,
                'season':
                len(item.seasons) if item.seasons else None,
            })

            art_dict = {
                'poster': item.poster,
                'landscape': item.thumb,
                'thumb': item.thumb,
                'fanart': item.fanart,
            }

            visible = True
            if isinstance(item.episodes, list) and not item.episodes:
                # We know that we don't have episodes
                title = '[COLOR gray]' + item.title + '[/COLOR]'
                visible = kodiutils.get_setting_bool(
                    'interface_show_unavailable')

            else:
                # We have episodes, or we don't know it
                title = item.title

            context_menu = []
            if item.uuid:
                if item.my_list:
                    context_menu.append((
                        kodiutils.localize(30101),  # Remove from My List
                        'Container.Update(%s)' %
                        kodiutils.url_for('mylist_del', uuid=item.uuid)))
                else:
                    context_menu.append((
                        kodiutils.localize(30100),  # Add to My List
                        'Container.Update(%s)' %
                        kodiutils.url_for('mylist_add', uuid=item.uuid)))

            context_menu.append((
                kodiutils.localize(30102),  # Go to Program
                'Container.Update(%s)' %
                kodiutils.url_for('show_catalog_program', program=item.path)))

            return TitleItem(title=title,
                             path=kodiutils.url_for('show_catalog_program',
                                                    program=item.path),
                             context_menu=context_menu,
                             art_dict=art_dict,
                             info_dict=info_dict,
                             visible=visible)

        #
        # Episode
        #
        if isinstance(item, Episode):
            info_dict.update({
                'mediatype': 'episode',
                'tvshowtitle': item.program_title,
                'duration': item.duration,
                'season': item.season,
                'episode': item.number,
            })

            art_dict = {
                'landscape': item.thumb,
                'thumb': item.thumb,
                'fanart': item.thumb,
            }

            stream_dict = STREAM_DICT.copy()
            stream_dict.update({
                'duration': item.duration,
            })

            if item.uuid:
                # We have an UUID and can play this item directly
                path = kodiutils.url_for('play_catalog', uuid=item.uuid)
            else:
                # We don't have an UUID, and first need to fetch the video information from the page
                path = kodiutils.url_for('play_from_page',
                                         page=quote(item.path, safe=''))

            return TitleItem(title=info_dict['title'],
                             path=path,
                             art_dict=art_dict,
                             info_dict=info_dict,
                             stream_dict=stream_dict,
                             prop_dict=prop_dict,
                             is_playable=True)

        raise Exception('Unknown video_type')
    def show_detail(self, channel=None, date=None):
        """ Shows the programs of a specific date in the tv guide
        :type channel: str
        :type date: str
        """
        try:
            programs = self._epg.get_epg(channel=channel, date=date)
        except UnavailableException as ex:
            kodiutils.notification(message=str(ex))
            kodiutils.end_of_directory()
            return

        listing = []
        for program in programs:
            if program.program_url:
                context_menu = [(
                    kodiutils.localize(30102),  # Go to Program
                    'Container.Update(%s)' %
                    kodiutils.url_for('show_catalog_program',
                                      channel=channel,
                                      program=program.program_url))]
            else:
                context_menu = None

            title = '{time} - {title}'.format(
                time=program.start.strftime('%H:%M'),
                title=program.program_title)

            if program.airing:
                title = '[B]{title}[/B]'.format(title=title)

            if program.video_url:
                path = kodiutils.url_for('play_from_page',
                                         channel=channel,
                                         page=quote(program.video_url,
                                                    safe=''))
            else:
                path = kodiutils.url_for('play_catalog', uuid='')
                title = '[COLOR gray]' + title + '[/COLOR]'

            stream_dict = STREAM_DICT.copy()
            stream_dict.update({
                'duration': program.duration,
            })

            info_dict = {
                'title': title,
                'plot': program.description,
                'studio': program.channel,
                'duration': program.duration,
                'tvshowtitle': program.program_title,
                'season': program.season,
                'episode': program.number,
                'mediatype': 'episode',
            }

            listing.append(
                TitleItem(title=title,
                          path=path,
                          art_dict={
                              'thumb': program.thumb,
                          },
                          info_dict=info_dict,
                          stream_dict=stream_dict,
                          context_menu=context_menu,
                          is_playable=True))

        kodiutils.show_listing(listing,
                               30013,
                               content='episodes',
                               sort=['unsorted'])
    def generate_titleitem(item):
        """ Generate a TitleItem based on a Program or Episode.
        :type item: Union[Program, Episode]
        :rtype TitleItem
        """
        art_dict = {
            'thumb': item.cover,
            'cover': item.cover,
            'fanart': item.background or item.cover,
        }
        info_dict = {
            'title': item.title,
            'plot': item.description,
            'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
            'aired': item.aired.strftime('%Y-%m-%d') if item.aired else None,
        }
        prop_dict = {}

        #
        # Program
        #
        if isinstance(item, Program):
            info_dict.update({
                'mediatype':
                None,
                'season':
                len(item.seasons) if item.seasons else None,
            })

            if isinstance(item.episodes, list) and not item.episodes:
                # We know that we don't have episodes
                title = '[COLOR gray]' + item.title + '[/COLOR]'
            else:
                # We have episodes, or we don't know it
                title = item.title

            return TitleItem(title=title,
                             path=kodiutils.url_for('show_catalog_program',
                                                    channel=item.channel,
                                                    program=item.path),
                             art_dict=art_dict,
                             info_dict=info_dict)

        #
        # Episode
        #
        if isinstance(item, Episode):
            info_dict.update({
                'mediatype': 'episode',
                'tvshowtitle': item.program_title,
                'duration': item.duration,
                'season': item.season,
                'episode': item.number,
            })

            stream_dict = STREAM_DICT.copy()
            stream_dict.update({
                'duration': item.duration,
            })

            if item.path:
                try:  # Python 3
                    from urllib.parse import quote
                except ImportError:  # Python 2
                    from urllib import quote

                # We don't have an UUID, and first need to fetch the video information from the page
                path = kodiutils.url_for('play_from_page',
                                         channel=item.channel,
                                         page=quote(item.path, safe=''))
            else:
                # We have an UUID and can play this item directly
                # This is not preferred since we will lack metadata
                path = kodiutils.url_for('play_catalog', uuid=item.uuid)

            return TitleItem(title=info_dict['title'],
                             path=path,
                             art_dict=art_dict,
                             info_dict=info_dict,
                             stream_dict=stream_dict,
                             prop_dict=prop_dict,
                             is_playable=True)

        raise Exception('Unknown video_type')