diff --git a/cmd/downloader/trackers/embed.go b/cmd/downloader/trackers/embed.go index 42828242c..694f2eee4 100644 --- a/cmd/downloader/trackers/embed.go +++ b/cmd/downloader/trackers/embed.go @@ -1,29 +1,47 @@ package trackers import ( + "bufio" _ "embed" "strings" ) //go:embed trackerslist/trackers_best.txt var best string -var Best = strings.Split(best, "\n\n") +var Best = split(best) //go:embed trackerslist/trackers_all_https.txt var https string -var Https = strings.Split(https, "\n\n") +var Https = split(https) //go:embed trackerslist/trackers_all_http.txt var http string -var Http = strings.Split(http, "\n\n") +var Http = split(http) //go:embed trackerslist/trackers_all_udp.txt var udp string -var Udp = strings.Split(udp, "\n\n") +var Udp = split(udp) //go:embed trackerslist/trackers_all_ws.txt var ws string -var Ws = strings.Split(ws, "\n\n") +var Ws = split(ws) + +func split(txt string) (lines []string) { + sc := bufio.NewScanner(strings.NewReader(txt)) + for sc.Scan() { + l := sc.Text() + l = strings.TrimSpace(l) + if len(l) == 0 { + continue + } + lines = append(lines, sc.Text()) + } + + if err := sc.Err(); err != nil { + panic(err) + } + return lines +} func First(n int, in []string) (res []string) { if n <= len(in) {