Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trakt official lists support #1162

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plextraktsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion plextraktsync/trakt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions plextraktsync/trakt_list_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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


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
Expand All @@ -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)))
Expand Down Expand Up @@ -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):
Expand Down