-
Notifications
You must be signed in to change notification settings - Fork 15
/
client.go
128 lines (115 loc) · 2.56 KB
/
client.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
var currentClientType = ""
// 重复判断 nil 是因为输出的类型转换 (qB_MainDataStruct -> interface{}) 会导致 nil 比较失效.
func IsBanPort() bool {
if currentClientType == "qBittorrent" && qB_useNewBanPeersMethod {
return true
}
return false
}
func IsSupportClient() bool {
switch currentClientType {
case "qBittorrent", "Transmission", "BitComet":
return true
}
return false
}
func InitClient() {
if currentClientType == "Transmission" {
Tr_InitClient()
}
}
func SetURLFromClient() {
// 未设置的情况下, 应按内部客户端顺序逐个测试.
if config.ClientURL == "" {
if !qB_SetURL() {
Tr_SetURL()
}
}
}
func DetectClient() bool {
if config.ClientType != "" {
currentClientType = config.ClientType
return true
}
currentClientType = "qBittorrent"
if qB_GetAPIVersion() {
Log("DetectClient", GetLangText("Success-DetectClient"), true, currentClientType)
return true
}
currentClientType = "Transmission"
if Tr_DetectVersion() {
Log("DetectClient", GetLangText("Success-DetectClient"), true, currentClientType)
return true
}
currentClientType = "BitComet"
if BC_DetectClient() {
Log("DetectClient", GetLangText("Success-DetectClient"), true, currentClientType)
return true
}
currentClientType = ""
return false
}
func Login() bool {
switch currentClientType {
case "qBittorrent":
return qB_Login()
case "Transmission":
return Tr_Login()
case "BitComet":
return BC_Login()
}
return false
}
func FetchTorrents() interface{} {
switch currentClientType {
case "qBittorrent":
maindata := qB_FetchTorrents()
if maindata == nil {
return nil
}
return maindata
case "Transmission":
maindata := Tr_FetchTorrents()
if maindata == nil {
return nil
}
return maindata
case "BitComet":
maindata := BC_FetchTorrents()
if maindata == nil {
return nil
}
return maindata
}
return nil
}
func FetchTorrentPeers(infoHash string) interface{} {
switch currentClientType {
case "qBittorrent":
torrentPeers := qB_FetchTorrentPeers(infoHash)
if torrentPeers == nil {
return nil
}
return torrentPeers
case "BitComet":
torrentPeers := BC_FetchTorrentPeers(infoHash)
if torrentPeers == nil {
return nil
}
return torrentPeers
}
return nil
}
func SubmitBlockPeer(blockPeerMap map[string]BlockPeerInfoStruct) bool {
if blockPeerMap == nil {
return true
}
switch currentClientType {
case "qBittorrent":
return qB_SubmitBlockPeer(blockPeerMap)
case "Transmission":
return Tr_SubmitBlockPeer(blockPeerMap)
}
return false
}