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_channels(self):
        """ Shows TV channels. """
        channels = self._channel_api.get_channels(
            filter_pin=kodiutils.get_setting_int(
                'interface_adult') == SETTINGS_ADULT_HIDE)

        # Load EPG details for the next 6 hours
        date_now = datetime.now(dateutil.tz.UTC)
        date_from = date_now.replace(minute=0, second=0, microsecond=0)
        date_to = (date_from + timedelta(hours=6))
        epg = self._epg_api.get_guide([channel.uid for channel in channels],
                                      date_from, date_to)
        for channel in channels:
            shows = [
                show for show in epg.get(channel.uid, {})
                if show.end > date_now
            ]
            try:
                channel.epg_now = shows[0]
            except (IndexError, KeyError):
                pass
            try:
                channel.epg_next = shows[1]
            except (IndexError, KeyError):
                pass

        listing = []
        for item in channels:
            title_item = Menu.generate_titleitem_channel(item)
            title_item.path = kodiutils.url_for('show_channel',
                                                channel_id=item.get_combi_id())
            title_item.is_playable = False
            listing.append(title_item)

        kodiutils.show_listing(listing, 30007)
示例#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(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)