Move section items filtering out of library section
This allows using accurate progress bar with known length
MODIFY
plex_trakt_sync/commands/sync.py
plex_trakt_sync/commands/sync.py
import click
+from plexapi.exceptions import NotFound
from plex_trakt_sync.requests_cache import requests_cache
from plex_trakt_sync.plex_server import get_plex_server
@@ -94,8 +95,24 @@ def sync_show_watched(pm, tm, pe, te, trakt_watched_shows, plex: PlexApi, trakt:
def for_each_pair(sections, trakt: TraktApi):
for section in sections:
with measure_time(f"Processing section {section.title}"):
- with click.progressbar(section.items(), label=f"Processing {section.title}") as items:
+ pb = click.progressbar(section.items(), length=len(section), label=f"Processing {section.title}")
+ with pb as items:
for pm in items:
+ try:
+ provider = pm.provider
+ except NotFound as e:
+ logger.error(f"Sipping {pm}: {e}")
+ continue
+
+ if provider in ["local", "none", "agents.none"]:
+ continue
+
+ if provider not in ["imdb", "tmdb", "tvdb"]:
+ logger.error(
+ f"{pm}: Unable to parse a valid provider from guid:'{pm.guid}', guids:{pm.guids}"
+ )
+ continue
+
tm = trakt.find_movie(pm)
if tm is None:
logger.warning(f"[{pm})]: Not found on Trakt. Skipping")

MODIFY
plex_trakt_sync/plex_api.py
plex_trakt_sync/plex_api.py
@@ -124,19 +124,6 @@ def all(self):
def items(self):
for item in (PlexLibraryItem(x) for x in self.all()):
- try:
- provider = item.provider
- except NotFound as e:
- logger.error(f"{e}, skipping {item}")
- continue
-
- if provider in ["local", "none", "agents.none"]:
- continue
-
- if provider not in ["imdb", "tmdb", "tvdb"]:
- logger.error(f"{item}: Unable to parse a valid provider from guid:'{item.guid}', guids:{item.guids}")
- continue
-
yield item

Move section items filtering out of library section

This allows using accurate progress bar with known length