Esempio 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})
Esempio n. 2
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})
Esempio n. 3
0
    def get_last_updated_series(self,
                                from_time,
                                weeks=1,
                                filter_show_list=None):
        """Retrieve a list with updated shows.

        :param from_time: epoch timestamp, with the start date/time
        :param weeks: number of weeks to get updates for.
        :param filter_show_list: Optional list of show objects, to use for filtering the returned list.
        :returns: A list of show_id's.
        """
        total_updates = []
        updates = True

        count = 0
        try:
            while updates and count < weeks:
                updates = self.config['session'].updates_api.updated_query_get(
                    from_time).data
                if updates:
                    last_update_ts = max(x.last_updated for x in updates)
                    from_time = last_update_ts
                    total_updates += [int(_.id) for _ in updates]
                count += 1
        except ApiException as e:
            if e.status == 401:
                raise IndexerAuthFailed(
                    'Authentication failed, possible bad api key. reason: {reason} ({status})'
                    .format(reason=e.reason, status=e.status))
            raise IndexerUnavailable(
                'Error connecting to Tvdb api. Caused by: {0}'.format(
                    e.reason))
        except RequestException as e:
            raise IndexerUnavailable(
                'Error connecting to Tvdb api. Caused by: {0}'.format(
                    e.reason))

        if total_updates and filter_show_list:
            new_list = []
            for show in filter_show_list:
                if show.indexerid in total_updates:
                    new_list.append(show.indexerid)
            total_updates = new_list

        return total_updates
Esempio n. 4
0
    def _query_series(self,
                      tvdb_id,
                      specials=False,
                      aired_season=None,
                      full_info=False):
        """Query against episodes for the given series.

        :param tvdb_id: tvdb series id.
        :param specials: enable/disable download of specials. Currently not used.
        :param aired_season: the episodes returned for a specific aired season.
        :param full_info: add full information to the episodes
        :return: An ordered dict of {'episode': [list of episode dicts]}
        """
        results = []
        if aired_season:
            aired_season = [
                aired_season
            ] if not isinstance(aired_season, list) else aired_season

        # Parse episode data
        log.debug('Getting all episodes of {0}', tvdb_id)

        # get paginated pages
        page = 1
        last = 1
        try:
            if aired_season:
                for season in aired_season:
                    page = 1
                    last = 1
                    while page <= last:
                        paged_episodes = self.config[
                            'session'].series_api.series_id_episodes_query_get(
                                tvdb_id,
                                page=page,
                                aired_season=season,
                                accept_language=self.config['language'])
                        results += paged_episodes.data
                        last = paged_episodes.links.last
                        page += 1
            else:
                while page <= last:
                    paged_episodes = self.config[
                        'session'].series_api.series_id_episodes_query_get(
                            tvdb_id,
                            page=page,
                            accept_language=self.config['language'])
                    results += paged_episodes.data
                    last = paged_episodes.links.last
                    page += 1

            if results and full_info:
                results = self._get_episodes_info(tvdb_id,
                                                  results,
                                                  season=aired_season)

        except ApiException as e:
            log.debug('Error trying to index the episodes')
            if e.status == 401:
                raise IndexerAuthFailed(
                    'Authentication failed, possible bad api key. reason: {reason} ({status})'
                    .format(reason=e.reason, status=e.status))
            raise IndexerShowIncomplete(
                'Show episode search exception, '
                'could not get any episodes. Did a {search_type} search. Exception: {e}'
                .format(search_type='full' if not aired_season else
                        'season {season}'.format(season=aired_season),
                        e=e.reason))
        except RequestException as error:
            raise IndexerUnavailable(
                'Error connecting to Tvdb api. Caused by: {error!r}'.format(
                    error=error))

        if not results:
            log.debug('Series results incomplete')
            raise IndexerShowIncomplete(
                'Show episode search returned incomplete results, '
                'could not get any episodes. Did a {search_type} search.'.
                format(search_type='full' if not aired_season else
                       'season {season}'.format(season=aired_season)))

        mapped_episodes = self._object_to_dict(results, self.series_map, '|')
        return OrderedDict({
            'episode':
            mapped_episodes
            if isinstance(mapped_episodes, list) else [mapped_episodes]
        })
Esempio n. 5
0
    def _query_series(self,
                      tvdb_id,
                      specials=False,
                      aired_season=None,
                      full_info=False):
        """Query against episodes for the given series.

        :param tvdb_id: tvdb series id.
        :param specials: enable/disable download of specials. Currently not used.
        :param aired_season: the episodes returned for a specific aired season.
        :param full_info: add full information to the episodes
        :return: An ordered dict of {'episode': [list of episode dicts]}
        """
        results = []
        if aired_season:
            aired_season = [
                aired_season
            ] if not isinstance(aired_season, list) else aired_season

        # Parse episode data
        log.debug('Getting all episodes of {0}', tvdb_id)

        # get paginated pages
        page = 1
        last = 1
        try:
            if aired_season:
                for season in aired_season:
                    page = 1
                    last = 1
                    while page <= last:
                        paged_episodes = self.config[
                            'session'].series_api.series_id_episodes_query_get(
                                tvdb_id,
                                page=page,
                                aired_season=season,
                                accept_language=self.config['language'])
                        results += paged_episodes.data
                        last = paged_episodes.links.last
                        page += 1
            else:
                while page <= last:
                    paged_episodes = self.config[
                        'session'].series_api.series_id_episodes_query_get(
                            tvdb_id,
                            page=page,
                            accept_language=self.config['language'])
                    results += paged_episodes.data
                    last = paged_episodes.links.last
                    page += 1

            if results and full_info:
                results = self._get_episodes_info(tvdb_id,
                                                  results,
                                                  season=aired_season)

        except ApiException as error:
            log.debug('Error trying to index the episodes')
            if error.status == 401:
                raise IndexerAuthFailed(
                    'Authentication failed, possible bad API key. Reason: {reason} ({status})'
                    .format(reason=error.reason, status=error.status))

            if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
                log.info(
                    'Show {name} does not have any episodes yet, adding it anyway',
                    {'name': self.shows[tvdb_id]['seriesname']})
            else:
                raise IndexerUnavailable(
                    'Error connecting to TVDB API. Reason: {reason}'.format(
                        reason=error.reason))

        mapped_episodes = self._object_to_dict(results, self.series_map, '|')
        return OrderedDict({
            'episode':
            mapped_episodes
            if isinstance(mapped_episodes, list) else [mapped_episodes]
        })