mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
Feature: Sonarr (#14)
* feat: add sonarr download client * feat(web): add sonarr download client and actions * feat: add sonarr to filter actions
This commit is contained in:
parent
455284a94b
commit
fce6c7149a
15 changed files with 594 additions and 5 deletions
|
@ -73,6 +73,14 @@ func (s *service) RunActions(torrentFile string, hash string, filter domain.Filt
|
|||
}
|
||||
}()
|
||||
|
||||
case domain.ActionTypeSonarr:
|
||||
go func() {
|
||||
err := s.sonarr(announce, action)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error sending torrent to sonarr")
|
||||
}
|
||||
}()
|
||||
|
||||
default:
|
||||
log.Warn().Msgf("unsupported action: %v type: %v", action.Name, action.Type)
|
||||
}
|
||||
|
|
65
internal/action/sonarr.go
Normal file
65
internal/action/sonarr.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *service) sonarr(announce domain.Announce, action domain.Action) error {
|
||||
log.Trace().Msg("action SONARR")
|
||||
|
||||
// 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 := sonarr.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 := sonarr.New(cfg)
|
||||
|
||||
release := sonarr.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("sonarr: failed to push release: %v", release)
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO save pushed release
|
||||
|
||||
log.Debug().Msgf("sonarr: successfully pushed release: %v, indexer %v to %v", release.Title, release.Indexer, client.Host)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -38,4 +38,5 @@ const (
|
|||
ActionTypeDelugeV2 ActionType = "DELUGE_V2"
|
||||
ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
|
||||
ActionTypeRadarr ActionType = "RADARR"
|
||||
ActionTypeSonarr ActionType = "SONARR"
|
||||
)
|
||||
|
|
|
@ -39,4 +39,5 @@ const (
|
|||
DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1"
|
||||
DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2"
|
||||
DownloadClientTypeRadarr DownloadClientType = "RADARR"
|
||||
DownloadClientTypeSonarr DownloadClientType = "SONARR"
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/qbittorrent"
|
||||
"github.com/autobrr/autobrr/pkg/radarr"
|
||||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
|
||||
delugeClient "github.com/gdm85/go-libdeluge"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -21,6 +22,9 @@ func (s *service) testConnection(client domain.DownloadClient) error {
|
|||
|
||||
case domain.DownloadClientTypeRadarr:
|
||||
return s.testRadarrConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeSonarr:
|
||||
return s.testSonarrConnection(client)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -106,3 +110,21 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testSonarrConnection(client domain.DownloadClient) error {
|
||||
r := sonarr.New(sonarr.Config{
|
||||
Hostname: client.Host,
|
||||
APIKey: client.Settings.APIKey,
|
||||
BasicAuth: client.Settings.Basic.Auth,
|
||||
Username: client.Settings.Basic.Username,
|
||||
Password: client.Settings.Basic.Password,
|
||||
})
|
||||
|
||||
_, err := r.Test()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("sonarr: connection test failed: %v", client.Host)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue