예제 #1
0
    def play(item):
        """ Play the requested item.
        :type item: string
        """

        # Workaround for Raspberry Pi 3 and older
        omxplayer = kodiutils.get_global_setting('videoplayer.useomxplayer')
        if omxplayer is False:
            kodiutils.set_global_setting('videoplayer.useomxplayer', True)

        try:
            # Check if we have credentials
            if not kodiutils.get_setting(
                    'username') or not kodiutils.get_setting('password'):
                confirm = kodiutils.yesno_dialog(
                    message=kodiutils.localize(30701)
                )  # To watch a video, you need to enter your credentials. Do you want to enter them now?
                if confirm:
                    kodiutils.open_settings()
                kodiutils.end_of_directory()
                return

            # Fetch an auth token now
            try:
                auth = AuthApi(kodiutils.get_setting('username'),
                               kodiutils.get_setting('password'),
                               kodiutils.get_tokens_path())

                # Get stream information
                resolved_stream = ContentApi(auth).get_stream_by_uuid(item)

            except (InvalidLoginException, AuthenticationException) as ex:
                _LOGGER.error(ex)
                kodiutils.ok_dialog(
                    message=kodiutils.localize(30702, error=str(ex)))
                kodiutils.end_of_directory()
                return

        except GeoblockedException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30709),
                                message=kodiutils.localize(
                                    30710))  # This video is geo-blocked...
            return

        except UnavailableException:
            kodiutils.ok_dialog(heading=kodiutils.localize(30711),
                                message=kodiutils.localize(
                                    30712))  # The video is unavailable...
            return

        # Play this item
        kodiutils.play(resolved_stream)
예제 #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:
            kodiutils.ok_dialog(
                message=kodiutils.localize(30717)
            )  # This program is not available in the VTM GO catalogue.
            kodiutils.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 kodiutils.get_global_setting('videolibrary.showallitems') is True:
            listing.append(
                kodiutils.TitleItem(
                    title='* %s' % kodiutils.localize(30204),  # * All seasons
                    path=kodiutils.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=kodiutils.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 kodiutils.localize(30216),  # All ages
                    ),
                ))

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

        # Sort by label. Some programs return seasons unordered.
        kodiutils.show_listing(listing,
                               30003,
                               content='tvshows',
                               sort=['label'])
예제 #3
0
    def show_program(self, program_id):
        """ Show a program from the catalog
        :type program_id: str
         """
        try:
            program = self._api.get_program(
                program_id, extract_clips=True, cache=CACHE_PREVENT
            )  # Use CACHE_PREVENT since we want fresh data
        except UnavailableException:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        if not program.episodes and not program.clips:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        # Go directly to the season when we have only one season and no clips
        if not program.clips and len(program.seasons) == 1:
            self.show_program_season(program_id,
                                     list(program.seasons.values())[0].uuid)
            return

        listing = []

        # Add an '* All seasons' entry when configured in Kodi
        if program.seasons and kodiutils.get_global_setting(
                'videolibrary.showallitems') is True:
            listing.append(
                TitleItem(
                    title='* %s' % kodiutils.localize(30204),  # * All seasons
                    path=kodiutils.url_for('show_catalog_program_season',
                                           program=program_id,
                                           season='-1'),
                    art_dict={
                        'fanart': program.fanart,
                        'poster': program.poster,
                        'landscape': program.thumb,
                    },
                    info_dict={
                        'tvshowtitle': program.title,
                        'title': kodiutils.localize(30204),  # All seasons
                        'plot': program.description,
                        'set': program.title,
                    }))

        # Add the seasons
        for season in list(program.seasons.values()):
            listing.append(
                TitleItem(
                    title=season.
                    title,  # kodiutils.localize(30205, season=season.number),  # Season {season}
                    path=kodiutils.url_for('show_catalog_program_season',
                                           program=program_id,
                                           season=season.uuid),
                    art_dict={
                        'fanart': program.fanart,
                        'poster': program.poster,
                        'landscape': program.thumb,
                    },
                    info_dict={
                        'tvshowtitle': program.title,
                        'title': kodiutils.localize(
                            30205, season=season.number),  # Season {season}
                        'plot': season.description or program.description,
                        'set': program.title,
                    }))

        # Add Clips
        if program.clips:
            listing.append(
                TitleItem(
                    title=kodiutils.localize(
                        30059, program=program.title),  # Clips for {program}
                    path=kodiutils.url_for('show_catalog_program_clips',
                                           program=program_id),
                    art_dict={
                        'fanart': program.fanart,
                        'poster': program.poster,
                        'landscape': program.thumb,
                    },
                    info_dict={
                        'tvshowtitle': program.title,
                        'title': kodiutils.localize(
                            30059,
                            program=program.title),  # Clips for {program}
                        'plot':
                        kodiutils.localize(30060, program=program.title
                                           ),  # Watch short clips of {program}
                        'set': program.title,
                    }))

        # Sort by label. Some programs return seasons unordered.
        kodiutils.show_listing(listing, 30003, content='tvshows')
