From 1958dcb7b27f3543ce8dd87ee952281558a0dffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jan 2022 22:29:02 +0200 Subject: [PATCH 1/9] TVShow: Extract progress property body to _progress() method --- trakt/tv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trakt/tv.py b/trakt/tv.py index 9c60d9f1..c7eb5b67 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -295,6 +295,9 @@ def comments(self): self._comments.append(Comment(user=user, **com)) yield self._comments + def _progress(self, progress_type): + yield f'{self.ext}/progress/{progress_type}' + @property @get def progress(self): @@ -305,7 +308,7 @@ def progress(self): The next_episode will be the next episode the user should collect, if there are no upcoming episodes it will be set to null. """ - yield (self.ext + '/progress/collection') + return self._progress('collection') @property def crew(self): From b74a0b647e55c80ab263c9e4d6dd9027bf8de330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jan 2022 22:11:21 +0200 Subject: [PATCH 2/9] TVShow: Add specials parameter to _progress() method --- trakt/tv.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trakt/tv.py b/trakt/tv.py index c7eb5b67..cc5664d0 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -295,8 +295,12 @@ def comments(self): self._comments.append(Comment(user=user, **com)) yield self._comments - def _progress(self, progress_type): - yield f'{self.ext}/progress/{progress_type}' + def _progress(self, progress_type, specials=False): + uri = f'{self.ext}/progress/{progress_type}' + if specials: + uri += '?specials=true' + data = yield uri + yield data @property @get From c308ce1de197d639b1dae1ecb92575eadf733970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jan 2022 22:13:22 +0200 Subject: [PATCH 3/9] TVShow: Add collection_progress() method --- trakt/tv.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/trakt/tv.py b/trakt/tv.py index cc5664d0..6e076ff4 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -314,6 +314,21 @@ def progress(self): """ return self._progress('collection') + @get + def collection_progress(self, specials=False): + """ + collection progress for a show including details on all aired + seasons and episodes. + + The next_episode will be the next episode the user should collect, + if there are no upcoming episodes it will be set to null. + + specials: include specials as season 0 Example: false. + + https://trakt.docs.apiary.io/#reference/shows/collection-progress/get-show-collection-progress + """ + return self._progress('collection', specials) + @property def crew(self): """All of the crew members that worked on this :class:`TVShow`""" From 649a8661442f1e80af2c57d7c304e00ae8a4214e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jan 2022 22:15:28 +0200 Subject: [PATCH 4/9] TVShow: Add watched_progress() method --- trakt/tv.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trakt/tv.py b/trakt/tv.py index 6e076ff4..dec9f765 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -329,6 +329,18 @@ def collection_progress(self, specials=False): """ return self._progress('collection', specials) + @get + def watched_progress(self, specials=False): + """ + watched progress for a show including details on all aired seasons + and episodes. + + specials: include specials as season 0 Example: false. + + https://trakt.docs.apiary.io/#reference/shows/watched-progress/get-show-collection-progress + """ + return self._progress('watched', specials) + @property def crew(self): """All of the crew members that worked on this :class:`TVShow`""" From f234cd87b3b5782ba25f0334608f45526789049a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jan 2022 22:27:15 +0200 Subject: [PATCH 5/9] TVShow: Add collection_progress() testing --- tests/test_shows.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_shows.py b/tests/test_shows.py index 8f54819a..9d6784b1 100644 --- a/tests/test_shows.py +++ b/tests/test_shows.py @@ -129,6 +129,13 @@ def test_show_comment(): assert got.comment('Test Comment Data').get('comment') +def test_collection_progress(): + show = TVShow('Game of Thrones') + assert show.progress is None + assert show.collection_progress() is None + assert show.watched_progress() is None + + def test_rate_show(): got = TVShow('Game of Thrones') assert got.rate(10)['added'] == {'episodes': 2, 'movies': 1, 'seasons': 1, 'shows': 1} From ee435c5b328dc43e2383edde9f373371ce646eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 12 Jan 2022 14:55:06 +0200 Subject: [PATCH 6/9] TVShow: Add count_specials, hidden parameters to _progress --- trakt/tv.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trakt/tv.py b/trakt/tv.py index dec9f765..1b81de59 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -2,6 +2,8 @@ """Interfaces to all of the TV objects offered by the Trakt.tv API""" from collections import namedtuple from datetime import datetime, timedelta +from urllib.parse import urlencode + from trakt.core import Airs, Alias, Comment, Genre, delete, get from trakt.errors import NotFoundException from trakt.sync import (Scrobbler, rate, comment, add_to_collection, @@ -295,11 +297,22 @@ def comments(self): self._comments.append(Comment(user=user, **com)) yield self._comments - def _progress(self, progress_type, specials=False): + def _progress(self, progress_type, + specials=False, count_specials=False, hidden=False): uri = f'{self.ext}/progress/{progress_type}' + params = {} if specials: - uri += '?specials=true' + params['specials'] = 'true' + if count_specials: + params['count_specials'] = 'true' + if hidden: + params['hidden'] = 'true' + + if params: + uri += '?' + urlencode(params) + data = yield uri + yield data @property From af1b70dc36875814403af019f2f812c72aeb371a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 12 Jan 2022 14:59:35 +0200 Subject: [PATCH 7/9] TVShow: Add count_specials, hidden to watched_progress() and collection_progress() --- trakt/tv.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/trakt/tv.py b/trakt/tv.py index 1b81de59..b82f35ca 100644 --- a/trakt/tv.py +++ b/trakt/tv.py @@ -328,7 +328,7 @@ def progress(self): return self._progress('collection') @get - def collection_progress(self, specials=False): + def collection_progress(self, **kwargs): """ collection progress for a show including details on all aired seasons and episodes. @@ -336,23 +336,27 @@ def collection_progress(self, specials=False): The next_episode will be the next episode the user should collect, if there are no upcoming episodes it will be set to null. - specials: include specials as season 0 Example: false. + specials: include specials as season 0. Default: false. + count_specials: count specials in the overall stats. Default: false. + hidden: include any hidden seasons. Default: false. https://trakt.docs.apiary.io/#reference/shows/collection-progress/get-show-collection-progress """ - return self._progress('collection', specials) + return self._progress('collection', **kwargs) @get - def watched_progress(self, specials=False): + def watched_progress(self, **kwargs): """ watched progress for a show including details on all aired seasons and episodes. - specials: include specials as season 0 Example: false. + specials: include specials as season 0. Default: false. + count_specials: count specials in the overall stats. Default: false. + hidden: include any hidden seasons. Default: false. https://trakt.docs.apiary.io/#reference/shows/watched-progress/get-show-collection-progress """ - return self._progress('watched', specials) + return self._progress('watched', **kwargs) @property def crew(self): From f59e5606ac797aa3997403f8113748335955e3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 12 Jan 2022 19:40:39 +0200 Subject: [PATCH 8/9] Fix progress typo --- trakt/users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trakt/users.py b/trakt/users.py index 523b83d3..a17e2955 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -380,7 +380,7 @@ def show_collection(self): @property @get def watched_movies(self): - """Watched profess for all :class:`Movie`'s in this :class:`User`'s + """Watched progress for all :class:`Movie`'s in this :class:`User`'s collection. """ if self._watched_movies is None: @@ -398,7 +398,7 @@ def watched_movies(self): @property @get def watched_shows(self): - """Watched profess for all :class:`TVShow`'s in this :class:`User`'s + """Watched progress for all :class:`TVShow`'s in this :class:`User`'s collection. """ if self._watched_shows is None: From cc0be4afb3a87c3a484a92e1197ebd3074fb8c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 12 Jan 2022 15:44:21 +0200 Subject: [PATCH 9/9] Tests: Add mock data for progress/collection --- tests/mock_data/shows.json | 83 ++++++++++++++++++++++++++++++++++++++ tests/test_shows.py | 6 +-- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/tests/mock_data/shows.json b/tests/mock_data/shows.json index e98784c1..8d728987 100644 --- a/tests/mock_data/shows.json +++ b/tests/mock_data/shows.json @@ -149,6 +149,89 @@ {"username":"sean","private":false,"name":"Sean Rudford","vip":true,"vip_ep":false} ] }, + "shows/game-of-thrones/progress/collection": { + "GET": { + "aired": 2, + "completed": 2, + "last_collected_at": "2020-08-25T20:10:33.000Z", + "seasons": [ + { + "number": 1, + "title": null, + "aired": 2, + "completed": 2, + "episodes": [ + { + "number": 1, + "completed": true, + "collected_at": "2011-12-18T12:21:20.000Z" + }, + { + "number": 2, + "completed": true, + "collected_at": "2011-12-18T14:18:22.000Z" + } + ] + } + ], + "hidden_seasons": [], + "next_episode": null, + "last_episode": { + "season": 1, + "number": 1, + "title": "Winter Is Coming", + "ids": { + "trakt": 73640, + "tvdb": 3254641, + "imdb": "tt1480055", + "tmdb": 63056, + "tvrage": 1065008299 + } + } + } + }, + "shows/game-of-thrones/progress/watched": { + "GET": { + "aired": 2, + "completed": 0, + "last_watched_at": null, + "reset_at": null, + "seasons": [ + { + "number": 1, + "title": null, + "aired": 2, + "completed": 0, + "episodes": [ + { + "number": 1, + "completed": false, + "last_watched_at": null + }, + { + "number": 2, + "completed": false, + "last_watched_at": null + } + ] + } + ], + "hidden_seasons": [], + "next_episode": { + "season": 1, + "number": 1, + "title": "Winter Is Coming", + "ids": { + "trakt": 73640, + "tvdb": 3254641, + "imdb": "tt1480055", + "tmdb": 63056, + "tvrage": 1065008299 + } + }, + "last_episode": null + } + }, "shows/the-walking-dead?extended=full": { "GET": {"title":"The Walking Dead","year":2010,"ids":{"trakt":1393,"slug":"the-walking-dead","tvdb":153021,"imdb":"tt1520211","tmdb":1402,"tvrage":25056},"overview":"The world we knew is gone. An epidemic of apocalyptic proportions has swept the globe causing the dead to rise and feed on the living. In a matter of months society has crumbled. In a world ruled by the dead, we are forced to finally start living. Based on a comic book series of the same name by Robert Kirkman, this AMC project focuses on the world after a zombie apocalypse. The series follows a police officer, Rick Grimes, who wakes up from a coma to find the world ravaged with zombies. Looking for his family, he and a group of survivors attempt to battle against the zombies in order to stay alive.\n","first_aired":"2010-10-31T07:00:00.000Z","airs":{"day":"Sunday","time":"21:00","timezone":"America/New_York"},"runtime":60,"certification":"TV-MA","network":"AMC","country":"us","trailer":"http://youtube.com/watch?v=R1v0uFms68U","homepage":"http://www.amctv.com/shows/the-walking-dead/","status":"returning series","rating":8.62829,"votes":34161,"updated_at":"2016-04-24T10:50:26.000Z","language":"en","available_translations":["en","de","sv","it","pt","tr","ru","zh","fr","es","nl","pl","bg","el","hu","ja","he","da","cs","ko","cn","bs","hr","fa","lt","lv","ro","sr","vi","et","uk","fi","th","id","ms"],"genres":["drama","action","horror","suspense"],"aired_episodes":83} } diff --git a/tests/test_shows.py b/tests/test_shows.py index 9d6784b1..2ec24078 100644 --- a/tests/test_shows.py +++ b/tests/test_shows.py @@ -131,9 +131,9 @@ def test_show_comment(): def test_collection_progress(): show = TVShow('Game of Thrones') - assert show.progress is None - assert show.collection_progress() is None - assert show.watched_progress() is None + assert isinstance(show.progress, dict) + assert isinstance(show.collection_progress(), dict) + assert isinstance(show.watched_progress(), dict) def test_rate_show():