Skip to content

Commit

Permalink
Merge branch 'shows/progress'
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Oct 23, 2022
2 parents dece4d0 + cc0be4a commit e1c4be0
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 3 deletions.
83 changes: 83 additions & 0 deletions tests/mock_data/shows.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_shows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 isinstance(show.progress, dict)
assert isinstance(show.collection_progress(), dict)
assert isinstance(show.watched_progress(), dict)


def test_rate_show():
got = TVShow('Game of Thrones')
assert got.rate(10)['added'] == {'episodes': 2, 'movies': 1, 'seasons': 1, 'shows': 1}
Expand Down
53 changes: 52 additions & 1 deletion trakt/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -295,6 +297,24 @@ def comments(self):
self._comments.append(Comment(user=user, **com))
yield self._comments

def _progress(self, progress_type,
specials=False, count_specials=False, hidden=False):
uri = f'{self.ext}/progress/{progress_type}'
params = {}
if specials:
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
@get
def progress(self):
Expand All @@ -305,7 +325,38 @@ 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')

@get
def collection_progress(self, **kwargs):
"""
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. 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', **kwargs)

@get
def watched_progress(self, **kwargs):
"""
watched progress for a show including details on all aired seasons
and episodes.
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', **kwargs)

@property
def crew(self):
Expand Down
4 changes: 2 additions & 2 deletions trakt/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,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:
Expand All @@ -399,7 +399,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:
Expand Down

0 comments on commit e1c4be0

Please sign in to comment.