mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(clients): qBittorrent rules ignore slow (#1200)
fix(clients): qBit rules ignore slow
This commit is contained in:
parent
ee0d055743
commit
d602b1e868
3 changed files with 77 additions and 62 deletions
|
@ -19,7 +19,9 @@ func (s *service) qbittorrent(ctx context.Context, action *domain.Action, releas
|
|||
|
||||
c := s.clientSvc.GetCachedClient(ctx, action.ClientID)
|
||||
|
||||
rejections, err := s.qbittorrentCheckRulesCanDownload(ctx, action, c.Dc, c.Qbt)
|
||||
if c.Dc.Settings.Rules.Enabled && !action.IgnoreRules {
|
||||
// check for active downloads and other rules
|
||||
rejections, err := s.qbittorrentCheckRulesCanDownload(ctx, action, c.Dc.Settings.Rules, c.Qbt)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error checking client rules: %s", action.Name)
|
||||
}
|
||||
|
@ -27,6 +29,7 @@ func (s *service) qbittorrent(ctx context.Context, action *domain.Action, releas
|
|||
if len(rejections) > 0 {
|
||||
return rejections, nil
|
||||
}
|
||||
}
|
||||
|
||||
if release.HasMagnetUri() {
|
||||
options, err := s.prepareQbitOptions(action)
|
||||
|
@ -140,93 +143,100 @@ func (s *service) prepareQbitOptions(action *domain.Action) (map[string]string,
|
|||
return opts.Prepare(), nil
|
||||
}
|
||||
|
||||
func (s *service) qbittorrentCheckRulesCanDownload(ctx context.Context, action *domain.Action, client *domain.DownloadClient, qbt *qbittorrent.Client) ([]string, error) {
|
||||
s.log.Trace().Msgf("action qBittorrent: %v check rules", action.Name)
|
||||
// qbittorrentCheckRulesCanDownload
|
||||
func (s *service) qbittorrentCheckRulesCanDownload(ctx context.Context, action *domain.Action, rules domain.DownloadClientRules, qbt *qbittorrent.Client) ([]string, error) {
|
||||
s.log.Trace().Msgf("action qBittorrent: %s check rules", action.Name)
|
||||
|
||||
checked := false
|
||||
// make sure it's not set to 0 by default
|
||||
if rules.MaxActiveDownloads > 0 {
|
||||
|
||||
// check for active downloads and other rules
|
||||
if client.Settings.Rules.Enabled && !action.IgnoreRules {
|
||||
// get active downloads
|
||||
activeDownloads, err := qbt.GetTorrentsActiveDownloadsCtx(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not fetch active downloads")
|
||||
}
|
||||
|
||||
// make sure it's not set to 0 by default
|
||||
if client.Settings.Rules.MaxActiveDownloads > 0 {
|
||||
|
||||
// if max active downloads reached, check speed and if lower than threshold add anyway
|
||||
if len(activeDownloads) >= client.Settings.Rules.MaxActiveDownloads {
|
||||
if client.Settings.Rules.IgnoreSlowTorrents {
|
||||
if client.Settings.Rules.IgnoreSlowTorrentsCondition == domain.IgnoreSlowTorrentsModeMaxReached {
|
||||
rejections, err := s.qbittorrentCheckIgnoreSlow(ctx, client, qbt)
|
||||
if err != nil {
|
||||
return rejections, err
|
||||
}
|
||||
|
||||
s.log.Debug().Msg("active downloads are slower than set limit, lets add it")
|
||||
|
||||
checked = true
|
||||
}
|
||||
} else {
|
||||
if len(activeDownloads) >= rules.MaxActiveDownloads {
|
||||
// if we do not care about slow torrents then return early
|
||||
if !rules.IgnoreSlowTorrents {
|
||||
rejection := "max active downloads reached, skipping"
|
||||
|
||||
s.log.Debug().Msg(rejection)
|
||||
|
||||
return []string{rejection}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !checked && client.Settings.Rules.IgnoreSlowTorrentsCondition == domain.IgnoreSlowTorrentsModeAlways {
|
||||
rejections, err := s.qbittorrentCheckIgnoreSlow(ctx, client, qbt)
|
||||
if err != nil {
|
||||
return rejections, err
|
||||
}
|
||||
|
||||
if len(rejections) > 0 {
|
||||
return rejections, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *service) qbittorrentCheckIgnoreSlow(ctx context.Context, client *domain.DownloadClient, qbt *qbittorrent.Client) ([]string, error) {
|
||||
if rules.IgnoreSlowTorrentsCondition == domain.IgnoreSlowTorrentsModeMaxReached {
|
||||
// get transfer info
|
||||
info, err := qbt.GetTransferInfoCtx(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get transfer info")
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("checking client ignore slow torrent rules: %+v", info)
|
||||
|
||||
if client.Settings.Rules.DownloadSpeedThreshold > 0 {
|
||||
// if current transfer speed is more than threshold return out and skip
|
||||
// DlInfoSpeed is in bytes so lets convert to KB to match DownloadSpeedThreshold
|
||||
if info.DlInfoSpeed/1024 >= client.Settings.Rules.DownloadSpeedThreshold {
|
||||
rejection := fmt.Sprintf("max active downloads reached and total download speed (%d) above threshold: (%d), skipping", info.DlInfoSpeed/1024, client.Settings.Rules.DownloadSpeedThreshold)
|
||||
|
||||
s.log.Debug().Msg(rejection)
|
||||
|
||||
return []string{rejection}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if client.Settings.Rules.UploadSpeedThreshold > 0 {
|
||||
// if current transfer speed is more than threshold return out and skip
|
||||
// UpInfoSpeed is in bytes so lets convert to KB to match UploadSpeedThreshold
|
||||
if info.UpInfoSpeed/1024 >= client.Settings.Rules.UploadSpeedThreshold {
|
||||
rejection := fmt.Sprintf("max active downloads reached and total upload speed (%d) above threshold: (%d), skipping", info.UpInfoSpeed/1024, client.Settings.Rules.UploadSpeedThreshold)
|
||||
|
||||
s.log.Debug().Msg(rejection)
|
||||
|
||||
return []string{rejection}, nil
|
||||
}
|
||||
rejections := s.qbittorrentCheckIgnoreSlow(rules.DownloadSpeedThreshold, rules.UploadSpeedThreshold, info)
|
||||
if len(rejections) > 0 {
|
||||
return rejections, nil
|
||||
}
|
||||
|
||||
s.log.Debug().Msg("active downloads are slower than set limit, lets add it")
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// if less, then we must check if ignore slow always which means we can't return here
|
||||
}
|
||||
|
||||
// if max active downloads is unlimited or not reached, lets check if ignore slow always should be checked
|
||||
if rules.IgnoreSlowTorrentsCondition == domain.IgnoreSlowTorrentsModeAlways {
|
||||
// get transfer info
|
||||
info, err := qbt.GetTransferInfoCtx(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get transfer info")
|
||||
}
|
||||
|
||||
rejections := s.qbittorrentCheckIgnoreSlow(rules.DownloadSpeedThreshold, rules.UploadSpeedThreshold, info)
|
||||
if len(rejections) > 0 {
|
||||
return rejections, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *service) qbittorrentCheckIgnoreSlow(downloadSpeedThreshold int64, uploadSpeedThreshold int64, info *qbittorrent.TransferInfo) []string {
|
||||
s.log.Debug().Msgf("checking client ignore slow torrent rules: %+v", info)
|
||||
|
||||
rejections := make([]string, 0)
|
||||
|
||||
if downloadSpeedThreshold > 0 {
|
||||
// if current transfer speed is more than threshold return out and skip
|
||||
// DlInfoSpeed is in bytes so lets convert to KB to match DownloadSpeedThreshold
|
||||
if info.DlInfoSpeed/1024 >= downloadSpeedThreshold {
|
||||
rejection := fmt.Sprintf("total download speed (%d) above threshold: (%d), skipping", info.DlInfoSpeed/1024, downloadSpeedThreshold)
|
||||
|
||||
s.log.Debug().Msg(rejection)
|
||||
|
||||
rejections = append(rejections, rejection)
|
||||
}
|
||||
}
|
||||
|
||||
if uploadSpeedThreshold > 0 {
|
||||
// if current transfer speed is more than threshold return out and skip
|
||||
// UpInfoSpeed is in bytes so lets convert to KB to match UploadSpeedThreshold
|
||||
if info.UpInfoSpeed/1024 >= uploadSpeedThreshold {
|
||||
rejection := fmt.Sprintf("total upload speed (%d) above threshold: (%d), skipping", info.UpInfoSpeed/1024, uploadSpeedThreshold)
|
||||
|
||||
s.log.Debug().Msg(rejection)
|
||||
|
||||
rejections = append(rejections, rejection)
|
||||
}
|
||||
}
|
||||
|
||||
s.log.Debug().Msg("active downloads are slower than set limit, lets add it")
|
||||
|
||||
return rejections
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import {
|
|||
TextFieldWide
|
||||
} from "@components/inputs";
|
||||
import { clientKeys } from "@screens/settings/DownloadClient";
|
||||
import { SelectFieldWide } from "@components/inputs/input_wide";
|
||||
import { DocsLink, ExternalLink } from "@components/ExternalLink";
|
||||
import {SelectFieldBasic} from "@components/inputs/select_wide";
|
||||
|
||||
interface InitialValuesSettings {
|
||||
basic?: {
|
||||
|
@ -37,6 +37,7 @@ interface InitialValuesSettings {
|
|||
rules?: {
|
||||
enabled?: boolean;
|
||||
ignore_slow_torrents?: boolean;
|
||||
ignore_slow_torrents_condition?: IgnoreTorrentsCondition;
|
||||
download_speed_threshold?: number;
|
||||
max_active_downloads?: number;
|
||||
};
|
||||
|
@ -464,6 +465,7 @@ function FormFieldsRulesQbit() {
|
|||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
<SwitchGroupWide
|
||||
name="settings.rules.ignore_slow_torrents"
|
||||
label="Ignore slow torrents"
|
||||
|
@ -471,10 +473,10 @@ function FormFieldsRulesQbit() {
|
|||
|
||||
{settings.rules?.ignore_slow_torrents === true && (
|
||||
<>
|
||||
<SelectFieldWide
|
||||
<SelectFieldBasic
|
||||
name="settings.rules.ignore_slow_torrents_condition"
|
||||
label="Ignore condition"
|
||||
optionDefaultText="Select ignore condition"
|
||||
placeholder="Select ignore condition"
|
||||
options={DownloadRuleConditionOptions}
|
||||
tooltip={<p>Choose whether to respect or ignore the <code className="text-blue-400">Max active downloads</code> setting before checking speed thresholds.</p>}
|
||||
/>
|
||||
|
|
3
web/src/types/Download.d.ts
vendored
3
web/src/types/Download.d.ts
vendored
|
@ -31,10 +31,13 @@ interface DownloadClientRules {
|
|||
enabled: boolean;
|
||||
max_active_downloads: number;
|
||||
ignore_slow_torrents: boolean;
|
||||
ignore_slow_torrents_condition: IgnoreTorrentsCondition;
|
||||
download_speed_threshold: number;
|
||||
upload_speed_threshold: number;
|
||||
}
|
||||
|
||||
type IgnoreTorrentsCondition = "ALWAYS" | "MAX_DOWNLOADS_REACHED";
|
||||
|
||||
interface DownloadClientBasicAuth {
|
||||
auth: boolean;
|
||||
username: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue