fix palylist and names

This commit is contained in:
nikk gitanes
2020-11-01 23:07:49 +03:00
parent 76ad8f6ade
commit a53b6a9f53
2 changed files with 9 additions and 5 deletions

View File

@@ -10,9 +10,11 @@ import (
)
func CleanFName(file string) string {
re := regexp.MustCompile(`[ !*'();:@&=+$,/?#\[\]~"]{}`)
re := regexp.MustCompile(`[ !*'();:@&=+$,/?#\[\]~"{}]`)
ret := re.ReplaceAllString(file, `_`)
ret = strings.Replace(ret, "__", "_", -1)
ret = strings.Replace(ret, "._", "_", -1)
ret = strings.Replace(ret, "_.", ".", -1)
return ret
}

View File

@@ -7,13 +7,14 @@ import (
"server/settings"
"server/torr"
"server/utils"
)
func MakeM3ULists(torrents []*settings.Torrent, host string) string {
m3u := "#EXTM3U\n"
for _, t := range torrents {
m3u += "#EXTINF:0 type=\"playlist\", " + t.Name + "\n"
m3u += "#EXTINF:0 type=\"playlist\"," + t.Name + "\n"
magnet := t.Magnet
mag, _, err := GetMagnet(magnet)
@@ -21,7 +22,7 @@ func MakeM3ULists(torrents []*settings.Torrent, host string) string {
mag.Trackers = []string{} //Remove retrackers for small link size
magnet = mag.String()
}
m3u += host + "/torrent/play?link=" + url.QueryEscape(magnet) + "&m3u=true\n\n"
m3u += host + "/torrent/play?link=" + url.QueryEscape(magnet) + "&m3u=true\n"
}
return m3u
}
@@ -32,6 +33,7 @@ func MakeM3UPlayList(tor torr.TorrentStats, magnet string, host string) string {
mag, _, err := GetMagnet(magnet)
if err == nil {
mag.Trackers = []string{} //Remove retrackers for small link size
mag.DisplayName = "" //Remove dn from link (useless)
magnet = mag.String()
}
magnet = url.QueryEscape(magnet)
@@ -42,8 +44,8 @@ func MakeM3UPlayList(tor torr.TorrentStats, magnet string, host string) string {
if fn == "" {
fn = f.Path
}
m3u += "#EXTINF:0, " + fn + "\n"
m3u += host + "/torrent/play?link=" + magnet + "&file=" + fmt.Sprint(f.Id) + "\n\n"
m3u += "#EXTINF:0," + fn + "\n"
m3u += host + "/torrent/play/" + url.QueryEscape(utils.CleanFName(f.Path)) + "?link=" + magnet + "&file=" + fmt.Sprint(f.Id) + "\n"
}
}
return m3u