Add encoding param to sync_item() and auto_run param to Syncer.__init__()#65
Conversation
sync_item(): Accept an optional encoding parameter instead of always using self.media_format. This fixes a race condition where concurrent download threads could clobber each other's format setting via the shared Syncer instance. Syncer.__init__(): Accept an optional auto_run parameter (default True) that controls whether sync starts immediately on construction. Setting auto_run=False allows external consumers to instantiate a Syncer, inspect purchases, and decide what to sync before starting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks, I'll take a look at these. They sound fine on paper. There's been a few AI-based PRs lately and the internals are now a bit of a mess so this may need to wait until I get time to manually refactor things. |
Super understandable - I'm in no big rush or anything, I just want to see the state of the art pushed, since god knows the world of self-hosting needs some real love - I appreciate you caring enough to be super responsive! Thank you for your time. |
|
Actually this is fine, I need to re-org the args to some of the functions a little but might as well bundle this in before. |
Summary
Two small additions to support external consumers of
Syncerthat need finer-grained control over the sync process:auto_run=TrueonSyncer.__init__(): wraps the existingasyncio.run()andself.notify()calls inif auto_run:. Passingauto_run=Falselets callers instantiate aSyncerto inspect purchases before deciding what to sync, without triggering a full sync immediately.encoding=Noneonsync_item(): usesencoding or self.media_formatthroughout the method instead ofself.media_formatdirectly. This allows per-item format overrides and avoids a potential race condition when concurrent threads callsync_item()with different formats.Both changes are backwards-compatible. Default behavior is unchanged.
Tests
Two new tests in
tests/test_sync_item.py:test_sync_item_uses_encoding_parameter-- verifies theencodingkwarg is passed through to the download URL calltest_sync_item_falls_back_to_media_format_when_no_encoding-- verifies default behavior is preserved