add subs to m3u

This commit is contained in:
YouROK
2021-03-11 20:19:08 +03:00
parent 9744982f79
commit b8dcf1c1cc

View File

@@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"path/filepath" "path/filepath"
"sort" "sort"
"strings"
"time" "time"
"github.com/anacrolix/missinggo/httptoo" "github.com/anacrolix/missinggo/httptoo"
@@ -93,6 +94,11 @@ func getM3uList(tor *state.TorrentStatus, host string, fromLast bool) string {
fn = f.Path fn = f.Path
} }
m3u += "#EXTINF:0," + fn + "\n" 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) name := filepath.Base(f.Path)
m3u += host + "/stream/" + url.PathEscape(name) + "?link=" + tor.Hash + "&index=" + fmt.Sprint(f.Id) + "&play\n" 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 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 { func searchLastPlayed(tor *state.TorrentStatus) int {
viewed := sets.ListViewed(tor.Hash) viewed := sets.ListViewed(tor.Hash)
if len(viewed) == 0 { if len(viewed) == 0 {