From b6b362845db34d3b640102d79c75a50dfd2999ab Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sun, 30 Apr 2023 09:15:38 +0100 Subject: [PATCH] =?UTF-8?q?Update=20Pytvmaze=20library=202.0.8=20(16ed096)?= =?UTF-8?q?=20=E2=86=92=202.0.8=20(81888a5).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 1 + lib/pytvmaze/endpoints.py | 3 +++ lib/pytvmaze/tvmaze.py | 55 +++++++++++++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ee558d5d..a94b40b2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ * Update feedparser 6.0.10 (5fcb3ae) to 6.0.10 (6d032b8) * Update filelock 3.9.0 (ce3e891) to 3.11.0 (d3241b9) * Update Msgpack 1.0.4 (b5acfd5) to 1.0.5 (0516c2c) +* Update Pytvmaze library 2.0.8 (16ed096) to 2.0.8 (81888a5) * Update Requests library 2.28.1 (ec553c2) to 2.29.0 (87d63de) * Update SimpleJSON 3.18.1 (c891b95) to 3.19.1 (aeb63ee) * Update Tornado Web Server 6.3.0 (7186b86) to 6.3.1 (419838b) diff --git a/lib/pytvmaze/endpoints.py b/lib/pytvmaze/endpoints.py index bb4566cf..b1405faf 100644 --- a/lib/pytvmaze/endpoints.py +++ b/lib/pytvmaze/endpoints.py @@ -17,6 +17,7 @@ show_index = 'https://api.tvmaze.com/shows?page={0}' people_search = 'https://api.tvmaze.com/search/people?q={0}' person_main_info = 'https://api.tvmaze.com/people/{0}' person_cast_credits = 'https://api.tvmaze.com/people/{0}/castcredits' +person_guestcast_credits = 'https://api.tvmaze.com/people/{0}/guestcastcredits' person_crew_credits = 'https://api.tvmaze.com/people/{0}/crewcredits' show_crew = 'https://api.tvmaze.com/shows/{0}/crew' show_updates = 'https://api.tvmaze.com/updates/shows' @@ -24,6 +25,8 @@ show_akas = 'https://api.tvmaze.com/shows/{0}/akas' show_seasons = 'https://api.tvmaze.com/shows/{0}/seasons' season_by_id = 'https://api.tvmaze.com/seasons/{0}' episode_by_id = 'https://api.tvmaze.com/episodes/{0}' +episode_guestcast = 'https://api.tvmaze.com/episodes/{0}/guestcast' +episode_guestcrew = 'https://api.tvmaze.com/episodes/{0}/guestcrew' show_images = 'https://api.tvmaze.com/shows/{0}/images' # TVmaze Premium endpoints diff --git a/lib/pytvmaze/tvmaze.py b/lib/pytvmaze/tvmaze.py index 7fe03db2..23931de5 100644 --- a/lib/pytvmaze/tvmaze.py +++ b/lib/pytvmaze/tvmaze.py @@ -287,9 +287,12 @@ class Episode(object): if data.get('show'): self.show = Show(data.get('show')) # Reference to show for when using get_full_schedule() - if data.get('_embedded'): + if not self.show and data.get('_embedded'): if data['_embedded'].get('show'): self.show = Show(data['_embedded']['show']) + if not self.show and data.get('_links') and 'show' in data['_links']: + self.show = Show({}) + self.show.id = int(re.search(r'/(\d+)$', data['_links']['show']['href']).group(1)) def __repr__(self): if self.special: @@ -345,6 +348,7 @@ class Person(object): self.country = data.get('country') self.character = None self._castcredits = None + self._guestcastcredits = None self._crewcredits = None # self.populate(data) @@ -363,6 +367,12 @@ class Person(object): self._castcredits = person_cast_credits(self.id, embed='show,character', raise_error=False) return self._castcredits + @property + def guestcastcredits(self): + if None is self._guestcastcredits: + self._guestcastcredits = person_guestcast_credits(self.id, embed='episode,character', raise_error=False) + return self._guestcastcredits + @property def crewcredits(self): if None is self._crewcredits: @@ -451,8 +461,9 @@ class Cast(object): class CastCredit(object): def __init__(self, data): self.links = data.get('_links') - self.character = None - self.show = None + self.character = None # type: Optional[Character] + self.show = None # type: Optional[Show] + self.episode = None # type: Optional[Episode] self.populate(data) def populate(self, data): @@ -461,6 +472,8 @@ class CastCredit(object): self.character = Character(data['_embedded']['character']) if data['_embedded'].get('show'): self.show = Show(data['_embedded']['show']) + if data['_embedded'].get('episode'): + self.episode = Episode(data['_embedded']['episode']) def __repr__(self): return self.__str__() @@ -1437,6 +1450,17 @@ def person_cast_credits(person_id, embed=None, raise_error=True): return [] +def person_guestcast_credits(person_id, embed=None, raise_error=True): + url = _embed_url(endpoints.person_guestcast_credits.format(person_id), embed, + [None, 'episode', 'character'], '?') + q = TVmaze.endpoint_standard_get(url) + if q: + return [CastCredit(credit) for credit in q] + elif raise_error: + raise CreditsNotFound('Couldn\'t find cast credits for person ID {0}'.format(person_id)) + return [] + + def person_crew_credits(person_id, embed=None, raise_error=True): url = _embed_url(endpoints.person_crew_credits.format(person_id), embed, [None, 'show'], '?') @@ -1518,10 +1542,31 @@ def season_by_id(season_id, embed=None): raise SeasonNotFound('Couldn\'t find Season with ID {0}'.format(season_id)) -def episode_by_id(episode_id, show=None, raise_error=True): - url = endpoints.episode_by_id.format(episode_id) +def episode_by_id(episode_id, show=None, raise_error=True, embed=None): + url = _embed_url(endpoints.episode_by_id.format(episode_id), embed, + [None, 'show', 'guestcast', 'guestcrew'], '?') q = TVmaze.endpoint_standard_get(url) if q: return Episode(q, show=show) elif raise_error: raise EpisodeNotFound('Couldn\'t find Episode with ID {0}'.format(episode_id)) + + +def episode_guestcast_credits(episode_id, raise_error=True): + url = endpoints.episode_guestcast.format(episode_id) + q = TVmaze.endpoint_standard_get(url) + if q: + return [CastCredit(credit) for credit in q] + elif raise_error: + raise CreditsNotFound('Couldn\'t find cast credits for episode ID {0}'.format(episode_id)) + return [] + + +def episode_crew_credits(episode_id, raise_error=True): + url = endpoints.episode_guestcrew.format(episode_id) + q = TVmaze.endpoint_standard_get(url) + if q: + return [CrewCredit(credit) for credit in q] + elif raise_error: + raise CreditsNotFound('Couldn\'t find crew credits for episode ID {0}'.format(episode_id)) + return []