示例#1
0
    def _get_show_data(self, sid, language):
        """Parse TheTVDB json response.

        Takes a series ID, gets the epInfo URL and parses the TheTVDB json response
        into the shows dict in layout:
        shows[series_id][season_number][episode_number]
        """
        if self.config['language'] is None:
            log.debug('Config language is none, using show language')
            if language is None:
                raise IndexerError(
                    "config['language'] was None, this should not happen")
            get_show_in_language = language
        else:
            log.debug(
                'Configured language {0} override show language of {1}',
                self.config['language'],
                language,
            )
            get_show_in_language = self.config['language']

        # Parse show information
        log.debug('Getting all series data for {0}', sid)

        # Parse show information
        series_info = self._get_show_by_id(
            sid, request_language=get_show_in_language)

        if not series_info:
            log.debug('Series result returned zero')
            raise IndexerError('Series result returned zero')

        # get series data / add the base_url to the image urls
        for k, v in series_info['series'].items():
            if v is not None:
                if v and k in ['banner', 'fanart', 'poster']:
                    v = self.config['artwork_prefix'] % v
            self._set_show_data(sid, k, v)

        # Create the externals structure
        self._set_show_data(
            sid, 'externals',
            {'imdb_id': str(getattr(self[sid], 'imdb_id', ''))})

        # get episode data
        if self.config['episodes_enabled']:
            self._get_episodes(sid,
                               specials=False,
                               aired_season=None,
                               full_info=True)

        # Parse banners
        if self.config['banners_enabled']:
            self._parse_images(sid)

        # Parse actors
        if self.config['actors_enabled']:
            self._parse_actors(sid)

        return True
示例#2
0
    def _get_show_data(self, sid, language='en'):  # pylint: disable=too-many-branches,too-many-statements,too-many-locals
        """Take a series ID, gets the epInfo URL and parses the TMDB json response.

        into the shows dict in layout:
        shows[series_id][season_number][episode_number]
        """
        if self.config['language'] is None:
            log.debug('Config language is none, using show language')
            if language is None:
                raise IndexerError("config['language'] was None, this should not happen")
            get_show_in_language = language
        else:
            log.debug('Configured language {0} override show language of {1}',
                      self.config['language'], language)
            get_show_in_language = self.config['language']

        # Parse show information
        log.debug('Getting all series data for {0}', sid)

        # Parse show information
        series_info = self._get_show_by_id(sid, request_language=get_show_in_language)

        if not series_info:
            log.debug('Series result returned zero')
            raise IndexerError('Series result returned zero')

        # get series data / add the base_url to the image urls
        # Create a key/value dict, to map the image type to a default image width.
        # possitlbe widths can also be retrieved from self.configuration.images['poster_sizes'] and
        # self.configuration.images['still_sizes']
        image_width = {'fanart': 'w1280', 'poster': 'w500'}

        for k, v in series_info['series'].items():
            if v is not None:
                if k in ['fanart', 'banner', 'poster']:
                    v = self.config['artwork_prefix'].format(base_url=self.tmdb_configuration.images['base_url'],
                                                             image_size=image_width[k],
                                                             file_path=v)

            self._set_show_data(sid, k, v)

        # Get external ids.
        # As the external id's are not part of the shows default response, we need to make an additional call for it.
        self._set_show_data(sid, 'externals', self.tmdb.TV(sid).external_ids())

        # get episode data
        if self.config['episodes_enabled']:
            self._get_episodes(sid, specials=False, aired_season=None)

        # Parse banners
        if self.config['banners_enabled']:
            self._parse_images(sid)

        # Parse actors
        if self.config['actors_enabled']:
            self._parse_actors(sid)

        return True
