Skip to content

Commit

Permalink
Merge pull request #1238 from glensc/parital-walk
Browse files Browse the repository at this point in the history
Fixes #298
  • Loading branch information
glensc authored Nov 30, 2022
2 parents 293928a + ebbed43 commit e1cee3c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
32 changes: 22 additions & 10 deletions plextraktsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,37 @@ def trakt_wl_shows(self) -> Dict[int, TVShow]:

def sync(self, walker: Walker, dry_run=False):
listutil = TraktListUtil()
is_partial = walker.is_partial

if self.config.update_plex_wl_as_pl:
listutil.addList(None, "Trakt Watchlist", trakt_list=self.trakt.watchlist_movies)
if is_partial:
logger.warning("Running partial library sync. Watchlist as playlist won't update because it needs full library sync.")
else:
listutil.addList(None, "Trakt Watchlist", trakt_list=self.trakt.watchlist_movies)

if self.config.sync_liked_lists:
for lst in self.trakt.liked_lists:
listutil.addList(lst["listid"], lst["listname"])
if is_partial:
logger.warning("Partial walk, disabling liked lists updating. Liked lists won't update because it needs full library sync.")
else:
for lst in self.trakt.liked_lists:
listutil.addList(lst["listid"], lst["listname"])

if self.config.need_library_walk:
for movie in walker.find_movies():
self.sync_collection(movie, dry_run=dry_run)
self.sync_ratings(movie, dry_run=dry_run)
self.sync_watched(movie, dry_run=dry_run)
listutil.addPlexItemToLists(movie)
if not is_partial:
listutil.addPlexItemToLists(movie)
self.trakt.flush()

shows = set()
for episode in walker.find_episodes():
self.sync_collection(episode, dry_run=dry_run)
self.sync_ratings(episode, dry_run=dry_run)
self.sync_watched(episode, dry_run=dry_run)
listutil.addPlexItemToLists(episode)
if not is_partial:
listutil.addPlexItemToLists(episode)
if self.config.sync_ratings:
# collect shows for later ratings sync
shows.add(episode.show)
Expand All @@ -157,11 +166,14 @@ def sync(self, walker: Walker, dry_run=False):
self.sync_ratings(show, dry_run=dry_run)

if self.sync_wl or self.config.sync_liked_lists:
with measure_time("Updated watchlist and/or liked list"):
if self.config.update_plex_wl_as_pl or self.config.sync_liked_lists:
self.update_playlists(listutil, dry_run=dry_run)
if self.sync_wl:
self.sync_watchlist(walker, dry_run=dry_run)
if is_partial:
logger.warning("Partial walk, watchlist and/or liked list updating was skipped")
else:
with measure_time("Updated watchlist and/or liked list"):
if self.config.update_plex_wl_as_pl or self.config.sync_liked_lists:
self.update_playlists(listutil, dry_run=dry_run)
if self.sync_wl:
self.sync_watchlist(walker, dry_run=dry_run)

if not dry_run:
self.trakt.flush()
Expand Down
17 changes: 17 additions & 0 deletions plextraktsync/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def add_show(self, show):
def add_movie(self, movie):
self.movie.append(movie)

@property
def is_partial(self):
"""
Returns true if partial library walk is performed.
Due the way watchlist is filled, watchlists should only be updated on full walk.
"""
# Single item provided
if self.library or self.movie or self.show or self.id:
return True

# Must sync both movies and shows to be full sync
return not self.walk_movies or not self.walk_shows

def is_valid(self):
# Single item provided
if self.library or self.movie or self.show or self.id:
Expand Down Expand Up @@ -212,6 +225,10 @@ def __init__(
def plan(self):
return WalkPlanner(self.plex, self.config).plan()

@property
def is_partial(self):
return self.config.is_partial

def print_plan(self, print=print):
if self.plan.movie_sections:
print(f"Sync Movie sections: {self.plan.movie_sections}")
Expand Down

0 comments on commit e1cee3c

Please sign in to comment.