mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
fix(downloadclients): Deluge v1 save path (#915)
fix(downloadclients): Deluge v1 fix save path
This commit is contained in:
parent
a5d6da7373
commit
1abc260047
4 changed files with 75 additions and 58 deletions
2
go.mod
2
go.mod
|
@ -7,6 +7,7 @@ require (
|
|||
github.com/Masterminds/squirrel v1.5.3
|
||||
github.com/anacrolix/torrent v1.46.0
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
|
||||
github.com/autobrr/go-deluge v1.0.0
|
||||
github.com/autobrr/go-qbittorrent v1.3.1
|
||||
github.com/autobrr/go-rtorrent v1.0.1
|
||||
github.com/avast/retry-go v3.0.0+incompatible
|
||||
|
@ -14,7 +15,6 @@ require (
|
|||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/ergochat/irc-go v0.2.0
|
||||
github.com/fsnotify/fsnotify v1.5.4
|
||||
github.com/gdm85/go-libdeluge v0.5.6
|
||||
github.com/go-chi/chi/v5 v5.0.7
|
||||
github.com/go-chi/render v1.0.2
|
||||
github.com/gorilla/sessions v1.2.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -89,6 +89,8 @@ github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
|
|||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
|
||||
github.com/autobrr/go-deluge v1.0.0 h1:dGpA3elktcH8eQ5ctzpU5dTjzR0eOBOnrhTZEGPVv6E=
|
||||
github.com/autobrr/go-deluge v1.0.0/go.mod h1:ndiXT1eHWv/ATNk9TpE8GHIs8OSSUnsImt4Syk+y5LM=
|
||||
github.com/autobrr/go-qbittorrent v1.3.1 h1:yh+Ipj7Vs/waim7/efHGiYgnnM9oTDyFf2mBoBBc49Y=
|
||||
github.com/autobrr/go-qbittorrent v1.3.1/go.mod h1:z88B3+O/1/3doQABErvIOOxE4hjpmIpulu6XzDG/q78=
|
||||
github.com/autobrr/go-rtorrent v1.0.1 h1:KbSBGcgsThYs4qHBYyFlgSOhDhfRXkJoAxVkB0atIzg=
|
||||
|
@ -140,8 +142,6 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3
|
|||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/gdm85/go-libdeluge v0.5.6 h1:tSAwrlOAhu9VAMuxGacK/DMSmLN6SjHHhcVtg76fFnY=
|
||||
github.com/gdm85/go-libdeluge v0.5.6/go.mod h1:PATKp4wpfcubDL/uIWPSLcIFC0ear942OKvD3ZB4Vsk=
|
||||
github.com/gdm85/go-rencode v0.1.8 h1:7+qxwoQWU1b1nMGcESOyoUR5dzPtRA6yLQpKn7uXmnI=
|
||||
github.com/gdm85/go-rencode v0.1.8/go.mod h1:0dr3BuaKzeseY1of6o1KRTGB/Oo7eio+YEyz8KDp5+s=
|
||||
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
delugeClient "github.com/gdm85/go-libdeluge"
|
||||
"github.com/autobrr/go-deluge"
|
||||
)
|
||||
|
||||
func (s *service) deluge(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
|
@ -44,12 +44,12 @@ func (s *service) deluge(ctx context.Context, action *domain.Action, release dom
|
|||
return rejections, err
|
||||
}
|
||||
|
||||
func (s *service) delugeCheckRulesCanDownload(deluge delugeClient.DelugeClient, client *domain.DownloadClient, action *domain.Action) ([]string, error) {
|
||||
func (s *service) delugeCheckRulesCanDownload(ctx context.Context, del deluge.DelugeClient, client *domain.DownloadClient, action *domain.Action) ([]string, error) {
|
||||
s.log.Trace().Msgf("action Deluge: %v check rules", action.Name)
|
||||
|
||||
// check for active downloads and other rules
|
||||
if client.Settings.Rules.Enabled && !action.IgnoreRules {
|
||||
activeDownloads, err := deluge.TorrentsStatus(delugeClient.StateDownloading, nil)
|
||||
activeDownloads, err := del.TorrentsStatus(ctx, deluge.StateDownloading, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not fetch downloading torrents")
|
||||
}
|
||||
|
@ -90,27 +90,27 @@ func (s *service) delugeCheckRulesCanDownload(deluge delugeClient.DelugeClient,
|
|||
}
|
||||
|
||||
func (s *service) delugeV1(ctx context.Context, client *domain.DownloadClient, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
settings := delugeClient.Settings{
|
||||
settings := deluge.Settings{
|
||||
Hostname: client.Host,
|
||||
Port: uint(client.Port),
|
||||
Login: client.Username,
|
||||
Password: client.Password,
|
||||
DebugServerResponses: true,
|
||||
ReadWriteTimeout: time.Second * 20,
|
||||
ReadWriteTimeout: time.Second * 30,
|
||||
}
|
||||
|
||||
deluge := delugeClient.NewV1(settings)
|
||||
del := deluge.NewV1(settings)
|
||||
|
||||
// perform connection to Deluge server
|
||||
err := deluge.Connect()
|
||||
err := del.Connect(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not connect to client %s at %s", client.Name, client.Host)
|
||||
}
|
||||
|
||||
defer deluge.Close()
|
||||
defer del.Close()
|
||||
|
||||
// perform connection to Deluge server
|
||||
rejections, err := s.delugeCheckRulesCanDownload(deluge, client, action)
|
||||
rejections, err := s.delugeCheckRulesCanDownload(ctx, del, client, action)
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Msgf("error checking client rules: %s", action.Name)
|
||||
return nil, err
|
||||
|
@ -127,20 +127,20 @@ func (s *service) delugeV1(ctx context.Context, client *domain.DownloadClient, a
|
|||
|
||||
s.log.Trace().Msgf("action Deluge options: %+v", options)
|
||||
|
||||
torrentHash, err := deluge.AddTorrentMagnet(release.MagnetURI, &options)
|
||||
torrentHash, err := del.AddTorrentMagnet(ctx, release.MagnetURI, &options)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.TorrentURL, client.Name)
|
||||
}
|
||||
|
||||
if action.Label != "" {
|
||||
labelPluginActive, err := deluge.LabelPlugin()
|
||||
labelPluginActive, err := del.LabelPlugin(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not load label plugin for client: %s", client.Name)
|
||||
}
|
||||
|
||||
if labelPluginActive != nil {
|
||||
// TODO first check if label exists, if not, add it, otherwise set
|
||||
err = labelPluginActive.SetTorrentLabel(torrentHash, action.Label)
|
||||
err = labelPluginActive.SetTorrentLabel(ctx, torrentHash, action.Label)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not set label: %s on client: %s", action.Label, client.Name)
|
||||
}
|
||||
|
@ -176,20 +176,20 @@ func (s *service) delugeV1(ctx context.Context, client *domain.DownloadClient, a
|
|||
|
||||
s.log.Trace().Msgf("action Deluge options: %+v", options)
|
||||
|
||||
torrentHash, err := deluge.AddTorrentFile(release.TorrentTmpFile, encodedFile, &options)
|
||||
torrentHash, err := del.AddTorrentFile(ctx, release.TorrentTmpFile, encodedFile, &options)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Name)
|
||||
}
|
||||
|
||||
if action.Label != "" {
|
||||
labelPluginActive, err := deluge.LabelPlugin()
|
||||
labelPluginActive, err := del.LabelPlugin(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not load label plugin for client: %s", client.Name)
|
||||
}
|
||||
|
||||
if labelPluginActive != nil {
|
||||
// TODO first check if label exists, if not, add it, otherwise set
|
||||
err = labelPluginActive.SetTorrentLabel(torrentHash, action.Label)
|
||||
err = labelPluginActive.SetTorrentLabel(ctx, torrentHash, action.Label)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not set label: %v on client: %s", action.Label, client.Name)
|
||||
}
|
||||
|
@ -203,27 +203,27 @@ func (s *service) delugeV1(ctx context.Context, client *domain.DownloadClient, a
|
|||
}
|
||||
|
||||
func (s *service) delugeV2(ctx context.Context, client *domain.DownloadClient, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
settings := delugeClient.Settings{
|
||||
settings := deluge.Settings{
|
||||
Hostname: client.Host,
|
||||
Port: uint(client.Port),
|
||||
Login: client.Username,
|
||||
Password: client.Password,
|
||||
DebugServerResponses: true,
|
||||
ReadWriteTimeout: time.Second * 20,
|
||||
ReadWriteTimeout: time.Second * 30,
|
||||
}
|
||||
|
||||
deluge := delugeClient.NewV2(settings)
|
||||
del := deluge.NewV2(settings)
|
||||
|
||||
// perform connection to Deluge server
|
||||
err := deluge.Connect()
|
||||
err := del.Connect(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not connect to client %s at %s", client.Name, client.Host)
|
||||
}
|
||||
|
||||
defer deluge.Close()
|
||||
defer del.Close()
|
||||
|
||||
// perform connection to Deluge server
|
||||
rejections, err := s.delugeCheckRulesCanDownload(deluge, client, action)
|
||||
rejections, err := s.delugeCheckRulesCanDownload(ctx, del, client, action)
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Msgf("error checking client rules: %s", action.Name)
|
||||
return nil, err
|
||||
|
@ -240,20 +240,20 @@ func (s *service) delugeV2(ctx context.Context, client *domain.DownloadClient, a
|
|||
|
||||
s.log.Trace().Msgf("action Deluge options: %+v", options)
|
||||
|
||||
torrentHash, err := deluge.AddTorrentMagnet(release.MagnetURI, &options)
|
||||
torrentHash, err := del.AddTorrentMagnet(ctx, release.MagnetURI, &options)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.TorrentURL, client.Name)
|
||||
}
|
||||
|
||||
if action.Label != "" {
|
||||
labelPluginActive, err := deluge.LabelPlugin()
|
||||
labelPluginActive, err := del.LabelPlugin(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not load label plugin for client: %s", client.Name)
|
||||
}
|
||||
|
||||
if labelPluginActive != nil {
|
||||
// TODO first check if label exists, if not, add it, otherwise set
|
||||
err = labelPluginActive.SetTorrentLabel(torrentHash, action.Label)
|
||||
err = labelPluginActive.SetTorrentLabel(ctx, torrentHash, action.Label)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not set label: %s on client: %s", action.Label, client.Name)
|
||||
}
|
||||
|
@ -290,20 +290,20 @@ func (s *service) delugeV2(ctx context.Context, client *domain.DownloadClient, a
|
|||
|
||||
s.log.Trace().Msgf("action Deluge options: %+v", options)
|
||||
|
||||
torrentHash, err := deluge.AddTorrentFile(release.TorrentTmpFile, encodedFile, &options)
|
||||
torrentHash, err := del.AddTorrentFile(ctx, release.TorrentTmpFile, encodedFile, &options)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %s to client: %s", release.TorrentTmpFile, client.Name)
|
||||
}
|
||||
|
||||
if action.Label != "" {
|
||||
labelPluginActive, err := deluge.LabelPlugin()
|
||||
labelPluginActive, err := del.LabelPlugin(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not load label plugin for client: %s", client.Name)
|
||||
}
|
||||
|
||||
if labelPluginActive != nil {
|
||||
// TODO first check if label exists, if not, add it, otherwise set
|
||||
err = labelPluginActive.SetTorrentLabel(torrentHash, action.Label)
|
||||
err = labelPluginActive.SetTorrentLabel(ctx, torrentHash, action.Label)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not set label: %s on client: %s", action.Label, client.Name)
|
||||
}
|
||||
|
@ -316,10 +316,10 @@ func (s *service) delugeV2(ctx context.Context, client *domain.DownloadClient, a
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *service) prepareDelugeOptions(action *domain.Action) (delugeClient.Options, error) {
|
||||
func (s *service) prepareDelugeOptions(action *domain.Action) (deluge.Options, error) {
|
||||
|
||||
// set options
|
||||
options := delugeClient.Options{}
|
||||
options := deluge.Options{}
|
||||
|
||||
if action.Paused {
|
||||
options.AddPaused = &action.Paused
|
||||
|
|
|
@ -17,10 +17,12 @@ import (
|
|||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
"github.com/autobrr/autobrr/pkg/whisparr"
|
||||
|
||||
"github.com/autobrr/go-deluge"
|
||||
"github.com/autobrr/go-qbittorrent"
|
||||
"github.com/autobrr/go-rtorrent"
|
||||
delugeClient "github.com/gdm85/go-libdeluge"
|
||||
"github.com/dcarbone/zadapters/zstdlog"
|
||||
"github.com/hekmon/transmissionrpc/v2"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
func (s *service) testConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
|
@ -29,7 +31,7 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
|
|||
return s.testQbittorrentConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeDelugeV1, domain.DownloadClientTypeDelugeV2:
|
||||
return s.testDelugeConnection(client)
|
||||
return s.testDelugeConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeRTorrent:
|
||||
return s.testRTorrentConnection(ctx, client)
|
||||
|
@ -59,7 +61,7 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
|
|||
return s.testSabnzbdConnection(ctx, client)
|
||||
|
||||
default:
|
||||
return errors.New("unsupported client")
|
||||
return errors.New("unsupported client: %s", client.Type)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,44 +95,59 @@ func (s *service) testQbittorrentConnection(ctx context.Context, client domain.D
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testDelugeConnection(client domain.DownloadClient) error {
|
||||
var deluge delugeClient.DelugeClient
|
||||
|
||||
settings := delugeClient.Settings{
|
||||
func (s *service) testDelugeConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
settings := deluge.Settings{
|
||||
Hostname: client.Host,
|
||||
Port: uint(client.Port),
|
||||
Login: client.Username,
|
||||
Password: client.Password,
|
||||
DebugServerResponses: true,
|
||||
ReadWriteTimeout: time.Second * 10,
|
||||
ReadWriteTimeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
settings.Logger = zstdlog.NewStdLoggerWithLevel(s.log.With().Logger(), zerolog.TraceLevel)
|
||||
|
||||
var err error
|
||||
var version string
|
||||
|
||||
switch client.Type {
|
||||
case "DELUGE_V1":
|
||||
deluge = delugeClient.NewV1(settings)
|
||||
|
||||
case "DELUGE_V2":
|
||||
deluge = delugeClient.NewV2(settings)
|
||||
|
||||
default:
|
||||
deluge = delugeClient.NewV2(settings)
|
||||
}
|
||||
del := deluge.NewV1(settings)
|
||||
|
||||
// perform connection to Deluge server
|
||||
err := deluge.Connect()
|
||||
if err != nil {
|
||||
if err := del.Connect(ctx); err != nil {
|
||||
return errors.Wrap(err, "error logging into client: %v", client.Host)
|
||||
}
|
||||
|
||||
defer deluge.Close()
|
||||
defer del.Close()
|
||||
|
||||
// print daemon version
|
||||
ver, err := deluge.DaemonVersion()
|
||||
version, err = del.DaemonVersion(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get daemon version: %v", client.Host)
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("test client connection for Deluge: success - daemon version: %v", ver)
|
||||
case "DELUGE_V2":
|
||||
del := deluge.NewV2(settings)
|
||||
|
||||
// perform connection to Deluge server
|
||||
if err := del.Connect(ctx); err != nil {
|
||||
return errors.Wrap(err, "error logging into client: %v", client.Host)
|
||||
}
|
||||
|
||||
defer del.Close()
|
||||
|
||||
// print daemon version
|
||||
version, err = del.DaemonVersion(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get daemon version: %v", client.Host)
|
||||
}
|
||||
|
||||
default:
|
||||
return errors.New("unsupported deluge client version: %s", client.Type)
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("test client connection for Deluge: success - daemon version: %v", version)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue