diff --git a/server/web/api/m3u.go b/server/web/api/m3u.go index 660c934..ef14a8a 100644 --- a/server/web/api/m3u.go +++ b/server/web/api/m3u.go @@ -7,6 +7,7 @@ import ( "net/url" "path/filepath" "sort" + "strings" "time" "github.com/anacrolix/missinggo/httptoo" @@ -93,6 +94,11 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string { fn = f.Path } m3u += "#EXTINF:0," + fn + "\n" + subs := findSubs(tor.FileStats, f) + if subs != nil { + sname := filepath.Base(subs.Path) + m3u += "#EXTVLCOPT:sub-file=" + host + "/stream/" + url.PathEscape(sname) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(f.Id) + "&play\n" + } name := filepath.Base(f.Path) m3u += host + "/stream/" + url.PathEscape(name) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(f.Id) + "&play\n" } @@ -101,6 +107,20 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string { return m3u } +func findSubs(files []*state.TorrentFileStat, file *state.TorrentFileStat) *state.TorrentFileStat { + name := strings.TrimSuffix(file.Path, filepath.Ext(file.Path)) + + for _, f := range files { + if f.Path == name+".srt" { + return f + } + if f.Path == name+".ass" { + return f + } + } + return nil +} + func searchLastPlayed(tor *state.TorrentStatus) int { viewed := sets.ListViewed(tor.Hash) if len(viewed) == 0 {