Feature: Radarr (#13)

* feat(web): add and update radarr

* feat: add radarr download client

* feat: add tests
This commit is contained in:
Ludvig Lundgren 2021-08-21 23:36:06 +02:00 committed by GitHub
parent 0c4aaa29b0
commit 455284a94b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 2898 additions and 3348 deletions

65
internal/action/radarr.go Normal file
View file

@ -0,0 +1,65 @@
package action
import (
"time"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/radarr"
"github.com/rs/zerolog/log"
)
func (s *service) radarr(announce domain.Announce, action domain.Action) error {
log.Trace().Msg("action RADARR")
// TODO validate data
// get client for action
client, err := s.clientSvc.FindByID(action.ClientID)
if err != nil {
log.Error().Err(err).Msgf("error finding client: %v", action.ClientID)
return err
}
// return early if no client found
if client == nil {
return err
}
// initial config
cfg := radarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
}
// 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
}
r := radarr.New(cfg)
release := radarr.Release{
Title: announce.TorrentName,
DownloadUrl: announce.TorrentUrl,
Size: 0,
Indexer: announce.Site,
DownloadProtocol: "torrent",
Protocol: "torrent",
PublishDate: time.Now().String(),
}
err = r.Push(release)
if err != nil {
log.Error().Err(err).Msgf("radarr: failed to push release: %v", release)
return err
}
// TODO save pushed release
log.Debug().Msgf("radarr: successfully pushed release: %v, indexer %v to %v", release.Title, release.Indexer, client.Host)
return nil
}

View file

@ -65,7 +65,14 @@ func (s *service) RunActions(torrentFile string, hash string, filter domain.Filt
}
}()
// pvr *arr
case domain.ActionTypeRadarr:
go func() {
err := s.radarr(announce, action)
if err != nil {
log.Error().Err(err).Msg("error sending torrent to radarr")
}
}()
default:
log.Warn().Msgf("unsupported action: %v type: %v", action.Name, action.Type)
}