예제 #4
0
def show_program(program, season=None):
    kids = _get_kids_mode()
    try:
        _vtmGo = VtmGo(kids=kids)
        program_obj = _vtmGo.get_program(program)
    except Exception as ex:
        notification(message=str(ex))
        raise

    seasons = program_obj.seasons.values()

    # If more than one season and no season provided, give a season-overview
    if season is None and len(seasons) > 1:

        # Add an '* All seasons' entry when configured in Kodi
        if get_global_setting('videolibrary.showallitems') is True:
            listitem = ListItem('* All seasons', offscreen=True)
            listitem.setArt({
                'thumb': program_obj.cover,
                'fanart': program_obj.cover,
            })
            listitem.setInfo(
                'video', {
                    'tvshowtitle': program_obj.name,
                    'title': 'All seasons',
                    'subtitle': program_obj.description,
                    'plot': _format_plot(program_obj),
                    'set': program_obj.name,
                })
            xbmcplugin.addDirectoryItem(
                plugin.handle,
                plugin.url_for(show_program,
                               program=program,
                               season='all',
                               kids=kids), listitem, True)

        for s in program_obj.seasons.values():
            listitem = ListItem('Season %d' % s.number, offscreen=True)
            listitem.setArt({
                'thumb': s.cover,
                'fanart': program_obj.cover,
            })
            listitem.setInfo(
                'video', {
                    'tvshowtitle': program_obj.name,
                    'title': 'Season %d' % s.number,
                    'subtitle': program_obj.description,
                    'plot': _format_plot(program_obj),
                    'set': program_obj.name,
                    'season': season,
                })
            xbmcplugin.addDirectoryItem(
                plugin.handle,
                plugin.url_for(show_program, program=program, season=s.number),
                listitem, True)
        xbmcplugin.setContent(plugin.handle, 'tvshows')

        # Sort by label. Some programs return seasons unordered.
        xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
        xbmcplugin.endOfDirectory(plugin.handle)
        return

    if season != 'all' and season is not None:
        # Use the season that was selected
        seasons = [program_obj.seasons[int(season)]]

    for s in seasons:
        for episode in s.episodes.values():
            listitem = ListItem(episode.name, offscreen=True)
            listitem.setArt({
                'banner': program_obj.cover,
                'fanart': program_obj.cover,
                'thumb': episode.cover,
            })
            listitem.setInfo(
                'video', {
                    'tvshowtitle': program_obj.name,
                    'title': episode.name,
                    'subtitle': program_obj.description,
                    'plot': _format_plot(episode),
                    'duration': episode.duration,
                    'season': episode.season,
                    'episode': episode.number,
                    'mediatype': episode.mediatype,
                    'set': program_obj.name,
                    'studio': episode.channel,
                    'aired': episode.aired,
                })
            listitem.addStreamInfo('video', {
                'duration': episode.duration,
            })
            listitem.setProperty('IsPlayable', 'true')
            xbmcplugin.addDirectoryItem(
                plugin.handle, plugin.url_for(play_episode,
                                              episode=episode.id), listitem)

    xbmcplugin.setContent(plugin.handle, 'episodes')

    # Sort by episode number by default. Takes seasons into account.
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_EPISODE)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.endOfDirectory(plugin.handle)
예제 #5
0
    def show_program(self, channel, program_id):
        """ Show a program from the catalog
        :type channel: str
        :type program_id: str
         """
        try:
            program = self._api.get_program(
                channel, program_id, cache=CACHE_PREVENT
            )  # Use CACHE_PREVENT since we want fresh data
        except UnavailableException:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        if not program.episodes:
            kodiutils.ok_dialog(message=kodiutils.localize(
                30717))  # This program is not available in the catalogue.
            kodiutils.end_of_directory()
            return

        # Go directly to the season when we have only one season
        if len(program.seasons) == 1:
            self.show_program_season(channel, program_id,
                                     list(program.seasons.values())[0].uuid)
            return

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

        listing = []

        # Add an '* All seasons' entry when configured in Kodi
        if kodiutils.get_global_setting('videolibrary.showallitems') is True:
            listing.append(
                TitleItem(
                    title='* %s' % kodiutils.localize(30204),  # * All seasons
                    path=kodiutils.url_for('show_catalog_program_season',
                                           channel=channel,
                                           program=program_id,
                                           season='-1'),
                    art_dict={
                        'fanart': program.background,
                    },
                    info_dict={
                        'tvshowtitle': program.title,
                        'title': kodiutils.localize(30204),  # All seasons
                        'plot': program.description,
                        'set': program.title,
                        'studio': studio,
                    }))

        # Add the seasons
        for season in list(program.seasons.values()):
            listing.append(
                TitleItem(
                    title=season.
                    title,  # kodiutils.localize(30205, season=season.number),  # Season {season}
                    path=kodiutils.url_for('show_catalog_program_season',
                                           channel=channel,
                                           program=program_id,
                                           season=season.uuid),
                    art_dict={
                        'fanart': program.background,
                    },
                    info_dict={
                        'tvshowtitle': program.title,
                        'title': kodiutils.localize(
                            30205, season=season.number),  # Season {season}
                        'plot': season.description,
                        'set': program.title,
                        'studio': studio,
                    }))

        # Sort by label. Some programs return seasons unordered.
        kodiutils.show_listing(listing, 30003, content='tvshows')