Skip to content

Scope subtitle/sidecar caching to the owning video in shared folders#183

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-182-flat-folder-subtitles
Jun 7, 2026
Merged

Scope subtitle/sidecar caching to the owning video in shared folders#183
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-182-flat-folder-subtitles

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

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

  1. Put two or more movies (each with its own .srt) in a single folder.
  2. Make only one of them OnDeck/Watchlisted and run a sync.
  3. Confirm only the cached movie's subtitle is cached — the others stay put.
  4. Run again: no subtitles churn back to the array.
  5. Confirm a normal one-movie-per-folder library still caches its subtitles,
    including subs named without the video's quality suffix (e.g. English.srt).

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.
@Brandon-Haney Brandon-Haney merged commit dabf439 into StudioNirin:main Jun 7, 2026
2 checks passed
@Brandon-Haney Brandon-Haney deleted the fix/issue-182-flat-folder-subtitles branch June 7, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SRT files getting cached/removed randomly

2 participants