Beispiel #1
0
    def _parse_actors(self, tmdb_id):
        """Parse actors XML."""
        log.debug('Getting actors for {0}', tmdb_id)

        # TMDB also support passing language here as a param.
        try:
            credits = self.tmdb.TV(tmdb_id).credits(
                language=self.config['language'])  # pylint: disable=W0622
        except RequestException as error:
            raise IndexerException(
                'Could not get actors. Cause: {cause}'.format(cause=error))

        if not credits or not credits.get('cast'):
            log.debug('Actors result returned zero')
            return

        cur_actors = Actors()
        for cur_actor in credits.get('cast'):
            new_actor = Actor()
            new_actor['id'] = cur_actor['credit_id']
            new_actor['image'] = \
                '{base_url}{image_size}{profile_path}'.format(base_url=self.tmdb_configuration.images['base_url'],
                                                              image_size='original',
                                                              profile_path=cur_actor['profile_path'])
            new_actor['name'] = cur_actor['name']
            new_actor['role'] = cur_actor['character']
            new_actor['sortorder'] = cur_actor['order']
            cur_actors.append(new_actor)
        self._set_show_data(tmdb_id, '_actors', cur_actors)
Beispiel #2
0
    def _parse_actors(self, sid):
        """Parser actors JSON.

        From http://www.glotz.info/api/[APIKEY]/series/[SERIES ID]/actors.json
        Actors are retrieved using t['show name]['_actors'].
        """
        log.debug('Getting actors for {0}', sid)

        try:
            _actors = self.glotz_api.get_actors_list(sid)
        except ActorNotFound:
            log.debug('Actors result returned zero')
            return
        except IndexerError as error:
            log.info('Could not get actors for show ID: {0} with reason: {1}', sid, error)
            return

        cur_actors = Actors()
        for cur_actor in _actors if isinstance(_actors, list) else [_actors]:
            new_actor = Actor()
            new_actor['id'] = cur_actor.id
            new_actor['image'] = self.config['artwork_prefix'].format(image=cur_actor.image)
            new_actor['name'] = cur_actor.name
            new_actor['role'] = cur_actor.role
            new_actor['sortorder'] = cur_actor.sort_order
            cur_actors.append(new_actor)
        self._set_show_data(sid, '_actors', cur_actors)
Beispiel #3
0
    def _parse_actors(self, sid):
        """Parser actors XML.

        From http://thetvdb.com/api/[APIKEY]/series/[SERIES ID]/actors.xml
        Actors are retrieved using t['show name]['_actors'], for example:

        >>> indexer_api = Tvdb(actors = True)
        >>> actors = indexer_api['scrubs']['_actors']
        >>> type(actors)
        <class 'tvdb_api.Actors'>
        >>> type(actors[0])
        <class 'tvdb_api.Actor'>
        >>> actors[0]
        <Actor "Zach Braff">
        >>> sorted(actors[0].keys())
        ['id', 'image', 'name', 'role', 'sortorder']
        >>> actors[0]['name']
        u'Zach Braff'
        >>> actors[0]['image']
        u'http://thetvdb.com/banners/actors/43640.jpg'

        Any key starting with an underscore has been processed (not the raw
        data from the XML)
        """
        log.debug('Getting actors for {0}', sid)

        try:
            actors = self.config['session'].series_api.series_id_actors_get(
                sid)
        except ApiException as error:
            log.info('Could not get actors for show ID: {0} with reason: {1}',
                     sid, error.reason)
            return

        if not actors or not actors.data:
            log.debug('Actors result returned zero')
            return

        cur_actors = Actors()
        for cur_actor in actors.data if isinstance(actors.data,
                                                   list) else [actors.data]:
            new_actor = Actor()
            new_actor['id'] = cur_actor.id
            new_actor['image'] = self.config['artwork_prefix'].format(
                image=cur_actor.image)
            new_actor['name'] = cur_actor.name
            new_actor['role'] = cur_actor.role
            new_actor['sortorder'] = 0
            cur_actors.append(new_actor)
        self._set_show_data(sid, '_actors', cur_actors)
Beispiel #4
0
    def _parse_actors(self, tvmaze_id):
        """Parsers actors XML, from
        http://thetvmaze.com/api/[APIKEY]/series/[SERIES ID]/actors.xml

        Actors are retrieved using t['show name]['_actors'], for example:

        >>> indexer_api = TVMaze(actors = True)
        >>> actors = indexer_api['scrubs']['_actors']
        >>> type(actors)
        <class 'tvmaze_api.Actors'>
        >>> type(actors[0])
        <class 'tvmaze_api.Actor'>
        >>> actors[0]
        <Actor "Zach Braff">
        >>> sorted(actors[0].keys())
        ['id', 'image', 'name', 'role', 'sortorder']
        >>> actors[0]['name']
        u'Zach Braff'
        >>> actors[0]['image']
        u'http://thetvmaze.com/banners/actors/43640.jpg'

        Any key starting with an underscore has been processed (not the raw
        data from the indexer)
        """
        log.debug('Getting actors for {0}', tvmaze_id)
        try:
            actors = self.tvmaze_api.show_cast(tvmaze_id)
        except CastNotFound:
            log.debug('Actors result returned zero')
            return
        except BaseError as e:
            log.warning('Getting actors failed. Cause: {0}', e)
            return

        cur_actors = Actors()
        for order, cur_actor in enumerate(actors.people):
            save_actor = Actor()
            save_actor['id'] = cur_actor.id
            save_actor['image'] = cur_actor.image.get(
                'original') if cur_actor.image else ''
            save_actor['name'] = cur_actor.name
            save_actor['role'] = cur_actor.character.name
            save_actor['sortorder'] = order
            cur_actors.append(save_actor)
        self._set_show_data(tvmaze_id, '_actors', cur_actors)
Beispiel #5
0
    def _parse_actors(self, imdb_id):
        """Get and parse actors using the get_title_credits route.

        Actors are retrieved using t['show name]['_actors'].

        Any key starting with an underscore has been processed (not the raw
        data from the indexer)
        """
        log.debug('Getting actors for {0}', imdb_id)

        try:
            actors = self.imdb_api.get_title_credits(
                ImdbIdentifier(imdb_id).imdb_id)
        except LookupError as error:
            raise IndexerShowNotFound(
                'Could not find show {imdb_id} using indexer Imdb. Cause: {cause!r}'
                .format(imdb_id=imdb_id, cause=error))
        except (AttributeError, RequestException) as error:
            raise IndexerUnavailable(
                'Could not get actors for show {imdb_id} using indexer Imdb. Cause: {cause!r}'
                .format(imdb_id=imdb_id, cause=error))

        if not actors.get('credits') or not actors['credits'].get('cast'):
            return

        cur_actors = Actors()
        for order, cur_actor in enumerate(actors['credits']['cast'][:25]):
            save_actor = Actor()
            save_actor['id'] = cur_actor['id'].split('/')[-2]
            save_actor['image'] = cur_actor.get('image', {}).get('url', None)
            save_actor['name'] = cur_actor['name']
            save_actor['role'] = cur_actor['characters'][0] if cur_actor.get(
                'characters') else ''
            save_actor['sortorder'] = order
            cur_actors.append(save_actor)
        self._set_show_data(imdb_id, '_actors', cur_actors)