feat(qbit): implement errored filter (#447)

* feat(qbit): implement errored

* well, evidently there's some crashes.

* fix(qbit): contentlayout. 

reported by Vyerni a couple minutes ago

* fix(clients): qbit contentLayout
This commit is contained in:
Kyle Sanderson 2022-08-30 13:09:56 -07:00 committed by GitHub
parent 5a7614f954
commit c1d2697e18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 41 deletions

View file

@ -176,6 +176,9 @@ const (
// Torrent is being downloaded, but no connection were made // Torrent is being downloaded, but no connection were made
TorrentFilterStalledDownloading TorrentFilter = "stalled_downloading" TorrentFilterStalledDownloading TorrentFilter = "stalled_downloading"
// Torrent is errored
TorrentFilterError TorrentFilter = "errored"
) )
// TrackerStatus https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-trackers // TrackerStatus https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-trackers
@ -239,10 +242,11 @@ type TransferInfo struct {
type ContentLayout string type ContentLayout string
// https://www.youtube.com/watch?v=4N1iwQxiHrs
const ( const (
ContentLayoutOriginal ContentLayout = "ORIGINAL" ContentLayoutOriginal ContentLayout = "Original"
ContentLayoutSubfolderNone ContentLayout = "SUBFOLDER_NONE" ContentLayoutSubfolderNone ContentLayout = "NoSubfolder"
ContentLayoutSubfolderCreate ContentLayout = "SUBFOLDER_CREATE" ContentLayoutSubfolderCreate ContentLayout = "Subfolder"
) )
type TorrentAddOptions struct { type TorrentAddOptions struct {
@ -270,9 +274,18 @@ func (o *TorrentAddOptions) Prepare() map[string]string {
} }
if o.ContentLayout != nil { if o.ContentLayout != nil {
if *o.ContentLayout == ContentLayoutSubfolderCreate { if *o.ContentLayout == ContentLayoutSubfolderCreate {
// pre qBittorrent version 4.3.2
options["root_folder"] = "true" options["root_folder"] = "true"
// post version 4.3.2
options["contentLayout"] = string(ContentLayoutSubfolderCreate)
} else if *o.ContentLayout == ContentLayoutSubfolderNone { } else if *o.ContentLayout == ContentLayoutSubfolderNone {
// pre qBittorrent version 4.3.2
options["root_folder"] = "false" options["root_folder"] = "false"
// post version 4.3.2
options["contentLayout"] = string(ContentLayoutSubfolderNone)
} }
// if ORIGINAL then leave empty // if ORIGINAL then leave empty
} }

View file

@ -64,14 +64,13 @@ func (c *Client) GetTorrents() ([]Torrent, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
var torrents []Torrent var torrents []Torrent
err = json.Unmarshal(body, &torrents) if err := json.Unmarshal(body, &torrents); err != nil {
if err != nil {
return nil, errors.Wrap(err, "could not unmarshal body") return nil, errors.Wrap(err, "could not unmarshal body")
} }
@ -90,14 +89,13 @@ func (c *Client) GetTorrentsFilter(filter TorrentFilter) ([]Torrent, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
var torrents []Torrent var torrents []Torrent
err = json.Unmarshal(body, &torrents) if err := json.Unmarshal(body, &torrents); err != nil {
if err != nil {
return nil, errors.Wrap(err, "could not unmarshal body") return nil, errors.Wrap(err, "could not unmarshal body")
} }
@ -118,15 +116,14 @@ func (c *Client) GetTorrentsActiveDownloads() ([]Torrent, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
var torrents []Torrent var torrents []Torrent
err = json.Unmarshal(body, &torrents) if err := json.Unmarshal(body, &torrents); err != nil {
if err != nil { return nil, errors.Wrap(err, "could not unmarshal body")
return nil, errors.Wrap(readErr, "could not unmarshal body")
} }
res := make([]Torrent, 0) res := make([]Torrent, 0)
@ -183,16 +180,15 @@ func (c *Client) GetTorrentTrackers(hash string) ([]TorrentTracker, error) {
return nil, nil return nil, nil
} }
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(err, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
c.log.Printf("get torrent trackers body: %v\n", string(body)) c.log.Printf("get torrent trackers body: %v\n", string(body))
var trackers []TorrentTracker var trackers []TorrentTracker
err = json.Unmarshal(body, &trackers) if err := json.Unmarshal(body, &trackers); err != nil {
if err != nil {
return nil, errors.Wrap(err, "could not unmarshal body") return nil, errors.Wrap(err, "could not unmarshal body")
} }
@ -262,15 +258,14 @@ func (c *Client) GetTransferInfo() (*TransferInfo, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
var info TransferInfo var info TransferInfo
err = json.Unmarshal(body, &info) if err := json.Unmarshal(body, &info); err != nil {
if err != nil { return nil, errors.Wrap(err, "could not unmarshal body")
return nil, errors.Wrap(readErr, "could not unmarshal body")
} }
return &info, nil return &info, nil
@ -452,15 +447,14 @@ func (c *Client) GetFilesInformation(hash string) (*TorrentFiles, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
var info TorrentFiles var info TorrentFiles
err = json.Unmarshal(body, &info) if err := json.Unmarshal(body, &info); err != nil {
if err != nil { return nil, errors.Wrap(err, "could not unmarshal body")
return nil, errors.Wrap(readErr, "could not unmarshal body")
} }
return &info, nil return &info, nil
@ -474,15 +468,14 @@ func (c *Client) GetCategories() (map[string]Category, error) {
defer resp.Body.Close() defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if readErr != nil { if err != nil {
return nil, errors.Wrap(readErr, "could not read body") return nil, errors.Wrap(err, "could not read body")
} }
m := make(map[string]Category) m := make(map[string]Category)
err = json.Unmarshal(body, &m) if err := json.Unmarshal(body, &m); err != nil {
if err != nil { return nil, errors.Wrap(err, "could not unmarshal body")
return nil, errors.Wrap(readErr, "could not unmarshal body")
} }
return m, nil return m, nil