Add WalkConfig class for walk configuration
MODIFY
plex_trakt_sync/commands/sync.py
plex_trakt_sync/commands/sync.py
from plex_trakt_sync.plex_api import PlexApi
from plex_trakt_sync.sync import Sync
from plex_trakt_sync.version import git_version_info
-from plex_trakt_sync.walker import Walker
+from plex_trakt_sync.walker import Walker, WalkConfig
def sync_all(walker: Walker, plex: PlexApi, runner: Sync, dry_run: bool):
@@ -93,28 +93,29 @@ def sync(
trakt = factory.trakt_api(batch_size=batch_size)
mf = factory.media_factory(batch_size=batch_size)
pb = factory.progressbar(not no_progress_bar)
- w = Walker(plex=plex, trakt=trakt, mf=mf, movies=movies, shows=tv, progressbar=pb)
+ wc = WalkConfig(movies=movies, shows=tv)
+ w = Walker(plex=plex, trakt=trakt, mf=mf, config=wc, progressbar=pb)
if id:
logger.info(f"Syncing item: {id}")
- w.add_id(library)
+ wc.add_id(id)
if library:
logger.info(f"Filtering Library: {library}")
- w.add_library(library)
+ wc.add_library(library)
if show:
- w.add_show(show)
+ wc.add_show(show)
logger.info(f"Syncing Show: {show}")
if movie:
- w.add_movie(movie)
+ wc.add_movie(movie)
logger.info(f"Syncing Movie: {movie}")
- if not w.is_valid():
+ if not wc.is_valid():
click.echo("Nothing to sync, this is likely due conflicting options given.")
return
if dry_run:
print("Enabled dry-run mode: not making actual changes")
- w.walk_details(print=tqdm.write)
+ wc.walk_details(print=tqdm.write)
with measure_time("Completed full sync"):
sync_all(walker=w, plex=plex, runner=factory.sync(), dry_run=dry_run)

MODIFY
plex_trakt_sync/commands/unmatched.py
plex_trakt_sync/commands/unmatched.py
from plex_trakt_sync.commands.login import ensure_login
from plex_trakt_sync.factory import factory
-from plex_trakt_sync.walker import Walker
+from plex_trakt_sync.walker import Walker, WalkConfig
@click.option(
@@ -23,13 +23,14 @@ def unmatched(no_progress_bar: bool):
trakt = factory.trakt_api()
mf = factory.media_factory()
pb = factory.progressbar(not no_progress_bar)
- walker = Walker(plex, trakt, mf, progressbar=pb)
+ wc = WalkConfig()
+ walker = Walker(plex, trakt, mf, wc, progressbar=pb)
- if not walker.is_valid():
+ if not wc.is_valid():
click.echo("Nothing to scan, this is likely due conflicting options given.")
return
- walker.walk_details(print=click.echo)
+ wc.walk_details(print=click.echo)
failed = []
for pm in walker.get_plex_movies():

MODIFY
plex_trakt_sync/walker.py
plex_trakt_sync/walker.py
from typing import List
+from plex_trakt_sync.decorators.memoize import memoize
from plex_trakt_sync.decorators.measure_time import measure_time
from plex_trakt_sync.media import Media, MediaFactory
from plex_trakt_sync.plex_api import PlexApi, PlexLibrarySection
from plex_trakt_sync.trakt_api import TraktApi
-class Walker:
- """
- Class dealing with finding and walking library, movies/shows, episodes
- """
+class WalkConfig:
+ walk_movies = True
+ walk_shows = True
+ library = []
+ show = []
+ movie = []
+ id = []
- def __init__(self, plex: PlexApi, trakt: TraktApi, mf: MediaFactory, progressbar=None, movies=True, shows=True):
- self._progressbar = progressbar
- self.plex = plex
- self.trakt = trakt
- self.mf = mf
+ def __init__(self, movies=True, shows=True):
self.walk_movies = movies
self.walk_shows = shows
- self.library = []
- self.show = []
- self.movie = []
- self.id = []
def add_library(self, library):
self.library.append(library)
@@ -60,17 +56,30 @@ def walk_details(self, print=print):
if self.movie:
print(f"Walk Movies: {self.movie}")
+
+class Walker:
+ """
+ Class dealing with finding and walking library, movies/shows, episodes
+ """
+
+ def __init__(self, plex: PlexApi, trakt: TraktApi, mf: MediaFactory, config: WalkConfig, progressbar=None):
+ self._progressbar = progressbar
+ self.plex = plex
+ self.trakt = trakt
+ self.mf = mf
+ self.config = config
+
def get_plex_movies(self):
"""
Iterate over movie sections unless specific movie is requested
"""
- if not self.walk_movies:
+ if not self.config.walk_movies:
return
- if self.movie:
- movies = self.media_from_titles("movie", self.movie)
+ if self.config.movie:
+ movies = self.media_from_titles("movie", self.config.movie)
else:
- movies = self.media_from_sections(self.plex.movie_sections(), self.library)
+ movies = self.media_from_sections(self.plex.movie_sections(), self.config.library)
yield from movies
@@ -82,13 +91,13 @@ def find_movies(self):
yield movie
def get_plex_shows(self):
- if not self.walk_shows:
+ if not self.config.walk_shows:
return
- if self.show:
- shows = self.media_from_titles("show", self.show)
+ if self.config.show:
+ shows = self.media_from_titles("show", self.config.show)
else:
- shows = self.media_from_sections(self.plex.show_sections(), self.library)
+ shows = self.media_from_sections(self.plex.show_sections(), self.config.library)
yield from shows

Add WalkConfig class for walk configuration