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)
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!r}', sid, error) 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)
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)