Skip to content

Commit

Permalink
Merge pull request #1734 from glensc/TraktPlayable
Browse files Browse the repository at this point in the history
Add TraktPlayable type
  • Loading branch information
glensc authored Jan 15, 2024
2 parents 7d8a05f + 214ed8e commit 96801df
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plextraktsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from plextraktsync.decorators.measure_time import measure_time
from plextraktsync.factory import logger
from plextraktsync.trakt.TraktUserListCollection import TraktUserListCollection
from plextraktsync.trakt.types import TraktMedia
from plextraktsync.trakt_list_util import TraktListUtil

if TYPE_CHECKING:
Expand All @@ -17,6 +16,7 @@
from plextraktsync.plan.Walker import Walker
from plextraktsync.plex.PlexApi import PlexApi
from plextraktsync.trakt.TraktApi import TraktApi
from plextraktsync.trakt.types import TraktMedia


class Sync:
Expand Down
6 changes: 2 additions & 4 deletions plextraktsync/trakt/ScrobblerCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from plextraktsync.trakt.ScrobblerProxy import ScrobblerProxy

if TYPE_CHECKING:
from plexapi.video import Movie
from trakt.tv import TVEpisode

from plextraktsync.trakt.TraktApi import TraktApi
from plextraktsync.trakt.types import TraktPlayable


class ScrobblerCollection(UserDict):
Expand All @@ -18,7 +16,7 @@ def __init__(self, trakt: TraktApi, threshold=80):
self.trakt = trakt
self.threshold = threshold

def __missing__(self, media: Movie | TVEpisode):
def __missing__(self, media: TraktPlayable):
scrobbler = media.scrobble(0, None, None)
proxy = ScrobblerProxy(scrobbler, self.threshold)
self[media] = proxy
Expand Down
8 changes: 3 additions & 5 deletions plextraktsync/trakt/TraktUserList.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from typing import TYPE_CHECKING

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

if TYPE_CHECKING:
from trakt.movies import Movie
from trakt.tv import TVEpisode

from plextraktsync.media import Media
from plextraktsync.plex.PlexLibraryItem import PlexLibraryItem

Expand Down Expand Up @@ -63,13 +61,13 @@ def load_items(self):
return userlist.description, dict(zip(prelist, count(1)))

@classmethod
def from_trakt_list(cls, name: str, items: list[Movie, TVEpisode]):
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))

@classmethod
def from_watchlist(cls, items: list[Movie, TVEpisode]):
def from_watchlist(cls, items: list[TraktPlayable]):
trakt_items = dict(
zip([(elem.media_type, elem.trakt) for elem in items], count(1))
)
Expand Down
7 changes: 2 additions & 5 deletions plextraktsync/trakt/TraktUserListCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
from plextraktsync.trakt.TraktUserList import TraktUserList

if TYPE_CHECKING:
from trakt.movies import Movie
from trakt.tv import TVEpisode

from plextraktsync.media import Media
from plextraktsync.trakt.types import TraktLikedList
from plextraktsync.trakt.types import TraktLikedList, TraktPlayable


class TraktUserListCollection(UserList):
Expand All @@ -31,7 +28,7 @@ def load_lists(self, liked_lists: list[TraktLikedList]):
for liked_list in liked_lists:
self.add_list(liked_list["listid"], liked_list["listname"])

def add_watchlist(self, items: list[Movie, TVEpisode]):
def add_watchlist(self, items: list[TraktPlayable]):
tl = TraktUserList.from_watchlist(items)
self.append(tl)
return tl
Expand Down
1 change: 1 addition & 0 deletions plextraktsync/trakt/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trakt.tv import TVEpisode, TVSeason, TVShow

TraktMedia = Union[Movie, TVShow, TVSeason, TVEpisode]
TraktPlayable = Union[Movie, TVEpisode]


class TraktLikedList(TypedDict):
Expand Down

0 comments on commit 96801df

Please sign in to comment.