Skip to content

Commit

Permalink
TVShow: Use /seasons endpoint to fill seasons and episodes
Browse files Browse the repository at this point in the history
This will make one api request to create list of
TVSeason with TVEpisode objects.
  • Loading branch information
glensc committed Jan 15, 2022
1 parent 9d46799 commit bb77719
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions trakt/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,23 @@ def related(self):
@get
def seasons(self):
"""A list of :class:`TVSeason` objects representing all of this show's
seasons
seasons which each contain :class:`TVEpisode` elements
"""
if self._seasons is None:
data = yield self.ext + '/seasons?extended=full'
data = yield self.ext + '/seasons?extended=episodes'
self._seasons = []
for season in data:
extract_ids(season)
self._seasons.append(TVSeason(self.title,
season['number'], **season))

# Prepare episodes
episodes = []
for ep in season.pop('episodes', []):
episode = TVEpisode(show=self.title, **ep)
episodes.append(episode)
season['episodes'] = episodes

season = TVSeason(self.title, season['number'], **season)
self._seasons.append(season)
yield self._seasons

@property
Expand Down

0 comments on commit bb77719

Please sign in to comment.