Skip to content

Commit

Permalink
feat: detect multiple subtitle languages (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazenbesher committed Dec 20, 2021
1 parent 608a001 commit c2e03bb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ func (i *FileInfo) detectSubtitles() {
i.Subtitles = []string{}
ext := filepath.Ext(i.Path)

// TODO: detect multiple languages. Base.Lang.vtt

fPath := strings.TrimSuffix(i.Path, ext) + ".vtt"
if _, err := i.Fs.Stat(fPath); err == nil {
i.Subtitles = append(i.Subtitles, fPath)
// detect multiple languages. Base*.vtt
// TODO: give subtitles descriptive names (lang) and track attributes
parentDir := strings.TrimRight(i.Path, i.Name)
dir, err := afero.ReadDir(i.Fs, parentDir)
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()))
}
}
}
}

Expand Down

0 comments on commit c2e03bb

Please sign in to comment.