From c1d2697e180dff8f9b2358f489b98b7399661f8a Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Tue, 30 Aug 2022 13:09:56 -0700 Subject: [PATCH] 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 --- pkg/qbittorrent/domain.go | 19 +++++++++-- pkg/qbittorrent/methods.go | 69 +++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/pkg/qbittorrent/domain.go b/pkg/qbittorrent/domain.go index 2cb20d1..4a2bda2 100644 --- a/pkg/qbittorrent/domain.go +++ b/pkg/qbittorrent/domain.go @@ -176,6 +176,9 @@ const ( // Torrent is being downloaded, but no connection were made 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 @@ -239,10 +242,11 @@ type TransferInfo struct { type ContentLayout string +// https://www.youtube.com/watch?v=4N1iwQxiHrs const ( - ContentLayoutOriginal ContentLayout = "ORIGINAL" - ContentLayoutSubfolderNone ContentLayout = "SUBFOLDER_NONE" - ContentLayoutSubfolderCreate ContentLayout = "SUBFOLDER_CREATE" + ContentLayoutOriginal ContentLayout = "Original" + ContentLayoutSubfolderNone ContentLayout = "NoSubfolder" + ContentLayoutSubfolderCreate ContentLayout = "Subfolder" ) type TorrentAddOptions struct { @@ -270,9 +274,18 @@ func (o *TorrentAddOptions) Prepare() map[string]string { } if o.ContentLayout != nil { if *o.ContentLayout == ContentLayoutSubfolderCreate { + // pre qBittorrent version 4.3.2 options["root_folder"] = "true" + + // post version 4.3.2 + options["contentLayout"] = string(ContentLayoutSubfolderCreate) + } else if *o.ContentLayout == ContentLayoutSubfolderNone { + // pre qBittorrent version 4.3.2 options["root_folder"] = "false" + + // post version 4.3.2 + options["contentLayout"] = string(ContentLayoutSubfolderNone) } // if ORIGINAL then leave empty } diff --git a/pkg/qbittorrent/methods.go b/pkg/qbittorrent/methods.go index 88ed567..7dd4ef3 100644 --- a/pkg/qbittorrent/methods.go +++ b/pkg/qbittorrent/methods.go @@ -64,14 +64,13 @@ func (c *Client) GetTorrents() ([]Torrent, error) { defer resp.Body.Close() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } var torrents []Torrent - err = json.Unmarshal(body, &torrents) - if err != nil { + if err := json.Unmarshal(body, &torrents); err != nil { 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() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } var torrents []Torrent - err = json.Unmarshal(body, &torrents) - if err != nil { + if err := json.Unmarshal(body, &torrents); err != nil { return nil, errors.Wrap(err, "could not unmarshal body") } @@ -118,15 +116,14 @@ func (c *Client) GetTorrentsActiveDownloads() ([]Torrent, error) { defer resp.Body.Close() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } var torrents []Torrent - err = json.Unmarshal(body, &torrents) - if err != nil { - return nil, errors.Wrap(readErr, "could not unmarshal body") + if err := json.Unmarshal(body, &torrents); err != nil { + return nil, errors.Wrap(err, "could not unmarshal body") } res := make([]Torrent, 0) @@ -183,16 +180,15 @@ func (c *Client) GetTorrentTrackers(hash string) ([]TorrentTracker, error) { return nil, nil } - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { return nil, errors.Wrap(err, "could not read body") } c.log.Printf("get torrent trackers body: %v\n", string(body)) var trackers []TorrentTracker - err = json.Unmarshal(body, &trackers) - if err != nil { + if err := json.Unmarshal(body, &trackers); err != nil { return nil, errors.Wrap(err, "could not unmarshal body") } @@ -262,15 +258,14 @@ func (c *Client) GetTransferInfo() (*TransferInfo, error) { defer resp.Body.Close() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } var info TransferInfo - err = json.Unmarshal(body, &info) - if err != nil { - return nil, errors.Wrap(readErr, "could not unmarshal body") + if err := json.Unmarshal(body, &info); err != nil { + return nil, errors.Wrap(err, "could not unmarshal body") } return &info, nil @@ -452,15 +447,14 @@ func (c *Client) GetFilesInformation(hash string) (*TorrentFiles, error) { defer resp.Body.Close() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } var info TorrentFiles - err = json.Unmarshal(body, &info) - if err != nil { - return nil, errors.Wrap(readErr, "could not unmarshal body") + if err := json.Unmarshal(body, &info); err != nil { + return nil, errors.Wrap(err, "could not unmarshal body") } return &info, nil @@ -474,15 +468,14 @@ func (c *Client) GetCategories() (map[string]Category, error) { defer resp.Body.Close() - body, readErr := ioutil.ReadAll(resp.Body) - if readErr != nil { - return nil, errors.Wrap(readErr, "could not read body") + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "could not read body") } m := make(map[string]Category) - err = json.Unmarshal(body, &m) - if err != nil { - return nil, errors.Wrap(readErr, "could not unmarshal body") + if err := json.Unmarshal(body, &m); err != nil { + return nil, errors.Wrap(err, "could not unmarshal body") } return m, nil