feat(download-client): add support for Porla (#553)

* Add support for the 'Test' button to work

* Make Porla show up in filter actions select

* Add an empty Porla action

* Make Porla action find download client

* Make implementation actually add torrent to Porla

* Fix qBittorrent import

* Finish up Porla action

* Check length on commitish before slicing

* Move Porla to the other DL clients

* Add Porla to type name map

* Move Porla to beneath the other download clients
This commit is contained in:
Viktor Elofsson 2023-01-29 18:17:01 +01:00 committed by GitHub
parent b95c1e6913
commit 870e109f6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 271 additions and 2 deletions

79
internal/action/porla.go Normal file
View file

@ -0,0 +1,79 @@
package action
import (
"bufio"
"context"
"encoding/base64"
"io/ioutil"
"os"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/autobrr/autobrr/pkg/porla"
"github.com/dcarbone/zadapters/zstdlog"
"github.com/rs/zerolog"
)
func (s *service) porla(action domain.Action, release domain.Release) ([]string, error) {
s.log.Debug().Msgf("action Porla: %v", action.Name)
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
if err != nil {
return nil, errors.Wrap(err, "error finding client: %v", action.ClientID)
}
if client == nil {
return nil, errors.New("could not find client by id: %v", action.ClientID)
}
porlaSettings := porla.Settings{
Hostname: client.Host,
AuthToken: client.Settings.APIKey,
}
porlaSettings.Log = zstdlog.NewStdLoggerWithLevel(s.log.With().Str("type", "Porla").Str("client", client.Name).Logger(), zerolog.TraceLevel)
prl := porla.NewClient(porlaSettings)
if release.TorrentTmpFile == "" {
if err := release.DownloadTorrentFile(); err != nil {
return nil, errors.Wrap(err, "error downloading torrent file for release: %v", release.TorrentName)
}
}
file, err := os.Open(release.TorrentTmpFile)
if err != nil {
return nil, errors.Wrap(err, "error opening file %v", release.TorrentTmpFile)
}
defer file.Close()
reader := bufio.NewReader(file)
content, err := ioutil.ReadAll(reader)
if err != nil {
return nil, errors.Wrap(err, "failed to read file: %v", release.TorrentTmpFile)
}
opts := &porla.TorrentsAddReq{
DownloadLimit: -1,
SavePath: action.SavePath,
Ti: base64.StdEncoding.EncodeToString(content),
UploadLimit: -1,
}
if action.LimitDownloadSpeed > 0 {
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
}
if action.LimitUploadSpeed > 0 {
opts.UploadLimit = action.LimitUploadSpeed * 1000
}
if err = prl.TorrentsAdd(opts); err != nil {
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Name)
}
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, client.Name)
return nil, nil
}

View file

@ -60,6 +60,9 @@ func (s *service) RunAction(ctx context.Context, action *domain.Action, release
case domain.ActionTypeTransmission:
rejections, err = s.transmission(ctx, action, release)
case domain.ActionTypePorla:
rejections, err = s.porla(*action, release)
case domain.ActionTypeRadarr:
rejections, err = s.radarr(ctx, action, release)

View file

@ -2,6 +2,7 @@ package domain
import (
"context"
"github.com/autobrr/autobrr/pkg/errors"
)
@ -80,6 +81,7 @@ const (
ActionTypeDelugeV2 ActionType = "DELUGE_V2"
ActionTypeRTorrent ActionType = "RTORRENT"
ActionTypeTransmission ActionType = "TRANSMISSION"
ActionTypePorla ActionType = "PORLA"
ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
ActionTypeWebhook ActionType = "WEBHOOK"
ActionTypeRadarr ActionType = "RADARR"

View file

@ -73,6 +73,7 @@ const (
DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2"
DownloadClientTypeRTorrent DownloadClientType = "RTORRENT"
DownloadClientTypeTransmission DownloadClientType = "TRANSMISSION"
DownloadClientTypePorla DownloadClientType = "PORLA"
DownloadClientTypeRadarr DownloadClientType = "RADARR"
DownloadClientTypeSonarr DownloadClientType = "SONARR"
DownloadClientTypeLidarr DownloadClientType = "LIDARR"

View file

@ -7,6 +7,7 @@ import (
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/autobrr/autobrr/pkg/lidarr"
"github.com/autobrr/autobrr/pkg/porla"
"github.com/autobrr/autobrr/pkg/radarr"
"github.com/autobrr/autobrr/pkg/readarr"
"github.com/autobrr/autobrr/pkg/sonarr"
@ -32,6 +33,9 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
case domain.DownloadClientTypeTransmission:
return s.testTransmissionConnection(ctx, client)
case domain.DownloadClientTypePorla:
return s.testPorlaConnection(client)
case domain.DownloadClientTypeRadarr:
return s.testRadarrConnection(ctx, client)
@ -258,3 +262,26 @@ func (s *service) testReadarrConnection(ctx context.Context, client domain.Downl
return nil
}
func (s *service) testPorlaConnection(client domain.DownloadClient) error {
p := porla.NewClient(porla.Settings{
Hostname: client.Host,
AuthToken: client.Settings.APIKey,
})
version, err := p.Version()
if err != nil {
return errors.Wrap(err, "porla: failed to get version: %v", client.Host)
}
commitish := version.Commitish
if len(commitish) > 8 {
commitish = commitish[:8]
}
s.log.Debug().Msgf("test client connection for porla: found version %s (commit %s)", version.Version, commitish)
return nil
}