Skip to content

Commit

Permalink
fix: qbit progress
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Oct 4, 2024
1 parent 3af5f96 commit 7461918
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
36 changes: 18 additions & 18 deletions pkg/go-qbittorrent/qbt/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package qbt

//BasicTorrent holds a basic torrent object from qbittorrent
// BasicTorrent holds a basic torrent object from qbittorrent
type BasicTorrent struct {
Category string `json:"category"`
CompletionOn int64 `json:"completion_on"`
Expand All @@ -25,8 +25,8 @@ type BasicTorrent struct {
FirstLastPiecePriority bool `json:"f_l_piece_prio"`
}

//Torrent holds a torrent object from qbittorrent
//with more information than BasicTorrent
// Torrent holds a torrent object from qbittorrent
// with more information than BasicTorrent
type Torrent struct {
AdditionDate int `json:"addition_date"`
Comment string `json:"comment"`
Expand Down Expand Up @@ -90,7 +90,7 @@ type TorrentInfo struct {
NumLeechs int64 `json:"num_leechs"`
NumSeeds int64 `json:"num_seeds"`
Priority int64 `json:"priority"`
Progress int64 `json:"progress"`
Progress float64 `json:"progress"`
Ratio float64 `json:"ratio"`
RatioLimit int64 `json:"ratio_limit"`
SavePath string `json:"save_path"`
Expand All @@ -111,7 +111,7 @@ type TorrentInfo struct {
Upspeed int64 `json:"upspeed"`
}

//Tracker holds a tracker object from qbittorrent
// Tracker holds a tracker object from qbittorrent
type Tracker struct {
Msg string `json:"msg"`
NumPeers int `json:"num_peers"`
Expand All @@ -123,12 +123,12 @@ type Tracker struct {
URL string `json:"url"`
}

//WebSeed holds a webseed object from qbittorrent
// WebSeed holds a webseed object from qbittorrent
type WebSeed struct {
URL string `json:"url"`
}

//TorrentFile holds a torrent file object from qbittorrent
// TorrentFile holds a torrent file object from qbittorrent
type TorrentFile struct {
Index int `json:"index"`
IsSeed bool `json:"is_seed"`
Expand All @@ -140,8 +140,8 @@ type TorrentFile struct {
PieceRange []int `json:"piece_range"`
}

//Sync holds the sync response struct which contains
//the server state and a map of infohashes to Torrents
// Sync holds the sync response struct which contains
// the server state and a map of infohashes to Torrents
type Sync struct {
Categories []string `json:"categories"`
FullUpdate bool `json:"full_update"`
Expand Down Expand Up @@ -274,15 +274,15 @@ type Preferences struct {
RSSAutoDlEnabled bool `json:"rss_auto_downloading_enabled"`
}

//Log
// Log
type Log struct {
ID int `json:"id"`
Message string `json:"message"`
Timestamp int `json:"timestamp"`
Type int `json:"type"`
}

//PeerLog
// PeerLog
type PeerLog struct {
ID int `json:"id"`
IP string `json:"ip"`
Expand All @@ -291,7 +291,7 @@ type PeerLog struct {
Reason string `json:"reason"`
}

//Info
// Info
type Info struct {
ConnectionStatus string `json:"connection_status"`
DHTNodes int `json:"dht_nodes"`
Expand All @@ -316,37 +316,37 @@ type TorrentsOptions struct {
Hashes []string // separated by | => optional
}

//Category of torrent
// Category of torrent
type Category struct {
Name string `json:"name"`
SavePath string `json:"savePath"`
}

//Categories mapping
// Categories mapping
type Categories struct {
Category map[string]Category
}

//LoginOptions contains all options for /login endpoint
// LoginOptions contains all options for /login endpoint
type LoginOptions struct {
Username string
Password string
}

//AddTrackersOptions contains all options for /addTrackers endpoint
// AddTrackersOptions contains all options for /addTrackers endpoint
type AddTrackersOptions struct {
Hash string
Trackers []string
}

//EditTrackerOptions contains all options for /editTracker endpoint
// EditTrackerOptions contains all options for /editTracker endpoint
type EditTrackerOptions struct {
Hash string
OrigURL string
NewURL string
}

//RemoveTrackersOptions contains all options for /removeTrackers endpoint
// RemoveTrackersOptions contains all options for /removeTrackers endpoint
type RemoveTrackersOptions struct {
Hash string
Trackers []string
Expand Down
10 changes: 9 additions & 1 deletion pkg/qbittorrent/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ func (t *Torrent) Progress() (int, error) {
if err != nil {
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 {
Expand Down

0 comments on commit 7461918

Please sign in to comment.