feat: detect multiple subtitle languages (#1723)
This commit is contained in:
parent
608a0015ee
commit
c2e03bbfab
|
@ -271,11 +271,17 @@ func (i *FileInfo) detectSubtitles() {
|
||||||
i.Subtitles = []string{}
|
i.Subtitles = []string{}
|
||||||
ext := filepath.Ext(i.Path)
|
ext := filepath.Ext(i.Path)
|
||||||
|
|
||||||
// TODO: detect multiple languages. Base.Lang.vtt
|
// detect multiple languages. Base*.vtt
|
||||||
|
// TODO: give subtitles descriptive names (lang) and track attributes
|
||||||
fPath := strings.TrimSuffix(i.Path, ext) + ".vtt"
|
parentDir := strings.TrimRight(i.Path, i.Name)
|
||||||
if _, err := i.Fs.Stat(fPath); err == nil {
|
dir, err := afero.ReadDir(i.Fs, parentDir)
|
||||||
i.Subtitles = append(i.Subtitles, fPath)
|
if err == nil {
|
||||||
|
base := strings.TrimSuffix(i.Name, ext)
|
||||||
|
for _, f := range dir {
|
||||||
|
if !f.IsDir() && strings.HasPrefix(f.Name(), base) && strings.HasSuffix(f.Name(), ".vtt") {
|
||||||
|
i.Subtitles = append(i.Subtitles, path.Join(parentDir, f.Name()))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue