Skip to content

Commit

Permalink
Implement syncing only specific show
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 16, 2021
1 parent b24a8de commit c640c52
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plex_trakt_sync/commands/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def for_each_episode(sections, trakt: TraktApi):
yield tm, pe, te


def find_show_episodes(show, plex: PlexApi, trakt: TraktApi):
search = plex.search(show, libtype='show')
for pm in search:
tm = trakt.find_by_media(pm)
for tm, pe, te in for_each_show_episode(pm, tm, trakt):
yield tm, pe, te


def for_each_show_episode(pm, tm, trakt: TraktApi):
lookup = trakt.lookup(tm)

Expand All @@ -141,7 +149,7 @@ def for_each_show_episode(pm, tm, trakt: TraktApi):
yield tm, pe, te.instance


def sync_all(movies=True, tv=True):
def sync_all(movies=True, tv=True, show=None):
with requests_cache.disabled():
server = get_plex_server()
listutil = TraktListUtil()
Expand Down Expand Up @@ -173,7 +181,12 @@ def sync_all(movies=True, tv=True):
sync_watched(pm, tm, plex, trakt, trakt_watched_movies)

if tv:
for tm, pe, te in for_each_episode(plex.show_sections, trakt):
if show:
it = find_show_episodes(show, plex, trakt)
else:
it = for_each_episode(plex.show_sections, trakt)

for tm, pe, te in it:
sync_show_collection(tm, pe, te, trakt)
sync_show_watched(tm, pe, te, trakt_watched_shows, plex, trakt)

Expand Down Expand Up @@ -219,4 +232,4 @@ def sync(sync_option: str, show: str):
logger.info(f"Syncing TV={tv}, Movies={movies}")

with measure_time("Completed full sync"):
sync_all(movies=movies, tv=tv)
sync_all(movies=movies, tv=tv, show=show)

0 comments on commit c640c52

Please sign in to comment.