SE UI drop video: find and offer matching subtitle - fix #11020#11038
Merged
Conversation
Dropping a subtitle on the window already opens its associated video, but dropping a video on the video player did not load the matching subtitle. Now it does: if no subtitle is loaded, load the found one; otherwise prompt (and save-if-unsaved via the existing flow). Also fixes FindSubtitleFileName, which was effectively broken — it called File.Exists without the directory so it only ever matched files in the current working directory. It now searches the video's own directory, recurses into trimmed name variants (movie.en -> movie), and falls back to scanning for movie.<lang>.srt style names. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the drag/drop asymmetry reported in #11020 by attempting to auto-locate and open a matching subtitle file after a video is dropped onto the video player, and by improving the underlying subtitle-file discovery logic to search in the video’s folder and handle common name variants.
Changes:
- Enhanced subtitle lookup to search the video’s directory, try trimmed basename variants, and fall back to detecting
{name}.{lang}.{ext}patterns (e.g.movie.en.srt). - Updated video drag/drop flow to optionally load an associated subtitle (auto-load when empty; prompt when a subtitle is already loaded).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/ui/Logic/Media/FindSubtitleFileName.cs | Reworks subtitle discovery to search alongside the video and support trimmed/language-suffixed naming patterns. |
| src/ui/Features/Main/MainViewModel.cs | After opening a dropped video, attempts to find and (optionally) open an associated subtitle file. |
Comment on lines
+34
to
+38
| if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory)) | ||
| { | ||
| try | ||
| { | ||
| foreach (var candidate in Directory.EnumerateFiles(directory, nameWithoutExtension + ".*")) |
Comment on lines
+49
to
+52
| catch | ||
| { | ||
| // ignore - directory not accessible | ||
| } |
Comment on lines
+17057
to
+17075
| if (!IsEmpty) | ||
| { | ||
| var answer = await MessageBox.Show( | ||
| Window!, | ||
| Se.Language.Title, | ||
| string.Format(Se.Language.Main.OpenSubtitleFileX, Path.GetFileName(foundSubtitleFileName)), | ||
| MessageBoxButtons.YesNo, | ||
| MessageBoxIcon.Question); | ||
| if (answer != MessageBoxResult.Yes) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var doContinue = await HasChangesContinue(); | ||
| if (!doContinue) | ||
| { | ||
| return; | ||
| } | ||
| } |
- FindSubtitleFileName: treat empty Path.GetDirectoryName as "." so the fallback scan still runs for relative-path callers. - FindSubtitleFileName: narrow the catch around Directory.EnumerateFiles to IOException / UnauthorizedAccessException / SecurityException / ArgumentException instead of swallowing everything. - TryLoadAssociatedSubtitle: gate the prompt on !IsEmpty || !IsEmptyOriginal so the original-text column's unsaved edits aren't silently discarded (HasChangesContinue's ContinueNewOrExitOriginal step runs). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
FindSubtitleFileName, which was effectively broken: it calledFile.Existswith no directory, so it would only ever match files in the current working directory. It now searches the video's own folder, recurses into trimmed name variants (movie.en→movie,movie_en→movie), and finally scans formovie.<lang>.srtstyle names.Test plan
movie.mp4+movie.srt) when the editor is empty — subtitle loads automatically.movie.mp4+movie.en.srt) — found and loaded.dotnet test tests/UI/UITests.csproj— 188/188 passing.🤖 Generated with Claude Code