Media directory monitoring: notifications + adaptive reconciliation, no disable on timeout - #799
Draft
AlySerry0 wants to merge 4 commits into
Draft
Media directory monitoring: notifications + adaptive reconciliation, no disable on timeout#799AlySerry0 wants to merge 4 commits into
AlySerry0 wants to merge 4 commits into
Conversation
New syncplay/filemonitor.py: a small, playlist-blind helper that owns the optional watchdog observer lifecycle and reports structured filesystem events back on the reactor thread. It knows only about paths and native watch characteristics: recursive watches for local/media roots, plus a budgeted set of supplemental non-recursive watches for Windows network roots (where a single recursive watch does not reliably report remotely- originated changes at depth). If watchdog is unavailable or a watch cannot be established it simply provides no events. Adds the supporting folder-search constants (reconciliation interval, warning base delay, event coalescing window, degraded-recovery count and the network watch budget).
A small public helper around the existing EpisodeFilenameParser that, given target playlist filenames, returns cached directories holding the same series/season. It reads only mediaFilesCache (no os.walk), maps matches in a Watched subfolder to their parent, and is a ranking hint only - a false positive cannot affect file switching or playlist behaviour.
…disable Rewrites FileSwitchManager to use filesystem notifications as an acceleration path over authoritative reconciliation scanning, keeping the recursive scan as the completeness authority: - a transient first-file/scan timeout aborts the pass but no longer sets folderSearchEnabled = False or requires re-affirming media directories; - clear file create/delete/move events update mediaFilesCache directly and idempotently on the reactor thread, without a scan to re-confirm them; directory events use targeted subtree reconciliation, with full reconciliation as the ambiguity/failure fallback; - single-flight scan worker; events arriving during a scan collapse into one pending full reconciliation; downstream fileSwitchFoundFiles() is coalesced; - adaptive polling: full reconciliation drops to a slow safety interval while the current/next local files resolve and returns to the ~30s cadence while a needed file is unresolved; - operational degraded state (cleared only after three consecutive clean full scans) is separated from a single user-visible warning per media configuration/session; the warning threshold becomes additional grace on a small base delay, so no config migration is needed; - supplemental Windows network directory watches are prioritised by current/next playlist relevance and same-series/season directories. The reworked warning no longer says folder searching has been disabled.
watchdog powers the optional filesystem-notification path. Pinned watchdog>=2.1.0,<4.0.0 to stay compatible with the currently declared minimum Python, and added to the py2exe packages so the frozen Windows build ships it. Notifications remain optional: if the import or a native backend is unavailable, folder search falls back to reconciliation scanning.
AlySerry0
force-pushed
the
folder-search-retry-not-disable
branch
from
August 19, 2026 02:13
7a9c584 to
8b43a0d
Compare
Contributor
|
Cheers, I'll review this when I have the time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft implementing the media-directory monitoring spec from the #796 discussion (refs #130). This revision replaces the earlier draft on this branch and is rebased onto current
master(so it builds on the merged watched-subfoldersEpisodeFilenameParser).Developed with AI assistance (Claude) and reviewed/tested by me, following the updated agent docs (#763).
Approach
Filesystem notifications are used as an acceleration path over authoritative reconciliation scanning; a full recursive scan stays the completeness authority, and absence of an event is never treated as proof nothing changed.
Kept from the earlier draft: transient timeouts no longer disable folder search, the synchronous single-flight scan claim, watchdog support, and the Windows packaging.
Reworked per the spec:
syncplay/filemonitor.py(new) — a small, playlist-blindFileMonitorowning the watchdog observer lifecycle and the thread→reactor handoff. It knows only paths/watch characteristics: a recursive watch per media root, plus a budgeted set of supplemental non-recursive watches for Windows network roots (FOLDER_SEARCH_NETWORK_WATCH_LIMIT = 32). If watchdog is unavailable or a watch fails, it provides no events and scanning continues.mediaFilesCachedirectly and idempotently on the reactor thread (no scan to re-confirm; component/case-aware path matching soP:\TV≠P:\TV2). Directory events use targeted subtree reconciliation, with full reconciliation as the ambiguity/failure fallback.fileSwitchFoundFiles()is coalesced (~1s).FOLDER_SEARCH_RECONCILIATION_INTERVAL = 300) while the current/next local files resolve, and returns to the existing ~30sfolderSearchDoubleCheckIntervalwhile a needed file is unresolved (usingfindFilepathresolution semantics; URLs don't force urgent polling).folderSearchWarningThresholdbecomes additional grace on a 3s base delay, so no config migration. ThefolderSearchUseNotificationsoption added in the earlier draft is removed (notifications are an internal optimisation). The warning no longer says folder searching has been disabled.getRelatedEpisodeDirectorieshelper reusingEpisodeFilenameParser(noos.walk, ranking hint only).watchdog>=2.1.0,<4.0.0to stay compatible with the currently declared minimum Python (deferring any deliberate 3.9 bump to a maintainer decision), added to the py2exe bundle.The §5 direct-watch gate (validated on the reported Win 11 + Samba setup)
A non-recursive
WindowsApiObserverwatch placed directly on an existing deep directory received all remote (Pi-originated) create/rename/delete events — whereas the recursive root watch missed them. So the supplemental per-directory watch strategy is worthwhile: it catches exactly the remotely-added media a recursive root watch does not surface at depth.Testing
TV/TV2boundary safety, case-insensitive key reuse, move in/out of roots — unit tested (13/13).FileMonitorlive against the Samba share: supplemental non-recursive watch delivers deep remote events on the reactor thread; budget accounting correct.filemonitor+watchdog(incl. the Windowsread_directory_changes/winapiobserver); real-session behaviour smoke (join/playlist/EOF/file-switch) showed no seek/pause/playlist/protocol change.Happy to adjust any of the constants, naming, or the Python/watchdog version decision.
Changelog line:
#799 by @AlySerry0, resolving #796 and #130