-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
72 lines (65 loc) · 1.82 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"github.com/robfig/cron"
"os"
"seeder/src/config"
"seeder/src/datebase"
"seeder/src/nexus"
"seeder/src/qbittorrent"
"strconv"
)
func main() {
var db datebase.Client
var nodes []nexus.Client
var servers []qbittorrent.Server
cron := cron.New()
if cfg, err := config.GetConfig(); err == nil {
db = datebase.NewClient()
for _, value := range cfg.Node {
if value.Enable == true {
node := nexus.NewClient(value.Source, value.Limit, value.Passkey, value.Rule)
nodes = append(nodes, node)
}
}
for _, value := range cfg.Server {
if value.Enable == true {
server := qbittorrent.NewClientWrapper(value.Endpoint, value.Username, value.Password, value.Remark, value.Rule)
server.CalcEstimatedQuota()
server.ServerClean(cfg)
cron.AddFunc("@every 5s", func() { server.CalcEstimatedQuota() })
cron.AddFunc("@every 1m", func() { server.AnnounceRace() })
cron.AddFunc("@every 1m", func() { server.ServerClean(cfg) })
cron.Start()
servers = append(servers, server)
}
}
} else {
os.Exit(1)
}
for true {
var ts []nexus.Torrent
for _, node := range nodes {
ts, _ = node.Get()
for _, t := range ts {
// 解决重复添加问题
for _, server := range servers {
server.CalcEstimatedQuota()
if db.Get(t.GUID) == false {
if Size, err := strconv.Atoi(t.Size); err == nil {
if server.AddTorrentByURL(t.URL, Size, int(node.Rule.SpeedLimit*1024*1024)) == true {
fmt.Println("[添加]种子:" + t.Title)
db.Insert(t.Title, t.GUID, t.URL)
}
}
}
}
if db.Get(t.GUID) == false {
//找遍了所有服务器(10次尝试),还是没法找到添加的,那么,就直接插入数据库不再尝试.
fmt.Println("[忽略]种子:" + t.Title)
db.Insert(t.Title, t.GUID, t.URL)
}
}
}
}
}