-
Notifications
You must be signed in to change notification settings - Fork 40
/
torrent.go
144 lines (133 loc) · 6.15 KB
/
torrent.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package transmission
type (
// TorrentCommand is the root command to interact with Transmission via RPC
TorrentCommand struct {
Method string `json:"method,omitempty"`
Arguments TorrentArguments `json:"arguments,omitempty"`
Result string `json:"result,omitempty"`
}
// TorrentArguments specifies the TorrentCommand in more detail
TorrentArguments struct {
Fields []string `json:"fields,omitempty"`
Torrents []Torrent `json:"torrents,omitempty"`
Ids []int `json:"ids,omitempty"`
DeleteData bool `json:"delete-local-data,omitempty"`
DownloadDir string `json:"download-dir,omitempty"`
MetaInfo string `json:"metainfo,omitempty"`
Filename string `json:"filename,omitempty"`
TorrentAdded TorrentArgumentsAdded `json:"torrent-added"`
}
// TorrentArgumentsAdded specifies the torrent to get added data from
TorrentArgumentsAdded struct {
HashString string `json:"hashString"`
ID int64 `json:"id"`
Name string `json:"name"`
}
// Torrent represents a transmission torrent
Torrent struct {
ID int `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Added int `json:"addedDate"`
LeftUntilDone int64 `json:"leftUntilDone"`
Eta int `json:"eta"`
UploadRatio float64 `json:"uploadRatio"`
RateDownload int `json:"rateDownload"`
RateUpload int `json:"rateUpload"`
DownloadDir string `json:"downloadDir"`
IsFinished bool `json:"isFinished"`
PercentDone float64 `json:"percentDone"`
SeedRatioMode int `json:"seedRatioMode"`
HashString string `json:"hashString"`
Error int `json:"error"`
ErrorString string `json:"errorString"`
Files []File `json:"files"`
FilesStats []FileStat `json:"fileStats"`
TrackerStats []TrackerStat `json:"trackerStats"`
Peers []Peer `json:"peers"`
PeersConnected int `json:"peersConnected"`
PeersGettingFromUs int `json:"peersGettingFromUs"`
TotalSize int `json:"totalSize"`
UploadedEver int `json:"uploadedEver"`
}
// ByID implements the sort Interface to sort by ID
ByID []Torrent
// ByName implements the sort Interface to sort by Name
ByName []Torrent
// ByDate implements the sort Interface to sort by Date
ByDate []Torrent
// ByRatio implements the sort Interface to sort by Ratio
ByRatio []Torrent
// File is a file contained inside a torrent
File struct {
BytesCompleted int64 `json:"bytesCompleted"`
Length int64 `json:"length"`
Name string `json:"name"`
}
// FileStat describe a file's priority & if it's wanted
FileStat struct {
BytesCompleted int64 `json:"bytesCompleted"`
Priority int `json:"priority"`
Wanted bool `json:"wanted"`
}
// TrackerStat has stats about the torrent's tracker
TrackerStat struct {
Announce string `json:"announce"`
AnnounceState int `json:"announceState"`
DownloadCount int `json:"downloadCount"`
HasAnnounced bool `json:"hasAnnounced"`
HasScraped bool `json:"hasScraped"`
Host string `json:"host"`
ID int `json:"id"`
IsBackup bool `json:"isBackup"`
LastAnnouncePeerCount int `json:"lastAnnouncePeerCount"`
LastAnnounceResult string `json:"lastAnnounceResult"`
LastAnnounceStartTime int `json:"lastAnnounceStartTime"`
LastAnnounceSucceeded bool `json:"lastAnnounceSucceeded"`
LastAnnounceTime int `json:"lastAnnounceTime"`
LastAnnounceTimedOut bool `json:"lastAnnounceTimedOut"`
LastScrapeResult string `json:"lastScrapeResult"`
LastScrapeStartTime int `json:"lastScrapeStartTime"`
LastScrapeSucceeded bool `json:"lastScrapeSucceeded"`
LastScrapeTime int `json:"lastScrapeTime"`
LastScrapeTimedOut bool `json:"lastScrapeTimedOut"`
LeecherCount int `json:"leecherCount"`
NextAnnounceTime int `json:"nextAnnounceTime"`
NextScrapeTime int `json:"nextScrapeTime"`
Scrape string `json:"scrape"`
ScrapeState int `json:"scrapeState"`
SeederCount int `json:"seederCount"`
Tier int `json:"tier"`
}
// Peer of a torrent
Peer struct {
Address string `json:"address"`
ClientIsChoked bool `json:"clientIsChoked"`
ClientIsInterested bool `json:"clientIsInterested"`
ClientName string `json:"clientName"`
FlagStr string `json:"flagStr"`
IsDownloadingFrom bool `json:"isDownloadingFrom"`
IsEncrypted bool `json:"isEncrypted"`
IsIncoming bool `json:"isIncoming"`
IsUTP bool `json:"isUTP"`
IsUploadingTo bool `json:"isUploadingTo"`
PeerIsChoked bool `json:"peerIsChoked"`
PeerIsInterested bool `json:"peerIsInterested"`
Port int `json:"port"`
Progress float64 `json:"progress"`
RateToClient int `json:"rateToClient"`
RateToPeer int `json:"rateToPeer"`
}
)
func (t ByID) Len() int { return len(t) }
func (t ByID) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t ByID) Less(i, j int) bool { return t[i].ID < t[j].ID }
func (t ByName) Len() int { return len(t) }
func (t ByName) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t ByName) Less(i, j int) bool { return t[i].Name < t[j].Name }
func (t ByDate) Len() int { return len(t) }
func (t ByDate) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t ByDate) Less(i, j int) bool { return t[i].Added < t[j].Added }
func (t ByRatio) Len() int { return len(t) }
func (t ByRatio) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t ByRatio) Less(i, j int) bool { return t[i].UploadRatio < t[j].UploadRatio }