diff --git a/files/file.go b/files/file.go index 46179587..cdb3c0d6 100644 --- a/files/file.go +++ b/files/file.go @@ -14,7 +14,6 @@ import ( "os" "path" "path/filepath" - "regexp" "strings" "time" @@ -272,27 +271,18 @@ func (i *FileInfo) detectSubtitles() { i.Subtitles = []string{} ext := filepath.Ext(i.Path) - // detect multiple languages. Base.Lang.vtt + // detect multiple languages. Base*.vtt // TODO: give subtitles descriptive names (lang) and track attributes afs := &afero.Afero{Fs: i.Fs} parentDir := strings.TrimRight(i.Path, i.Name) dir, err := afs.ReadDir(parentDir) if err == nil { base := strings.TrimSuffix(i.Name, ext) - r := regexp.MustCompile("^" + regexp.QuoteMeta(base) + `\.(.*\.)?vtt$`) for _, f := range dir { - if !f.IsDir() { - if matches := r.FindStringSubmatch(f.Name()); len(matches) == 2 { - i.Subtitles = append(i.Subtitles, path.Join(parentDir, matches[0])) - } + if !f.IsDir() && strings.HasPrefix(f.Name(), base) && strings.HasSuffix(f.Name(), ".vtt") { + i.Subtitles = append(i.Subtitles, path.Join(parentDir, f.Name())) } } - return - } - - fPath := strings.TrimSuffix(i.Path, ext) + ".vtt" - if _, err := i.Fs.Stat(fPath); err == nil { - i.Subtitles = append(i.Subtitles, fPath) } }