feat(clients): add rTorrent support (#421)

This commit is contained in:
ze0s 2022-08-21 21:42:07 +02:00 committed by GitHub
parent 765215270a
commit 54d7151894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 692 additions and 541 deletions

View file

@ -0,0 +1,68 @@
package action
import (
"context"
"io/ioutil"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/mrobinsn/go-rtorrent/rtorrent"
)
func (s *service) rtorrent(action domain.Action, release domain.Release) ([]string, error) {
s.log.Debug().Msgf("action rTorrent: %v", action.Name)
var err error
// get client for action
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
if err != nil {
s.log.Error().Stack().Err(err).Msgf("error finding client: %v", action.ClientID)
return nil, err
}
if client == nil {
return nil, errors.New("could not find client by id: %v", action.ClientID)
}
var rejections []string
if release.TorrentTmpFile == "" {
if err = release.DownloadTorrentFile(); err != nil {
s.log.Error().Err(err).Msgf("could not download torrent file for release: %v", release.TorrentName)
return nil, err
}
}
// create client
rt := rtorrent.New(client.Host, true)
tmpFile, err := ioutil.ReadFile(release.TorrentTmpFile)
if err != nil {
return nil, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
}
var args []*rtorrent.FieldValue
if action.Label != "" {
args = append(args, &rtorrent.FieldValue{
Field: "d.custom1",
Value: action.Label,
})
}
if action.SavePath != "" {
args = append(args, &rtorrent.FieldValue{
Field: "d.base_path",
Value: action.SavePath,
})
}
if err := rt.AddTorrent(tmpFile, args...); err != nil {
return nil, errors.Wrap(err, "could not add torrent file: %v", release.TorrentTmpFile)
}
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", "", client.Name)
return rejections, nil
}

View file

@ -48,6 +48,9 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
case domain.ActionTypeQbittorrent:
rejections, err = s.qbittorrent(*action, release)
case domain.ActionTypeRTorrent:
rejections, err = s.rtorrent(*action, release)
case domain.ActionTypeTransmission:
rejections, err = s.transmission(*action, release)

View file

@ -54,6 +54,7 @@ const (
ActionTypeQbittorrent ActionType = "QBITTORRENT"
ActionTypeDelugeV1 ActionType = "DELUGE_V1"
ActionTypeDelugeV2 ActionType = "DELUGE_V2"
ActionTypeRTorrent ActionType = "RTORRENT"
ActionTypeTransmission ActionType = "TRANSMISSION"
ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
ActionTypeWebhook ActionType = "WEBHOOK"

View file

@ -49,6 +49,7 @@ const (
DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT"
DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1"
DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2"
DownloadClientTypeRTorrent DownloadClientType = "RTORRENT"
DownloadClientTypeTransmission DownloadClientType = "TRANSMISSION"
DownloadClientTypeRadarr DownloadClientType = "RADARR"
DownloadClientTypeSonarr DownloadClientType = "SONARR"

View file

@ -14,6 +14,7 @@ import (
delugeClient "github.com/gdm85/go-libdeluge"
"github.com/hekmon/transmissionrpc/v2"
"github.com/mrobinsn/go-rtorrent/rtorrent"
)
func (s *service) testConnection(client domain.DownloadClient) error {
@ -24,6 +25,9 @@ func (s *service) testConnection(client domain.DownloadClient) error {
case domain.DownloadClientTypeDelugeV1, domain.DownloadClientTypeDelugeV2:
return s.testDelugeConnection(client)
case domain.DownloadClientTypeRTorrent:
return s.testRTorrentConnection(client)
case domain.DownloadClientTypeTransmission:
return s.testTransmissionConnection(client)
@ -119,6 +123,21 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testRTorrentConnection(client domain.DownloadClient) error {
// create client
rt := rtorrent.New(client.Host, true)
name, err := rt.Name()
if err != nil {
return errors.Wrap(err, "error logging into client: %v", client.Host)
}
s.log.Trace().Msgf("test client connection for rTorrent: got client: %v", name)
s.log.Debug().Msgf("test client connection for rTorrent: success")
return nil
}
func (s *service) testTransmissionConnection(client domain.DownloadClient) error {
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
HTTPS: client.TLS,