Add --batch-size option for TraktBatch
MODIFY
plex_trakt_sync/commands/sync.py
plex_trakt_sync/commands/sync.py
@@ -154,12 +154,12 @@ def for_each_show_episode(pm, tm, trakt: TraktApi):
yield tm, pe, te
-def sync_all(movies=True, tv=True, show=None):
+def sync_all(movies=True, tv=True, show=None, batch_size=None):
with requests_cache.disabled():
server = get_plex_server()
listutil = TraktListUtil()
plex = PlexApi(server)
- trakt = TraktApi()
+ trakt = TraktApi(batch_size=batch_size)
with measure_time("Loaded Trakt lists"):
trakt_watched_movies = trakt.watched_movies
@@ -216,7 +216,13 @@ def sync_all(movies=True, tv=True, show=None):
default="all",
show_default=True, help="Specify what to sync"
)
-def sync(sync_option: str, show: str):
+@click.option(
+ "--batch-size", "batch_size",
+ type=int,
+ default=None,
+ help="Specify batch size for collection submit queue"
+)
+def sync(sync_option: str, show: str, batch_size: int):
"""
Perform sync between Plex and Trakt
"""
@@ -237,4 +243,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, show=show)
+ sync_all(movies=movies, tv=tv, show=show, batch_size=batch_size)

MODIFY
plex_trakt_sync/trakt_api.py
plex_trakt_sync/trakt_api.py
@@ -50,8 +50,8 @@ class TraktApi:
Trakt API class abstracting common data access and dealing with requests cache.
"""
- def __init__(self):
- self.batch = TraktBatch(self)
+ def __init__(self, batch_size=None):
+ self.batch = TraktBatch(self, batch_size=batch_size)
@property
@memoize
@@ -234,8 +234,9 @@ def flush(self):
class TraktBatch:
- def __init__(self, trakt: TraktApi):
+ def __init__(self, trakt: TraktApi, batch_size=None):
self.trakt = trakt
+ self.batch_size = batch_size
self.collection = {}
@nocache

Add --batch-size option for TraktBatch