コード例 #1
0
ファイル: api.py プロジェクト: segator/Medusa
    def _get_show_data(self, tvmaze_id, language='en'):
        """Take 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 viewitems(series_info['series']):
            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
コード例 #2
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 viewitems(series_info['series']):
            if v is not None:
                if v and k in ['banner', 'fanart', 'poster']:
                    v = self.config['artwork_prefix'].format(image=v)
            self._set_show_data(sid, k, v)

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

        # 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, sid, language):
        """Fetches available information about a show."""
        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 dict.items(series_info['series']):
            if v is not None:
                if v and k in ['banner', 'fanart', 'poster']:
                    v = self.config['artwork_prefix'].format(image=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)

        # Parse banners
        if self.config['banners_enabled']:
            # Set the data from Series Info to avoid broken images caused by broken links
            po = None
            fa = None
            if series_info.get('series').get('poster') and series_info.get('series').get('poster') != '':
                po = series_info.get('series').get('poster')
            if series_info.get('series').get('fanart') and series_info.get('series').get('fanart') != '':
                fa = series_info.get('series').get('fanart')
            self._parse_images(sid, poster=po, fanart=fa)

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

        return True
コード例 #4
0
ファイル: api.py プロジェクト: reconman/Medusa
    def _get_show_data(self, imdb_id, language='en'):  # pylint: disable=too-many-branches,too-many-statements,too-many-locals
        """Get show data by imdb id.

        Take a series ID, gets the epInfo URL and parses the imdb json response into the shows dict in a format:
        shows[series_id][season_number][episode_number]
        """
        # Parse show information
        log.debug('Getting all series data for {0}', imdb_id)

        # Parse show information
        series_info = self._get_show_by_id(imdb_id)

        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(imdb_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(
            imdb_id, 'externals', {
                external_id: text_type(
                    getattr(self.shows[imdb_id], external_id, None))
                for external_id in ['tvdb_id', 'imdb_id', 'tvrage_id']
                if getattr(self.shows[imdb_id], external_id, None)
            })

        # get episode data
        if self.config['episodes_enabled']:
            self._get_episodes(imdb_id,
                               aired_season=self.config['limit_seasons'])

        # Parse banners
        if self.config['banners_enabled']:
            self._parse_images(imdb_id, language=language)

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

        return True
コード例 #5
0
    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