From 7bde7493ee3dcfb44225c13bf10d8e09f7328a2f Mon Sep 17 00:00:00 2001 From: twolaw Date: Sat, 12 Nov 2022 12:46:42 +0100 Subject: [PATCH] Add trakt official lists support (#1162) --- plextraktsync/sync.py | 2 +- plextraktsync/trakt_api.py | 2 +- plextraktsync/trakt_list_util.py | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plextraktsync/sync.py b/plextraktsync/sync.py index 1252f2a3ab..2592c3f159 100644 --- a/plextraktsync/sync.py +++ b/plextraktsync/sync.py @@ -131,7 +131,7 @@ def sync(self, walker: Walker, dry_run=False): if self.config.sync_liked_lists: for lst in self.trakt.liked_lists: - listutil.addList(lst["username"], lst["listname"]) + listutil.addList(lst["listid"], lst["listname"]) if self.config.need_library_walk: for movie in walker.find_movies(): diff --git a/plextraktsync/trakt_api.py b/plextraktsync/trakt_api.py index 2d147269dd..1f32efad99 100644 --- a/plextraktsync/trakt_api.py +++ b/plextraktsync/trakt_api.py @@ -135,7 +135,7 @@ def liked_lists(self): for item in self.me.get_liked_lists("lists", limit=1000): yield { 'listname': item['list']['name'], - 'username': item['list']['user']['ids']['slug'], + 'listid': item['list']['ids']['trakt'], } @cached_property diff --git a/plextraktsync/trakt_list_util.py b/plextraktsync/trakt_list_util.py index 6fefce00c5..eff1ace784 100644 --- a/plextraktsync/trakt_list_util.py +++ b/plextraktsync/trakt_list_util.py @@ -4,7 +4,7 @@ from trakt.core import get from trakt.errors import NotFoundException, OAuthException from trakt.users import UserList -from trakt.utils import extract_ids, slugify +from trakt.utils import extract_ids from plextraktsync.factory import logger @@ -12,7 +12,7 @@ class LazyUserList(UserList): @get def get_items(self): - data = yield f"users/{slugify(self.creator)}/lists/{self.slug}/items" + data = yield f"lists/{self.trakt}/items" for item in data: if "type" not in item: continue @@ -24,22 +24,23 @@ def get_items(self): @classmethod @get - def _get(cls, title, creator): - data = yield f"users/{slugify(creator)}/lists/{slugify(title)}" + def _get(cls, title, id): + data = yield f"lists/{id}" extract_ids(data) - ulist = LazyUserList(creator=creator, **data) + ulist = LazyUserList(creator=data['user']['username'], **data) ulist.get_items() yield ulist class TraktList: - def __init__(self, username, listname): + def __init__(self, listid, listname): self.name = listname self.plex_items = [] - if username is not None: + if listid is not None: + list_items = LazyUserList._get(listname, listid)._items prelist = [ (elem[0], elem[1]) - for elem in LazyUserList._get(listname, username)._items + for elem in list_items if elem[0] in ["movies", "episodes"] ] self.trakt_items = dict(zip(prelist, count(1))) @@ -81,17 +82,17 @@ class TraktListUtil: def __init__(self): self.lists = [] - def addList(self, username, listname, trakt_list=None): + def addList(self, listid, listname, trakt_list=None): if trakt_list is not None: self.lists.append(TraktList.from_trakt_list(listname, trakt_list)) logger.info(f"Downloaded List {listname}") return try: - self.lists.append(TraktList(username, listname)) + self.lists.append(TraktList(listid, listname)) logger.info(f"Downloaded List {listname}") except (NotFoundException, OAuthException): logger.warning( - f"Failed to get list {listname} by user {username}" + f"Failed to get list {listname} with id {listid}" ) def addPlexItemToLists(self, m):