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

Feature: Add keep watched to liked lists #1832

Merged
merged 27 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a54a0cf
Add simplified type fort SyncConfig.config
glensc Mar 10, 2024
8830328
Add liked_list top level default config
glensc Mar 10, 2024
27fe892
Add example liked list overrides to default config
glensc Apr 30, 2024
0b5ce50
Add liked_lists_keep_watched SyncConfig property
glensc Feb 23, 2024
a8ac4a1
Add keep_watched property to TraktUserListCollection
glensc Feb 23, 2024
6064b87
Configure keep_watched for TraktUserListCollection
glensc Feb 23, 2024
3ff8c6b
Filter liked list items with keep_watched. XXX
glensc Feb 23, 2024
26f37c9
Add keep_watched to TraktListsPlugin
glensc Apr 30, 2024
ca89cdf
Check keep_watched in TraktListsPlugin
glensc Apr 30, 2024
a632e53
tl.plex_items_sorted is method
glensc Apr 30, 2024
3b77aca
Cleanup superfluous sync from TraktUserListCollection
glensc Apr 30, 2024
ca94424
Cleanup keep_watched from TraktUserListCollection
glensc Apr 30, 2024
155fd07
Add trakt_lists_config to TraktListsPlugin
glensc Apr 30, 2024
7dc0008
Add list_keep_watched method
glensc Apr 30, 2024
a87720b
Check per list keep_watched setting
glensc Apr 30, 2024
f93e87f
Load overrides from overrides section
glensc Apr 30, 2024
e6b995e
Add liked_lists_overrides SyncConfig
glensc May 1, 2024
7d88991
Use liked_lists_overrides config
glensc May 1, 2024
abd6c7b
Add keep_watched, trakt_lists_overrides to TraktUserListCollection
glensc May 1, 2024
dac207a
Add keep_watched to TraktUserList
glensc May 1, 2024
52d6fee
Add keep watched from config to TraktUserList
glensc May 1, 2024
da6613e
Use keep_watched from list property
glensc May 1, 2024
e2617ed
Undo keep_watched check in the plugin
glensc May 1, 2024
34326a9
Cleanup keep_watched from plugin
glensc May 1, 2024
0ad29b4
Skip adding watched items
glensc May 1, 2024
788b26f
Use liked_list for overrides
glensc May 1, 2024
b0664a3
Keep plex_items_sorted as property
glensc Jun 11, 2024
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
10 changes: 10 additions & 0 deletions plextraktsync/config.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ sync:
# Sync Play Progress from Trakt to Plex
playback_status: false

# Configuration for liked lists
liked_lists:
# Whether to keep watched items in the list
keep_watched: true

# Configuration override for specific lists
#liked_list:
# "Saw Collection":
# keep_watched: true

# settings for 'watch' command
watch:
add_collection: false
Expand Down
10 changes: 10 additions & 0 deletions plextraktsync/config/SyncConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any

from plextraktsync.config.Config import Config
from plextraktsync.config.PlexServerConfig import PlexServerConfig


class SyncConfig:
config: dict[str, Any]

def __init__(self, config: Config, server_config: PlexServerConfig):
self.config = dict(config["sync"])
self.liked_lists = config["liked_lists"]
self.liked_lists_overrides = config["liked_list"] or {}
self.server_config = server_config.sync_config

def __getitem__(self, key):
Expand Down Expand Up @@ -61,6 +67,10 @@ def sync_watched_status(self):
self.trakt_to_plex["watched_status"] or self.plex_to_trakt["watched_status"]
)

@property
def liked_lists_keep_watched(self):
return self.liked_lists["keep_watched"]

@cached_property
def sync_playback_status(self):
return self["trakt_to_plex"]["playback_status"]
Expand Down
5 changes: 4 additions & 1 deletion plextraktsync/sync/Sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi):

@cached_property
def trakt_lists(self):
return TraktUserListCollection()
return TraktUserListCollection(
self.config.liked_lists_keep_watched,
self.config.liked_lists_overrides,
)

@cached_property
def pm(self):
Expand Down
19 changes: 16 additions & 3 deletions plextraktsync/trakt/TraktUserList.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def __init__(
trakt_id: int = None,
name: str = None,
items=None,
keep_watched: bool = None,
):
self.trakt_id = trakt_id
self.name = name
self._items = items
self.description = None
self.plex_items = []
self.keep_watched = keep_watched

def __iter__(self):
return iter(self.items)
Expand Down Expand Up @@ -64,8 +66,8 @@ def load_items(self):
return pl.description, self.build_dict(pl)

@classmethod
def from_trakt_list(cls, list_id: int, list_name: str):
return cls(trakt_id=list_id, name=list_name)
def from_trakt_list(cls, list_id: int, list_name: str, keep_watched: bool):
return cls(trakt_id=list_id, name=list_name, keep_watched=keep_watched)

@classmethod
def from_watchlist(cls, items: list[TraktPlayable]):
Expand Down Expand Up @@ -98,6 +100,10 @@ def add(self, m: Media):
# Already in the list
return

if not self.keep_watched and m.plex.is_watched:
# Skip adding watched items
return

self.logger.info(
f"Adding {m.title_link} ({m.plex_key}) to Plex list {self.title_link}",
extra={"markup": True},
Expand Down Expand Up @@ -128,7 +134,14 @@ def plex_items_sorted(self):
if len(self.plex_items) == 0:
return []

plex_items = [(r, p.item) for (r, p) in self.plex_items]
plex_items = [
(r, p.item)
for (r, p) in self.plex_items
if self.keep_watched or (not self.keep_watched and not p.is_watched)
]
if len(plex_items) == 0:
return []

_, items = zip(*sorted(dict(reversed(plex_items)).items()))

return items
9 changes: 8 additions & 1 deletion plextraktsync/trakt/TraktUserListCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
class TraktUserListCollection(UserList):
logger = logging.getLogger(__name__)

def __init__(self, keep_watched: bool, trakt_lists_overrides: dict):
super().__init__()
self.keep_watched = keep_watched
self.trakt_lists_overrides = trakt_lists_overrides

@property
def is_empty(self):
return not len(self)
Expand All @@ -36,6 +41,8 @@ def add_watchlist(self, items: list[TraktPlayable]):
return tl

def add_list(self, list_id: int, list_name: str):
tl = TraktUserList.from_trakt_list(list_id, list_name)
list_config = self.trakt_lists_overrides.get(list_name, {})
keep_watched = list_config.get("keep_watched", self.keep_watched)
tl = TraktUserList.from_trakt_list(list_id, list_name, keep_watched)
self.append(tl)
return tl
Loading