detect multiple subtitle languages
This commit is contained in:
parent
a078f0b787
commit
d1b4d54ccf
@ -14,6 +14,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -271,7 +272,23 @@ 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.Lang.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(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]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fPath := strings.TrimSuffix(i.Path, ext) + ".vtt"
|
fPath := strings.TrimSuffix(i.Path, ext) + ".vtt"
|
||||||
if _, err := i.Fs.Stat(fPath); err == nil {
|
if _, err := i.Fs.Stat(fPath); err == nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user