Skip to content

Commit

Permalink
Merge pull request #155 from moogar0880/correct-tvshow-slug-generation
Browse files Browse the repository at this point in the history
ensure TVShow slugs respect the year when necessary #154
  • Loading branch information
moogar0880 authored Aug 9, 2021
2 parents 320f9f1 + 4a10bd7 commit 033f2ed
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release History
^^^^^^^^^^^^^^^

3.2.1 (2021-08-08)
+++++++++++++++++++

* Fix an issue when accessing the `seasons` property of a `TVShow` instance whose slug requires a year

3.2.0 (2021-06-21)
+++++++++++++++++++

Expand Down
9 changes: 9 additions & 0 deletions tests/mock_data/seasons.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
{"number":4,"ids":{"trakt":5,"tvdb":522882,"tmdb":3628,"tvrage":null}}
]
},
"shows/the-flash-2014/seasons?extended=full": {
"GET": [
{"number":0,"ids":{"trakt":1,"tvdb":137481,"tmdb":3627,"tvrage":null}},
{"number":1,"ids":{"trakt":2,"tvdb":364731,"tmdb":3624,"tvrage":null}},
{"number":2,"ids":{"trakt":3,"tvdb":473271,"tmdb":3625,"tvrage":null}},
{"number":3,"ids":{"trakt":4,"tvdb":488434,"tmdb":3626,"tvrage":null}},
{"number":4,"ids":{"trakt":5,"tvdb":522882,"tmdb":3628,"tvrage":null}}
]
},
"shows/game-of-thrones/seasons?extended=images": {
"GET": [
{"number":0,"ids":{"trakt":1,"tvdb":137481,"tmdb":3627,"tvrage":null},"images":{"poster":{"full":"https://walter.trakt.us/images/seasons/000/002/145/posters/original/41221f3712.jpg?1409351965","medium":"https://walter.trakt.us/images/seasons/000/002/145/posters/medium/41221f3712.jpg?1409351965","thumb":"https://walter.trakt.us/images/seasons/000/002/145/posters/thumb/41221f3712.jpg?1409351965"},"thumb":{"full":"https://walter.trakt.us/images/seasons/000/002/145/thumbs/original/c41b46dd09.jpg?1409351965"}}},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def test_get_seasons():
assert all([isinstance(s, TVSeason) for s in got.seasons])


def test_get_seasons_with_year():
got = TVShow('The Flash', year=2014)
assert all([isinstance(s, TVSeason) for s in got.seasons])


def test_get_season():
s1 = TVSeason('Game of Thrones', season=1)
assert isinstance(s1, TVSeason)
Expand Down
2 changes: 1 addition & 1 deletion trakt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
except ImportError:
pass

version_info = (3, 2, 0)
version_info = (3, 2, 1)
__author__ = 'Jon Nappi'
__version__ = '.'.join([str(i) for i in version_info])
13 changes: 12 additions & 1 deletion trakt/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,24 @@ def __init__(self, title='', slug=None, **kwargs):
self._images = self._people = self._ratings = self._translations = None
self._seasons = None
self._last_episode = self._next_episode = None
self._slug = slug
self.title = title
self.slug = slug or slugify(self.title)

if len(kwargs) > 0:
self._build(kwargs)
else:
self._get()

@property
def slug(self):
if self._slug is not None:
return self._slug

if self.year is None:
return slugify(self.title)

return slugify(self.title + ' ' + str(self.year))

@classmethod
def search(cls, title, year=None):
"""Perform a search for the specified *title*.
Expand Down

0 comments on commit 033f2ed

Please sign in to comment.