Skip to content

Commit

Permalink
Merge pull request #1843 from glensc/use-PublicList
Browse files Browse the repository at this point in the history
Refactor to use PublicList class
  • Loading branch information
glensc authored Mar 11, 2024
2 parents 39e7ad7 + c151d49 commit cbac241
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
26 changes: 11 additions & 15 deletions plextraktsync/trakt/TraktUserList.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from itertools import count
from typing import TYPE_CHECKING

from trakt.users import PublicList

from plextraktsync.factory import factory, logging
from plextraktsync.trakt.types import TraktPlayable

Expand Down Expand Up @@ -44,25 +46,19 @@ def items(self):
self.description, self._items = self.load_items()
return self._items

def load_items(self):
from plextraktsync.trakt_list_util import LazyUserList
@staticmethod
def build_dict(pl: PublicList):
return {(f"{le.type}s", le.trakt): le.rank for le in pl if le.type in ["movie", "episode"]}

userlist = LazyUserList._get(self.name, self.trakt_id)
list_items = userlist._items
prelist = [
(elem[0], elem[1])
for elem in list_items
if elem[0] in ["movies", "episodes"]
]
self.logger.info(f"Downloaded Trakt list '{self.name}' ({len(list_items)} items): https://trakt.tv/lists/{self.trakt_id}")
def load_items(self):
pl = PublicList.load(self.trakt_id)
self.logger.info(f"Downloaded Trakt list '{pl.name}' ({len(pl)} items): {pl.share_link}")

return userlist.description, dict(zip(prelist, count(1)))
return pl.description, self.build_dict(pl)

@classmethod
def from_trakt_list(cls, name: str, items: list[TraktPlayable]):
items = zip([(item.media_type, item.trakt) for item in items], count(1))

return cls(name=name, items=dict(items))
def from_trakt_list(cls, list_id: int, list_name: str):
return cls(trakt_id=list_id, name=list_name)

@classmethod
def from_watchlist(cls, items: list[TraktPlayable]):
Expand Down
2 changes: 1 addition & 1 deletion plextraktsync/trakt/TraktUserListCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def add_watchlist(self, items: list[TraktPlayable]):
return tl

def add_list(self, list_id: int, list_name: str):
tl = TraktUserList(list_id, list_name)
tl = TraktUserList.from_trakt_list(list_id, list_name)
self.append(tl)
return tl

Expand Down
25 changes: 0 additions & 25 deletions plextraktsync/trakt_list_util.py

This file was deleted.

0 comments on commit cbac241

Please sign in to comment.