def show_search(self, query=None):
        """ Shows the search dialog.

        :param str query:               The query to search for.
        """
        if not query:
            # Ask for query
            query = kodiutils.get_search_string(
                heading=kodiutils.localize(30009))  # Search
            if not query:
                kodiutils.end_of_directory()
                return

        # Do search
        items = self._search_api.search(query)

        # Generate the results
        listing = []
        for item in items:
            if isinstance(item, Program):
                if item.series_id:
                    listing.append(Menu.generate_titleitem_series(item))
                else:
                    listing.append(Menu.generate_titleitem_program(item))

            if isinstance(item, Channel) and item.available is not False:
                listing.append(Menu.generate_titleitem_channel(item))

        # Sort like we get our results back.
        kodiutils.show_listing(listing, 30009, content='files')
    def show_channel_replay_series(self, series_id):
        """ Shows the related programs of the specified channel.

        :param str series_id:           The series we want to show.
        """

        programs = self._channel_api.get_series(series_id)

        listing = [Menu.generate_titleitem_program(item) for item in programs]

        kodiutils.show_listing(listing, 30013, content='episodes')
Exemple #3
0
    def play_asset(self, asset_id):
        """ Play an asset (can be a program of a live channel).

        :param string asset_id:         The ID of the asset to play.
        """
        # Get asset info
        if len(asset_id) == 32:
            # a locId is 32 chars
            asset = self._channel_api.get_asset_by_locid(asset_id)
        else:
            # an asset_id is 40 chars
            asset = self._channel_api.get_asset(asset_id)

        if isinstance(asset, Program):
            item = Menu.generate_titleitem_program(asset)
        elif isinstance(asset, Channel):
            item = Menu.generate_titleitem_channel(asset)
        else:
            raise Exception('Unknown asset type: %s' % asset)

        # Get stream info
        try:
            stream_info = self._channel_api.get_stream(asset.uid)
        except InvalidTokenException:
            # Retry with fresh tokens
            self._auth.login(True)
            stream_info = self._channel_api.get_stream(asset.uid)
        except (NotAvailableInOfferException, UnavailableException) as exc:
            _LOGGER.error(exc)
            kodiutils.ok_dialog(
                message=kodiutils.localize(30712)
            )  # The video is unavailable and can't be played right now.
            kodiutils.end_of_directory()
            return

        license_key = self._create_license_key(
            stream_info.drm_license_url,
            key_headers={'Content-Type': 'application/octet-stream'})

        _LOGGER.debug('Starting playing %s with license key %s',
                      stream_info.url, license_key)
        kodiutils.play(stream_info.url, license_key, item.title, item.art_dict,
                       item.info_dict, item.prop_dict)
    def show_channel_guide_detail(self, channel_id, date):
        """ Shows the dates in the tv guide.

        :param str channel_id:          The channel for which we want to show an EPG.
        :param str date:                The date to show.
        """
        # Lookup with CAPI
        lookup_id = channel_id.split(':')[1]
        programs = self._epg_api.get_guide_with_capi([lookup_id], date)

        # Lookup with TV API
        # lookup_id = channel_id.split(':')[0]
        # programs = self._epg_api.get_guide([lookup_id], date)

        listing = [
            Menu.generate_titleitem_program(item, timeline=True)
            for item in programs.get(lookup_id)
        ]

        kodiutils.show_listing(listing, 30013, content='files')
    def show_channel_replay(self, channel_id):
        """ Shows the replay programs of the specified channel.

        :param str channel_id:          The channel for which we want to show the replay programs.
        """
        programs = self._channel_api.get_replay(channel_id.split(':')[0])

        listing = []
        for item in programs:
            # Hide these items
            if item.title == EpgApi.EPG_NO_BROADCAST:
                continue

            if item.series_id:
                listing.append(Menu.generate_titleitem_series(item))
            else:
                listing.append(Menu.generate_titleitem_program(item))

        kodiutils.show_listing(listing,
                               30013,
                               content='tvshows',
                               sort=['label'])
    def show_channel(self, channel_id):
        """ Shows TV channel details.

        :param str channel_id:          The channel we want to display.
        """
        channel = self._channel_api.get_asset(channel_id.split(':')[0])

        # Verify PIN
        if channel.pin and kodiutils.get_setting_int(
                'interface_adult') != SETTINGS_ADULT_ALLOW:
            pin = kodiutils.get_numeric_input(
                kodiutils.localize(30204))  # Enter PIN
            if not pin:
                # Cancelled
                kodiutils.end_of_directory()
                return

            if not self._channel_api.verify_pin(pin):
                kodiutils.ok_dialog(message=kodiutils.localize(
                    30205))  # The PIN you have entered is invalid!
                kodiutils.end_of_directory()
                return

        listing = []

        # Play live
        live_titleitem = Menu.generate_titleitem_channel(channel)
        live_titleitem.info_dict['title'] = kodiutils.localize(
            30051, channel=channel.title)  # Watch live [B]{channel}[/B]
        listing.append(live_titleitem)

        # Restart currently airing program
        if channel.epg_now and channel.epg_now.restart:
            restart_titleitem = Menu.generate_titleitem_program(
                channel.epg_now)
            restart_titleitem.info_dict['title'] = kodiutils.localize(
                30052,
                program=channel.epg_now.title)  # Restart [B]{program}[/B]
            restart_titleitem.art_dict['thumb'] = 'DefaultInProgressShows.png'
            listing.append(restart_titleitem)

        # TV Guide
        listing.append(
            TitleItem(
                title=kodiutils.localize(
                    30053, channel=channel.title),  # TV Guide for {channel}
                path=kodiutils.url_for('show_channel_guide',
                                       channel_id=channel_id),
                art_dict=dict(icon='DefaultAddonTvInfo.png', ),
                info_dict=dict(
                    plot=kodiutils.localize(
                        30054, channel=channel.title
                    ),  # Browse the TV Guide for {channel}
                ),
            ))

        if channel.replay:
            listing.append(
                TitleItem(
                    title=kodiutils.localize(
                        30055, channel=channel.title),  # Catalog for {channel}
                    path=kodiutils.url_for('show_channel_replay',
                                           channel_id=channel_id),
                    art_dict=dict(icon='DefaultMovieTitle.png', ),
                    info_dict=dict(
                        plot=kodiutils.localize(
                            30056, channel=channel.title
                        ),  # Browse the Catalog for {channel}
                    ),
                ))

        kodiutils.show_listing(listing, 30007)