fix(files): detectSubtitles 用 path.Dir 取父目录而非 TrimRight 字符集#233
Open
fix(files): detectSubtitles 用 path.Dir 取父目录而非 TrimRight 字符集#233
Conversation
detectSubtitles built parentDir as
strings.TrimRight(i.Path, i.Name)
but TrimRight treats its second argument as a *cutset of runes*, not
a suffix. For a video at "/foo/bar/baz.mp4" with Name "baz.mp4", it
strips every trailing rune that appears in the set
{'b','a','z','.','m','p','4'}, producing something like "/foo/" -
or, for many filenames, a totally wrong path. The subsequent
ReadDir then either failed or scanned the wrong directory, so
adjacent .vtt subtitle files were almost never detected.
Use path.Dir(i.Path), which actually returns the parent directory.
Co-authored-by: Cursor <cursoragent@cursor.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.
概要
`pkg/files/file.go` 的 `detectSubtitles` 用:
```go
parentDir := strings.TrimRight(i.Path, i.Name)
```
`strings.TrimRight` 的第二个参数是 字符集(cutset of runes),不是字符串后缀。对一个 video 文件 `/foo/bar/baz.mp4`、`Name = "baz.mp4"`:
随后的 `afero.ReadDir(i.Fs, parentDir)` 要么读到错误的目录、要么直接报错——几乎所有真实视频文件都拿不到字幕检测结果。
改动
用 `path.Dir(i.Path)` 取真正的父目录,并加注释说明历史 bug。
验证方式
Made with Cursor