Ejemplo n.º 1
0
    def _show_search(self, show, request_language='en'):
        """Use the pytvdbv2 API to search for a show.

        @param show: The show name that's searched for as a string
        @return: A list of Show objects.
        """
        try:
            results = self.config['session'].search_api.search_series_get(
                name=show, accept_language=request_language)
        except ApiException as error:
            if error.status == 401:
                raise IndexerAuthFailed(
                    'Authentication failed, possible bad api key. reason: {reason} ({status})'
                    .format(reason=error.reason, status=error.status))
            raise IndexerShowNotFound(
                'Show search failed in getting a result with reason: {0}'.
                format(error.reason))
        except RequestException as error:
            raise IndexerException(
                'Show search failed in getting a result with error: {0!r}'.
                format(error))

        if results:
            return results
        else:
            return OrderedDict({'data': None})
Ejemplo n.º 2
0
    def _get_series(self, series):
        """Search thetvdb.com for the series name.

        If a custom_ui UI is configured, it uses this to select the correct
        series. If not, and interactive == True, ConsoleUI is used, if not
        BaseUI is used to select the first result.

        :param series: the query for the series name
        :return: A list of series mapped to a UI (for example: a BaseUi or custom_ui).
        """
        all_series = self.search(series)
        if not all_series:
            log.debug('Series result returned zero')
            IndexerShowNotFound(
                'Show search returned zero results (cannot find show on TVDB)')

        if not isinstance(all_series, list):
            all_series = [all_series]

        if self.config['custom_ui'] is not None:
            log.debug('Using custom UI {0!r}', self.config['custom_ui'])
            custom_ui = self.config['custom_ui']
            ui = custom_ui(config=self.config)
        else:
            if not self.config['interactive']:
                log.debug('Auto-selecting first search result using BaseUI')
                ui = BaseUI(config=self.config)
            else:
                log.debug('Interactively selecting show using ConsoleUI')
                ui = ConsoleUI(config=self.config)  # pylint: disable=redefined-variable-type

        return ui.select_series(all_series)
Ejemplo n.º 3
0
    def _get_show_by_id(self, tvdbv2_id, request_language='en'):  # pylint: disable=unused-argument
        """Retrieve tvdbv2 show information by tvdbv2 id, or if no tvdbv2 id provided by passed external id.

        :param tvdbv2_id: The shows tvdbv2 id
        :return: An ordered dict with the show searched for.
        """
        results = None
        if tvdbv2_id:
            log.debug('Getting all show data for {0}', tvdbv2_id)
            try:
                results = self.config['session'].series_api.series_id_get(
                    tvdbv2_id, accept_language=request_language)
            except ApiException as error:
                if error.status == 401:
                    raise IndexerAuthFailed(
                        'Authentication failed, possible bad API key. Reason: {reason} ({status})'
                        .format(reason=error.reason, status=error.status))
                raise IndexerShowNotFound(
                    'Show search failed in getting a result with reason: {reason} ({status})'
                    .format(reason=error.reason, status=error.status))

        if not results:
            return

        if not getattr(results.data, 'series_name', None):
            raise IndexerShowNotFoundInLanguage(
                'Missing attribute series_name, cant index in language: {0}'.
                format(request_language), request_language)

        mapped_results = self._object_to_dict(results, self.series_map, '|')

        return OrderedDict({'series': mapped_results})
Ejemplo n.º 4
0
    def _show_search(self, show, request_language='en'):
        """Use TMDB API to search for a show.

        :param show: The show name that's searched for as a string
        :param request_language: Language in two letter code. TMDB fallsback to en itself.
        :return: A list of Show objects.
        """
        try:
            # get paginated pages
            page = 1
            last = 1
            results = []
            while page <= last:
                search_result = self.tmdb.Search().tv(query=show,
                                                      language=request_language,
                                                      page=page)
                last = search_result.get('total_pages', 0)
                results += search_result.get('results')
                page += 1
        except RequestException as error:
            raise IndexerUnavailable('Show search failed using indexer TMDB. Cause: {cause}'.format(cause=error))

        if not results:
            raise IndexerShowNotFound('Show search failed in getting a result with reason: Not found')

        return results
Ejemplo n.º 5
0
    def _get_show_by_id(self, tvmaze_id, request_language='en'):  # pylint: disable=unused-argument
        """
        Retrieve tvmaze show information by tvmaze id, or if no tvmaze id provided by passed external id.

        :param tvmaze_id: The shows tvmaze id
        :return: An ordered dict with the show searched for.
        """
        results = None
        if tvmaze_id:
            log.debug('Getting all show data for {0}', tvmaze_id)

            try:
                results = self.tvmaze_api.get_show(maze_id=tvmaze_id)
            except ShowNotFound as error:
                # Use error.value because TVMaze API exceptions may be utf-8 encoded when using __str__
                raise IndexerShowNotFound(
                    'Show search failed in getting a result with reason: {0}'.format(error.value)
                )
            except BaseError as error:
                raise IndexerUnavailable('Show search failed in getting a result with error: {0!r}'.format(error))

        if not results:
            return

        mapped_results = self._map_results(results, self.series_map)
        return OrderedDict({'series': mapped_results})
Ejemplo n.º 6
0
    def _show_search(self, show, request_language='en'):
        """
        Use the TVMaze API to search for a show.

        :param show: The show name that's searched for as a string
        :param request_language: Language in two letter code. TVMaze fallsback to en itself.
        :return: A list of Show objects.
        """
        try:
            results = self.tvmaze_api.get_show_list(show)
        except ShowNotFound as error:
            # Use error.value because TVMaze API exceptions may be utf-8 encoded when using __str__
            raise IndexerShowNotFound(
                'Show search failed in getting a result with reason: {0}'.format(error.value)
            )
        except BaseError as error:
            raise IndexerUnavailable('Show search failed in getting a result with error: {0!r}'.format(error))

        return results
Ejemplo n.º 7
0
    def _show_search(self, show, request_language='en'):
        """
        Uses the TVMaze API to search for a show
        :param show: The show name that's searched for as a string
        :param request_language: Language in two letter code. TVMaze fallsback to en itself.
        :return: A list of Show objects.
        """
        try:
            results = self.tvmaze_api.get_show_list(show)
        except ShowNotFound as error:
            raise IndexerShowNotFound(
                'Show search failed in getting a result with reason: {0}'.
                format(error))
        except BaseError as error:
            raise IndexerException(
                'Show search failed in getting a result with error: {0!r}'.
                format(error))

        if results:
            return results
        else:
            return None