check vtt using prefix and suffix instead of regex
This commit is contained in:
parent
39abd1da6d
commit
7e942b0c63
@ -14,7 +14,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -272,28 +271,19 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *FileInfo) readListing(checker rules.Checker, readHeader bool) error {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user