mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
trackers from file
This commit is contained in:
@@ -65,6 +65,11 @@ func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -5,8 +5,11 @@ import (
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"server/settings"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
@@ -27,6 +30,22 @@ var defTrackers = []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 {
|
||||
loadNewTracker()
|
||||
if len(loadedTrackers) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user