-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathstatus.go
More file actions
131 lines (111 loc) · 5.66 KB
/
status.go
File metadata and controls
131 lines (111 loc) · 5.66 KB
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
package arigo
import (
"encoding/json"
"time"
)
// DownloadStatus represents the status of a download.
type DownloadStatus string
const (
// StatusActive represents currently downloading/seeding downloads
StatusActive DownloadStatus = "active"
// StatusWaiting represents downloads in the queue
StatusWaiting DownloadStatus = "waiting"
// StatusPaused represents paused downloads
StatusPaused DownloadStatus = "paused"
// StatusError represents downloads that were stopped because of error
StatusError DownloadStatus = "error"
// StatusCompleted represents stopped and completed downloads
StatusCompleted DownloadStatus = "complete"
// StatusRemoved represents the downloads removed by user
StatusRemoved DownloadStatus = "removed"
)
// Status holds information for a download.
type Status struct {
GID string `json:"gid"` // gid of the download
Status DownloadStatus `json:"status"` // Download status
TotalLength uint `json:"totalLength,string"` // Total length of the download in bytes
CompletedLength uint `json:"completedLength,string"` // Completed length of the download in bytes
UploadLength uint `json:"uploadLength,string"` // Uploaded length of the download in bytes
// Hexadecimal representation of the download progress.
// The highest bit corresponds to the piece at index 0. Any set bits indicate loaded pieces,
// while unset bits indicate not yet loaded and/or missing pieces.
// Any overflow bits at the end are set to zero.
// When the download was not started yet, this will be an empty string.
BitField string `json:"bitfield"`
DownloadSpeed uint `json:"downloadSpeed,string"` // Download speed of this download measured in bytes/sec
UploadSpeed uint `json:"uploadSpeed,string"` // Upload speed of this download measured in bytes/sec
InfoHash string `json:"infoHash"` // InfoHash. BitTorrent only
// The number of seeders aria2 has connected to. BitTorrent only
NumSeeders uint `json:"numSeeders,string"`
// true if the local endpoint is a seeder. Otherwise false. BitTorrent only
Seeder bool `json:"seeder,string"`
PieceLength uint `json:"pieceLength,string"` // Piece length in bytes
NumPieces uint `json:"numPieces,string"` // The number of pieces
Connections uint `json:"connections,string"` // The number of peers/servers aria2 has connected to
ErrorCode ExitStatus `json:"errorCode,string"` // The code of the last error for this item, if any.
ErrorMessage string `json:"errorMessage"` // The human readable error message associated to ErrorCode
// List of GIDs which are generated as the result of this download.
// For example, when aria2 downloads a Metalink file, it generates downloads described in the Metalink
// (see the --follow-metalink option). This value is useful to track auto-generated downloads.
// If there are no such downloads, this will be an empty slice
FollowedBy []string `json:"followedBy"`
// The reverse link for followedBy.
// A download included in followedBy has this object’s GID in its following
// value.
Following string `json:"following"`
// GID of a parent download. Some downloads are a part of another download.
// For example, if a file in a Metalink has BitTorrent resources,
// the downloads of “.torrent” files are parts of that parent.
// If this download has no parent, this will be an empty string
BelongsTo string `json:"belongsTo"`
Dir string `json:"dir"` // Directory to save files
Files []File `json:"files"` // Slice of files.
BitTorrent BitTorrentStatus `json:"bittorrent"` // Information retrieved from the .torrent (file). BitTorrent only
// The number of verified number of bytes while the files are being has
// checked.
// This key exists only when this download is being hash checked
VerifiedLength uint `json:"verifiedLength,string"`
// true if this download is waiting for the hash check in a queue.
VerifyIntegrityPending bool `json:"verifyIntegrityPending,string"`
}
// UNIXTime is a wrapper around time.Time that marshals to a unix timestamp.
type UNIXTime struct {
time.Time
}
// MarshalJSON converts the time to a unix timestamp
func (t UNIXTime) MarshalJSON() ([]byte, error) {
return json.Marshal(t.Unix())
}
// UnmarshalJSON loads a unix timestamp
func (t *UNIXTime) UnmarshalJSON(data []byte) error {
var ts int64
err := json.Unmarshal(data, &ts)
if err != nil {
return err
}
*t = UNIXTime{time.Unix(ts, 0)}
return nil
}
// TorrentMode represents the file mode of the torrent
type TorrentMode string
const (
// TorrentModeSingle represents the file mode single
TorrentModeSingle TorrentMode = "single"
// TorrentModeMulti represents the file mode multi
TorrentModeMulti TorrentMode = "multi"
)
// BitTorrentStatus holds information for a BitTorrent download
type BitTorrentStatus struct {
// List of lists of announce URIs.
// If the torrent contains announce and no announce-list,
// announce is converted to the announce-list format
AnnounceList [][]string `json:"announceList"` // List of lists of announce URIs.
Comment string `json:"comment"` // The comment of the torrent
CreationDate UNIXTime `json:"creationDate"` // The creation time of the torrent
Mode TorrentMode `json:"mode"` // File mode of the torrent
Info BitTorrentStatusInfo `json:"info"` // Information from the info dictionary
}
// A BitTorrentStatusInfo holds information from the info dictionary.
type BitTorrentStatusInfo struct {
Name string `json:"name"` // name in info dictionary
}