Skip to content

Commit

Permalink
Merge pull request #2023 from glensc/add-watched-only-flag
Browse files Browse the repository at this point in the history
Feature: Add --match-watched flag to compare servers
  • Loading branch information
glensc authored Aug 18, 2024
2 parents ef94d4f + c593ab3 commit 072ccdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions plextraktsync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def clear_collections():
required=True,
help="Plex Server/Plex Library name from servers.yml",
)
@click.option("--match-watched", is_flag=True, help="Match only watched items")
def compare_libraries():
"""
Compare two Plex Libraries
Expand Down
13 changes: 7 additions & 6 deletions plextraktsync/commands/compare_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import contextlib

from plexapi.exceptions import NotFound
from sqlalchemy.util import OrderedSet

from plextraktsync.config.ConfigLoader import ConfigLoader
from plextraktsync.decorators.coro import coro
Expand Down Expand Up @@ -37,7 +36,7 @@ def get_walker(plex: PlexApi, library: PlexLibrarySection):


async def load_movies(walker1, walker2):
movies1 = OrderedSet()
movies1 = set()
async for pm in walker1.get_plex_movies():
movies1.add(pm)

Expand Down Expand Up @@ -80,7 +79,7 @@ def use_cache(cache_file: str):


@coro
async def compare_libraries(library1: str, library2: str):
async def compare_libraries(library1: str, library2: str, match_watched: bool):
print = factory.print
print(f"Compare contents of '{library1}' and '{library2}'")
plex1, lib1 = get_plex_from_name(library1)
Expand All @@ -95,9 +94,11 @@ async def compare_libraries(library1: str, library2: str):
cache_file = f"compare-cache-{cache_key(lib1, lib2)}.json"
with use_cache(cache_file) as cache:
for pm1, pm2 in get_pairs(movies1, movies2):
if cache.get(str(pm1.key)):
continue
if not pm1.is_watched:
cached = cache.get(str(pm1.key))
if cached:
if not match_watched and cached != "not watched":
continue
if match_watched and not pm1.is_watched:
cache[str(pm1.key)] = "not watched"
continue

Expand Down

0 comments on commit 072ccdf

Please sign in to comment.