trackers from file

This commit is contained in:
YouROK
2021-04-20 11:01:32 +03:00
parent f87ddc5917
commit 3eb3d9efbc
2 changed files with 24 additions and 0 deletions

View File

@@ -65,6 +65,11 @@ func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
spec.Trackers = [][]string{utils.GetDefTrackers()} spec.Trackers = [][]string{utils.GetDefTrackers()}
} }
trackers := utils.GetTrackerFromFile()
if len(trackers) > 0 {
spec.Trackers = append(spec.Trackers, [][]string{trackers}...)
}
goTorrent, _, err := bt.client.AddTorrentSpec(spec) goTorrent, _, err := bt.client.AddTorrentSpec(spec)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -5,8 +5,11 @@ import (
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"path/filepath"
"strings" "strings"
"server/settings"
"golang.org/x/time/rate" "golang.org/x/time/rate"
) )
@@ -27,6 +30,22 @@ var defTrackers = []string{
var loadedTrackers []string var loadedTrackers []string
func GetTrackerFromFile() []string {
name := filepath.Join(settings.Path, "trackers.txt")
buf, err := ioutil.ReadFile(name)
if err == nil {
list := strings.Split(string(buf), "\n")
var ret []string
for _, l := range list {
if strings.HasPrefix(l, "udp") || strings.HasPrefix(l, "http") {
ret = append(ret, l)
}
}
return ret
}
return nil
}
func GetDefTrackers() []string { func GetDefTrackers() []string {
loadNewTracker() loadNewTracker()
if len(loadedTrackers) == 0 { if len(loadedTrackers) == 0 {