示例#3
0
    def _get_show_data(self, tvmaze_id, language='en'):  # pylint: disable=too-many-branches,too-many-statements,too-many-locals
        """Takes a series ID, gets the epInfo URL and parses the tvmaze json response
        into the shows dict in layout:
        shows[series_id][season_number][episode_number]
        """

        if self.config['language'] is None:
            log.debug('Config language is none, using show language')
            if language is None:
                raise IndexerError(
                    "config['language'] was None, this should not happen")
            get_show_in_language = language
        else:
            log.debug('Configured language {0} override show language of {1}',
                      self.config['language'], language)
            get_show_in_language = self.config['language']

        # Parse show information
        log.debug('Getting all series data for {0}', tvmaze_id)

        # Parse show information
        series_info = self._get_show_by_id(
            tvmaze_id, request_language=get_show_in_language)

        if not series_info:
            log.debug('Series result returned zero')
            raise IndexerError('Series result returned zero')

        # save all retrieved show information to Show object.
        for k, v in series_info['series'].items():
            if v is not None:
                self._set_show_data(tvmaze_id, k, v)

        # Get external ids.
        # As the external id's are not part of the shows default response, we need to make an additional call for it.
        # Im checking for the external value. to make sure only externals with a value get in.
        self._set_show_data(
            tvmaze_id, 'externals', {
                external_id: text_type(
                    getattr(self.shows[tvmaze_id], external_id, None))
                for external_id in ['tvdb_id', 'imdb_id', 'tvrage_id']
                if getattr(self.shows[tvmaze_id], external_id, None)
            })

        # get episode data
        if self.config['episodes_enabled']:
            self._get_episodes(tvmaze_id, specials=False, aired_season=None)

        # Parse banners
        if self.config['banners_enabled']:
            self._parse_images(tvmaze_id)

        # Parse actors
        if self.config['actors_enabled']:
            self._parse_actors(tvmaze_id)

        return True
示例#4
0
文件: tmdb.py 项目: todokku/Medusa
    def _get_show_data(self, tmdb_id, language='en'):
        """Take a series ID, gets the epInfo URL and parses the TMDB json response.

        into the shows dict in layout:
        shows[series_id][season_number][episode_number]
        """
        if self.config['language'] is None:
            log.debug('Config language is none, using show language')
            if language is None:
                raise IndexerError("config['language'] was None, this should not happen")
            get_show_in_language = language
        else:
            log.debug('Configured language {0} override show language of {1}',
                      self.config['language'], language)
            get_show_in_language = self.config['language']

        # Parse show information
        log.debug('Getting all series data for {0}', tmdb_id)

        # Parse show information
        extra_series_info = ('content_ratings', 'external_ids')
        series_info = self._get_show_by_id(
            tmdb_id,
            request_language=get_show_in_language,
            extra_info=extra_series_info
        )

        if not series_info:
            log.debug('Series result returned zero')
            raise IndexerError('Series result returned zero')

        # Get MPAA rating if available
        content_ratings = series_info['series'].get('content_ratings', {}).get('results')
        if content_ratings:
            mpaa_rating = next((r['rating'] for r in content_ratings
                                if r['iso_3166_1'].upper() == 'US'), None)
            if mpaa_rating:
                self._set_show_data(tmdb_id, 'contentrating', mpaa_rating)

        # get series data / add the base_url to the image urls
        # Create a key/value dict, to map the image type to a default image width.
        # possitlbe widths can also be retrieved from self.configuration.images['poster_sizes'] and
        # self.configuration.images['still_sizes']
        image_width = {'fanart': 'w1280', 'poster': 'w500'}

        for k, v in viewitems(series_info['series']):
            if v is not None:
                if k in ['fanart', 'banner', 'poster']:
                    v = self.config['artwork_prefix'].format(base_url=self.tmdb_configuration.images['base_url'],
                                                             image_size=image_width[k],
                                                             file_path=v)

            self._set_show_data(tmdb_id, k, v)

        # Get external ids.
        external_ids = series_info['series'].get('external_ids', {})
        self._set_show_data(tmdb_id, 'externals', external_ids)

        # get episode data
        if self.config['episodes_enabled']:
            self._get_episodes(tmdb_id, specials=False, aired_season=None)

        # Parse banners
        if self.config['banners_enabled']:
            self._parse_images(tmdb_id)

        # Parse actors
        if self.config['actors_enabled']:
            self._parse_actors(tmdb_id)

        return True