mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(clients): add Readarr support (#490)
* Add initial Readarr support * Readarr working with MaM * feat(clients): readarr add tests
This commit is contained in:
parent
b7d2161fdb
commit
71d0424b61
16 changed files with 626 additions and 6 deletions
68
internal/action/readarr.go
Normal file
68
internal/action/readarr.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/readarr"
|
||||
)
|
||||
|
||||
func (s *service) readarr(action domain.Action, release domain.Release) ([]string, error) {
|
||||
s.log.Trace().Msg("action READARR")
|
||||
|
||||
// TODO validate data
|
||||
|
||||
// get client for action
|
||||
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "readarr could not find client: %v", action.ClientID)
|
||||
}
|
||||
|
||||
// return early if no client found
|
||||
if client == nil {
|
||||
return nil, errors.New("no client found")
|
||||
}
|
||||
|
||||
// initial config
|
||||
cfg := readarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
Log: s.subLogger,
|
||||
}
|
||||
|
||||
// only set basic auth if enabled
|
||||
if client.Settings.Basic.Auth {
|
||||
cfg.BasicAuth = client.Settings.Basic.Auth
|
||||
cfg.Username = client.Settings.Basic.Username
|
||||
cfg.Password = client.Settings.Basic.Password
|
||||
}
|
||||
|
||||
arr := readarr.New(cfg)
|
||||
|
||||
r := readarr.Release{
|
||||
Title: release.TorrentName,
|
||||
DownloadUrl: release.TorrentURL,
|
||||
Size: int64(release.Size),
|
||||
Indexer: release.Indexer,
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: time.Now().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
rejections, err := arr.Push(r)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "readarr: failed to push release: %v", r)
|
||||
}
|
||||
|
||||
if rejections != nil {
|
||||
s.log.Debug().Msgf("readarr: release push rejected: %v, indexer %v to %v reasons: '%v'", r.Title, r.Indexer, client.Host, rejections)
|
||||
|
||||
return rejections, nil
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("readarr: successfully pushed release: %v, indexer %v to %v", r.Title, r.Indexer, client.Host)
|
||||
|
||||
return nil, nil
|
||||
}
|
|
@ -66,6 +66,9 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
|
|||
case domain.ActionTypeWhisparr:
|
||||
rejections, err = s.whisparr(*action, release)
|
||||
|
||||
case domain.ActionTypeReadarr:
|
||||
rejections, err = s.readarr(*action, release)
|
||||
|
||||
default:
|
||||
s.log.Warn().Msgf("unsupported action type: %v", action.Type)
|
||||
return rejections, err
|
||||
|
|
|
@ -62,6 +62,7 @@ const (
|
|||
ActionTypeSonarr ActionType = "SONARR"
|
||||
ActionTypeLidarr ActionType = "LIDARR"
|
||||
ActionTypeWhisparr ActionType = "WHISPARR"
|
||||
ActionTypeReadarr ActionType = "READARR"
|
||||
)
|
||||
|
||||
type ActionContentLayout string
|
||||
|
|
|
@ -55,4 +55,5 @@ const (
|
|||
DownloadClientTypeSonarr DownloadClientType = "SONARR"
|
||||
DownloadClientTypeLidarr DownloadClientType = "LIDARR"
|
||||
DownloadClientTypeWhisparr DownloadClientType = "WHISPARR"
|
||||
DownloadClientTypeReadarr DownloadClientType = "READARR"
|
||||
)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/autobrr/autobrr/pkg/lidarr"
|
||||
"github.com/autobrr/autobrr/pkg/qbittorrent"
|
||||
"github.com/autobrr/autobrr/pkg/radarr"
|
||||
"github.com/autobrr/autobrr/pkg/readarr"
|
||||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
"github.com/autobrr/autobrr/pkg/whisparr"
|
||||
|
||||
|
@ -42,6 +43,9 @@ func (s *service) testConnection(client domain.DownloadClient) error {
|
|||
|
||||
case domain.DownloadClientTypeWhisparr:
|
||||
return s.testWhisparrConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeReadarr:
|
||||
return s.testReadarrConnection(client)
|
||||
default:
|
||||
return errors.New("unsupported client")
|
||||
}
|
||||
|
@ -242,3 +246,23 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testReadarrConnection(client domain.DownloadClient) error {
|
||||
r := readarr.New(readarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
BasicAuth: client.Settings.Basic.Auth,
|
||||
Username: client.Settings.Basic.Username,
|
||||
Password: client.Settings.Basic.Password,
|
||||
Log: s.subLogger,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "readarr: connection test failed: %v", client.Host)
|
||||
}
|
||||
|
||||
s.log.Debug().Msgf("test client connection for readarr: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -59,3 +59,4 @@ parse:
|
|||
|
||||
match:
|
||||
torrenturl: "{{ .baseUrl }}tor/download.php?tid={{ .torrentId }}"
|
||||
torrentname: "{{ .torrentName }} by {{ .author }} [{{ .language }} / {{ .tags }}]"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue