Scope subtitle/sidecar caching to the owning video in shared folders#183
Merged
Brandon-Haney merged 1 commit intoJun 7, 2026
Conversation
Associated-file discovery decided whether siblings belonged to one video based on how many videos were being cached from a directory, not how many physically exist in it. In a flat folder holding many movies, caching one movie pulled in every other movie's subtitles, which then churned back to the array on the next run. get_media_siblings_grouped() now scans the directory for all physical videos (including .plexcached backups) and gates on that count: - One physical video (per-movie folder): unchanged fast path — every sibling belongs to it, including subtitles named without the video's quality suffix. - Multiple physical videos: assign each sibling to its owning video by boundary-aware name-prefix match. Siblings owned by a video that is not being cached are skipped, and orphan subtitles (no matching video) are skipped rather than handed to the first video, since a subtitle belongs to exactly one video. Generic shared assets (poster.jpg) still go to the first cached video. name_matches_video_stem() requires a non-alphanumeric boundary after the stem so "Movie 10.en.srt" no longer matches the stem "Movie 1". Adds regression tests covering the flat-folder case, the per-movie folder with non-prefixed subtitles, the .plexcached-as-owner case, orphan subtitle skipping, and the boundary matcher.
StudioNirin
approved these changes
Jun 6, 2026
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.
Fixes #182.
In a folder that holds many movies (e.g. a genre-based library folder),
caching a single movie also cached every other movie's subtitles, and the
next run moved them back to the array — a copy/remove cycle on every sync.
The cause: associated-file discovery decided whether subtitles/sidecars
belonged to a video based on how many videos were being cached from a
directory, not how many physically exist in it. With one cached movie in a
flat folder, it grabbed all siblings.
Discovery now scans the directory for all physical videos and assigns each
sibling to its owning video by a boundary-aware name match. Siblings owned
by a video that isn't being cached are skipped; orphan subtitles are skipped
rather than attached to an unrelated movie. Per-movie folders are unchanged.
Test steps
.srt) in a single folder.including subs named without the video's quality suffix (e.g.
English.srt).