mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
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:
parent
5a7614f954
commit
c1d2697e18
2 changed files with 47 additions and 41 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue