Avoid calling self.lookup(tm) in a loop
MODIFY
plex_trakt_sync/commands/sync.py
plex_trakt_sync/commands/sync.py
@@ -136,6 +136,7 @@ def find_show_episodes(show, plex: PlexApi, trakt: TraktApi):
def for_each_show_episode(pm, tm, trakt: TraktApi):
+ lookup = trakt.lookup(tm)
for pe in pm.episodes():
try:
provider = pe.provider
@@ -147,7 +148,7 @@ def for_each_show_episode(pm, tm, trakt: TraktApi):
logger.error(f"Skipping {pe}: Provider {provider} not supported")
continue
- te = trakt.find_episode(tm, pe)
+ te = trakt.find_episode(tm, pe, lookup)
if te is None:
logger.warning(f"Skipping {pe}: Not found on Trakt")
continue

MODIFY
plex_trakt_sync/trakt_api.py
plex_trakt_sync/trakt_api.py
@@ -216,11 +216,11 @@ def search_by_id(self, media_id: str, id_type: str, media_type: str):
return None
- def find_episode(self, tm: TVShow, pe: PlexLibraryItem):
+ def find_episode(self, tm: TVShow, pe: PlexLibraryItem, lookup=None):
"""
Find Trakt Episode from Plex Episode
"""
- lookup = self.lookup(tm)
+ lookup = lookup if lookup else self.lookup(tm)
try:
return lookup[pe.season_number][pe.episode_number].instance
except KeyError:

Avoid calling self.lookup(tm) in a loop