From c2e03bbfab97fc6716bcdd59158e9d5129bf0ea7 Mon Sep 17 00:00:00 2001 From: Mazen Besher Date: Tue, 21 Dec 2021 00:07:43 +0100 Subject: [PATCH] feat: detect multiple subtitle languages (#1723) --- files/file.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/files/file.go b/files/file.go index 675f7df1..f05dacd6 100644 --- a/files/file.go +++ b/files/file.go @@ -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())) + } + } } }