Skip to content

Commit

Permalink
Merge pull request #711 from glensc/pytrakt/shows/progress
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Oct 23, 2022
2 parents aeb59d2 + f980212 commit d51020d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ oauthlib = "==3.2.2"
plexapi = "==4.13.0"
python-dotenv = "==0.21.0"
python-git-info = "==0.8.0"
pytrakt = "==3.4.5"
pytrakt = "==3.4.7"
pyyaml = "==6.0"
requests = ">=2.25.1"
requests-cache = "==0.9.6"
Expand Down
8 changes: 4 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions plextraktsync/pytrakt_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ def allcollected():
yield AllShowsProgress(data)


@get
def watched(show_id):
# returns a ShowProgress object containing the watched states of the passed show
data = yield "shows/{}/progress/watched?specials=true".format(show_id)
yield ShowProgress(**data)


@get
def collected(show_id):
# returns a ShowProgress object containing the collected states of the passed show
data = yield "shows/{}/progress/collection?specials=true".format(show_id)
yield ShowProgress(**data)


class EpisodeProgress:
def __init__(
self,
Expand Down
4 changes: 3 additions & 1 deletion plextraktsync/trakt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from plextraktsync.factory import factory, logger, logging
from plextraktsync.path import pytrakt_file
from plextraktsync.plex_api import PlexGuid, PlexLibraryItem
from plextraktsync.pytrakt_extensions import ShowProgress


class ScrobblerProxy:
Expand Down Expand Up @@ -311,7 +312,8 @@ def remove_from_watchlist(self, m, batch=False):
@rate_limit()
@retry()
def collected(self, tm: TVShow):
return pytrakt_extensions.collected(tm.trakt)
data = tm.collection_progress(specials=True)
return ShowProgress(**data)

def find_by_guid(self, guid: PlexGuid):
if guid.type == "episode" and guid.is_episode:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ prompt-toolkit==3.0.31; python_full_version >= '3.6.2'
pygments==2.13.0; python_version >= '3.6'
python-dotenv==0.21.0
python-git-info==0.8.0
pytrakt==3.4.5
pytrakt==3.4.7
pyyaml==6.0
requests-cache==0.9.6
requests-oauthlib==1.3.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
Expand Down
31 changes: 31 additions & 0 deletions tests/test_trakt_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3 -m pytest
from trakt.tv import TVShow

from plextraktsync.pytrakt_extensions import ShowProgress
from plextraktsync.trakt_api import TraktApi
from tests.conftest import factory

trakt: TraktApi = factory.trakt_api()


def test_trakt_collection_progress():
show = TVShow('Game of Thrones')
collected = trakt.collected(show)
assert isinstance(collected, ShowProgress)
s01e01 = collected.get_completed(1, 1)
assert isinstance(s01e01, bool)


def test_trakt_watched_progress():
show = TVShow('Game of Thrones')
data = show.watched_progress()
watched = ShowProgress(**data)

assert isinstance(watched, ShowProgress)
s01e01 = watched.get_completed(1, 1)
assert isinstance(s01e01, bool)


if __name__ == '__main__':
test_trakt_collection_progress()
test_trakt_watched_progress()

0 comments on commit d51020d

Please sign in to comment.