fix: qbit progress

This commit is contained in:
Simon Ding
2024-10-04 11:36:12 +08:00
parent 3af5f96cb0
commit 7461918a6c
2 changed files with 27 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
package qbt package qbt
//BasicTorrent holds a basic torrent object from qbittorrent // BasicTorrent holds a basic torrent object from qbittorrent
type BasicTorrent struct { type BasicTorrent struct {
Category string `json:"category"` Category string `json:"category"`
CompletionOn int64 `json:"completion_on"` CompletionOn int64 `json:"completion_on"`
@@ -25,8 +25,8 @@ type BasicTorrent struct {
FirstLastPiecePriority bool `json:"f_l_piece_prio"` FirstLastPiecePriority bool `json:"f_l_piece_prio"`
} }
//Torrent holds a torrent object from qbittorrent // Torrent holds a torrent object from qbittorrent
//with more information than BasicTorrent // with more information than BasicTorrent
type Torrent struct { type Torrent struct {
AdditionDate int `json:"addition_date"` AdditionDate int `json:"addition_date"`
Comment string `json:"comment"` Comment string `json:"comment"`
@@ -90,7 +90,7 @@ type TorrentInfo struct {
NumLeechs int64 `json:"num_leechs"` NumLeechs int64 `json:"num_leechs"`
NumSeeds int64 `json:"num_seeds"` NumSeeds int64 `json:"num_seeds"`
Priority int64 `json:"priority"` Priority int64 `json:"priority"`
Progress int64 `json:"progress"` Progress float64 `json:"progress"`
Ratio float64 `json:"ratio"` Ratio float64 `json:"ratio"`
RatioLimit int64 `json:"ratio_limit"` RatioLimit int64 `json:"ratio_limit"`
SavePath string `json:"save_path"` SavePath string `json:"save_path"`
@@ -111,7 +111,7 @@ type TorrentInfo struct {
Upspeed int64 `json:"upspeed"` Upspeed int64 `json:"upspeed"`
} }
//Tracker holds a tracker object from qbittorrent // Tracker holds a tracker object from qbittorrent
type Tracker struct { type Tracker struct {
Msg string `json:"msg"` Msg string `json:"msg"`
NumPeers int `json:"num_peers"` NumPeers int `json:"num_peers"`
@@ -123,12 +123,12 @@ type Tracker struct {
URL string `json:"url"` URL string `json:"url"`
} }
//WebSeed holds a webseed object from qbittorrent // WebSeed holds a webseed object from qbittorrent
type WebSeed struct { type WebSeed struct {
URL string `json:"url"` URL string `json:"url"`
} }
//TorrentFile holds a torrent file object from qbittorrent // TorrentFile holds a torrent file object from qbittorrent
type TorrentFile struct { type TorrentFile struct {
Index int `json:"index"` Index int `json:"index"`
IsSeed bool `json:"is_seed"` IsSeed bool `json:"is_seed"`
@@ -140,8 +140,8 @@ type TorrentFile struct {
PieceRange []int `json:"piece_range"` PieceRange []int `json:"piece_range"`
} }
//Sync holds the sync response struct which contains // Sync holds the sync response struct which contains
//the server state and a map of infohashes to Torrents // the server state and a map of infohashes to Torrents
type Sync struct { type Sync struct {
Categories []string `json:"categories"` Categories []string `json:"categories"`
FullUpdate bool `json:"full_update"` FullUpdate bool `json:"full_update"`
@@ -274,7 +274,7 @@ type Preferences struct {
RSSAutoDlEnabled bool `json:"rss_auto_downloading_enabled"` RSSAutoDlEnabled bool `json:"rss_auto_downloading_enabled"`
} }
//Log // Log
type Log struct { type Log struct {
ID int `json:"id"` ID int `json:"id"`
Message string `json:"message"` Message string `json:"message"`
@@ -282,7 +282,7 @@ type Log struct {
Type int `json:"type"` Type int `json:"type"`
} }
//PeerLog // PeerLog
type PeerLog struct { type PeerLog struct {
ID int `json:"id"` ID int `json:"id"`
IP string `json:"ip"` IP string `json:"ip"`
@@ -291,7 +291,7 @@ type PeerLog struct {
Reason string `json:"reason"` Reason string `json:"reason"`
} }
//Info // Info
type Info struct { type Info struct {
ConnectionStatus string `json:"connection_status"` ConnectionStatus string `json:"connection_status"`
DHTNodes int `json:"dht_nodes"` DHTNodes int `json:"dht_nodes"`
@@ -316,37 +316,37 @@ type TorrentsOptions struct {
Hashes []string // separated by | => optional Hashes []string // separated by | => optional
} }
//Category of torrent // Category of torrent
type Category struct { type Category struct {
Name string `json:"name"` Name string `json:"name"`
SavePath string `json:"savePath"` SavePath string `json:"savePath"`
} }
//Categories mapping // Categories mapping
type Categories struct { type Categories struct {
Category map[string]Category Category map[string]Category
} }
//LoginOptions contains all options for /login endpoint // LoginOptions contains all options for /login endpoint
type LoginOptions struct { type LoginOptions struct {
Username string Username string
Password string Password string
} }
//AddTrackersOptions contains all options for /addTrackers endpoint // AddTrackersOptions contains all options for /addTrackers endpoint
type AddTrackersOptions struct { type AddTrackersOptions struct {
Hash string Hash string
Trackers []string Trackers []string
} }
//EditTrackerOptions contains all options for /editTracker endpoint // EditTrackerOptions contains all options for /editTracker endpoint
type EditTrackerOptions struct { type EditTrackerOptions struct {
Hash string Hash string
OrigURL string OrigURL string
NewURL string NewURL string
} }
//RemoveTrackersOptions contains all options for /removeTrackers endpoint // RemoveTrackersOptions contains all options for /removeTrackers endpoint
type RemoveTrackersOptions struct { type RemoveTrackersOptions struct {
Hash string Hash string
Trackers []string Trackers []string

View File

@@ -128,7 +128,15 @@ func (t *Torrent) Progress() (int, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
return int(qb.Progress), nil p := qb.Progress * 100
if p >= 100 {
return 100, nil
}
if int(p) == 100 {
return 99, nil
}
return int(p), nil
} }
func (t *Torrent) Stop() error { func (t *Torrent) Stop() error {