mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
Feature: Save releases (#36)
* chore: tidy deps * refactor: database migration * refactor: store release * refactor: save release * chore: add packages * feat(web): show stats and recent releases * refactor: simply filter struct * feat: add eventbus * chore: cleanup logging * chore: update packages
This commit is contained in:
parent
d22dd2fe84
commit
7177e48c02
40 changed files with 5859 additions and 3328 deletions
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *service) execCmd(announce domain.Announce, action domain.Action, torrentFile string) {
|
||||
log.Debug().Msgf("action exec: %v release: %v", action.Name, announce.TorrentName)
|
||||
func (s *service) execCmd(release domain.Release, action domain.Action, torrentFile string) {
|
||||
log.Debug().Msgf("action exec: %v release: %v", action.Name, release.TorrentName)
|
||||
|
||||
// check if program exists
|
||||
cmd, err := exec.LookPath(action.ExecCmd)
|
||||
|
@ -22,9 +22,9 @@ func (s *service) execCmd(announce domain.Announce, action domain.Action, torren
|
|||
|
||||
// handle args and replace vars
|
||||
m := Macro{
|
||||
TorrentName: announce.TorrentName,
|
||||
TorrentName: release.TorrentName,
|
||||
TorrentPathName: torrentFile,
|
||||
TorrentUrl: announce.TorrentUrl,
|
||||
TorrentUrl: release.TorrentURL,
|
||||
}
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
@ -53,5 +53,5 @@ func (s *service) execCmd(announce domain.Announce, action domain.Action, torren
|
|||
|
||||
duration := time.Since(start)
|
||||
|
||||
log.Info().Msgf("executed command: '%v', args: '%v' %v,%v, total time %v", cmd, parsedArgs, announce.TorrentName, announce.Site, duration)
|
||||
log.Info().Msgf("executed command: '%v', args: '%v' %v,%v, total time %v", cmd, parsedArgs, release.TorrentName, release.Indexer, duration)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *service) lidarr(announce domain.Announce, action domain.Action) error {
|
||||
func (s *service) lidarr(release domain.Release, action domain.Action) error {
|
||||
log.Trace().Msg("action LIDARR")
|
||||
|
||||
// TODO validate data
|
||||
|
@ -39,28 +39,35 @@ func (s *service) lidarr(announce domain.Announce, action domain.Action) error {
|
|||
cfg.Password = client.Settings.Basic.Password
|
||||
}
|
||||
|
||||
r := lidarr.New(cfg)
|
||||
arr := lidarr.New(cfg)
|
||||
|
||||
release := lidarr.Release{
|
||||
Title: announce.TorrentName,
|
||||
DownloadUrl: announce.TorrentUrl,
|
||||
Size: 0,
|
||||
Indexer: announce.Site,
|
||||
r := lidarr.Release{
|
||||
Title: release.TorrentName,
|
||||
DownloadUrl: release.TorrentURL,
|
||||
Size: int64(release.Size),
|
||||
Indexer: release.Indexer,
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: time.Now().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
success, err := r.Push(release)
|
||||
success, rejections, err := arr.Push(r)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msgf("lidarr: failed to push release: %v", release)
|
||||
log.Error().Stack().Err(err).Msgf("lidarr: failed to push release: %v", r)
|
||||
return err
|
||||
}
|
||||
|
||||
if success {
|
||||
// TODO save pushed release
|
||||
log.Debug().Msgf("lidarr: successfully pushed release: %v, indexer %v to %v", release.Title, release.Indexer, client.Host)
|
||||
if !success {
|
||||
log.Debug().Msgf("lidarr: release push rejected: %v, indexer %v to %v reasons: '%v'", r.Title, r.Indexer, client.Host, rejections)
|
||||
|
||||
// save pushed release
|
||||
s.bus.Publish("release:update-push-status-rejected", release.ID, rejections)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Msgf("lidarr: successfully pushed release: %v, indexer %v to %v", r.Title, r.Indexer, client.Host)
|
||||
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *service) radarr(announce domain.Announce, action domain.Action) error {
|
||||
func (s *service) radarr(release domain.Release, action domain.Action) error {
|
||||
log.Trace().Msg("action RADARR")
|
||||
|
||||
// TODO validate data
|
||||
|
@ -39,28 +39,35 @@ func (s *service) radarr(announce domain.Announce, action domain.Action) error {
|
|||
cfg.Password = client.Settings.Basic.Password
|
||||
}
|
||||
|
||||
r := radarr.New(cfg)
|
||||
arr := radarr.New(cfg)
|
||||
|
||||
release := radarr.Release{
|
||||
Title: announce.TorrentName,
|
||||
DownloadUrl: announce.TorrentUrl,
|
||||
Size: 0,
|
||||
Indexer: announce.Site,
|
||||
r := radarr.Release{
|
||||
Title: release.TorrentName,
|
||||
DownloadUrl: release.TorrentURL,
|
||||
Size: int64(release.Size),
|
||||
Indexer: release.Indexer,
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: time.Now().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
success, err := r.Push(release)
|
||||
success, rejections, err := arr.Push(r)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msgf("radarr: failed to push release: %v", release)
|
||||
log.Error().Stack().Err(err).Msgf("radarr: failed to push release: %v", r)
|
||||
return err
|
||||
}
|
||||
|
||||
if success {
|
||||
// TODO save pushed release
|
||||
log.Debug().Msgf("radarr: successfully pushed release: %v, indexer %v to %v", release.Title, release.Indexer, client.Host)
|
||||
if !success {
|
||||
log.Debug().Msgf("radarr: release push rejected: %v, indexer %v to %v reasons: '%v'", r.Title, r.Indexer, client.Host, rejections)
|
||||
|
||||
// save pushed release
|
||||
s.bus.Publish("release:update-push-status-rejected", release.ID, rejections)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Msgf("radarr: successfully pushed release: %v, indexer %v to %v", r.Title, r.Indexer, client.Host)
|
||||
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/domain"
|
||||
)
|
||||
|
||||
func (s *service) RunActions(actions []domain.Action, announce domain.Announce) error {
|
||||
func (s *service) RunActions(actions []domain.Action, release domain.Release) error {
|
||||
|
||||
var err error
|
||||
var tmpFile string
|
||||
|
@ -24,33 +24,36 @@ func (s *service) RunActions(actions []domain.Action, announce domain.Announce)
|
|||
continue
|
||||
}
|
||||
|
||||
log.Debug().Msgf("process action: %v", action.Name)
|
||||
log.Debug().Msgf("process action: %v for '%v'", action.Name, release.TorrentName)
|
||||
|
||||
switch action.Type {
|
||||
case domain.ActionTypeTest:
|
||||
s.test(action.Name)
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
|
||||
case domain.ActionTypeExec:
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(announce.TorrentUrl)
|
||||
tmpFile, hash, err = downloadFile(release.TorrentURL)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
go func(announce domain.Announce, action domain.Action, tmpFile string) {
|
||||
s.execCmd(announce, action, tmpFile)
|
||||
}(announce, action, tmpFile)
|
||||
go func(release domain.Release, action domain.Action, tmpFile string) {
|
||||
s.execCmd(release, action, tmpFile)
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
}(release, action, tmpFile)
|
||||
|
||||
case domain.ActionTypeWatchFolder:
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(announce.TorrentUrl)
|
||||
tmpFile, hash, err = downloadFile(release.TorrentURL)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.watchFolder(action.WatchFolder, tmpFile)
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
|
||||
case domain.ActionTypeDelugeV1, domain.ActionTypeDelugeV2:
|
||||
canDownload, err := s.delugeCheckRulesCanDownload(action)
|
||||
|
@ -58,22 +61,25 @@ func (s *service) RunActions(actions []domain.Action, announce domain.Announce)
|
|||
log.Error().Stack().Err(err).Msgf("error checking client rules: %v", action.Name)
|
||||
continue
|
||||
}
|
||||
if canDownload {
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(announce.TorrentUrl)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
go func(action domain.Action, tmpFile string) {
|
||||
err = s.deluge(action, tmpFile)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to Deluge")
|
||||
}
|
||||
}(action, tmpFile)
|
||||
if !canDownload {
|
||||
s.bus.Publish("release:update-push-status-rejected", release.ID, "deluge busy")
|
||||
continue
|
||||
}
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(release.TorrentURL)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
go func(action domain.Action, tmpFile string) {
|
||||
err = s.deluge(action, tmpFile)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to Deluge")
|
||||
}
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
}(action, tmpFile)
|
||||
|
||||
case domain.ActionTypeQbittorrent:
|
||||
canDownload, err := s.qbittorrentCheckRulesCanDownload(action)
|
||||
|
@ -81,49 +87,53 @@ func (s *service) RunActions(actions []domain.Action, announce domain.Announce)
|
|||
log.Error().Stack().Err(err).Msgf("error checking client rules: %v", action.Name)
|
||||
continue
|
||||
}
|
||||
if canDownload {
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(announce.TorrentUrl)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
go func(action domain.Action, hash string, tmpFile string) {
|
||||
err = s.qbittorrent(action, hash, tmpFile)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to qBittorrent")
|
||||
}
|
||||
}(action, hash, tmpFile)
|
||||
if !canDownload {
|
||||
s.bus.Publish("release:update-push-status-rejected", release.ID, "qbittorrent busy")
|
||||
continue
|
||||
}
|
||||
|
||||
if tmpFile == "" {
|
||||
tmpFile, hash, err = downloadFile(release.TorrentURL)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
go func(action domain.Action, hash string, tmpFile string) {
|
||||
err = s.qbittorrent(action, hash, tmpFile)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to qBittorrent")
|
||||
}
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
}(action, hash, tmpFile)
|
||||
|
||||
case domain.ActionTypeRadarr:
|
||||
go func(announce domain.Announce, action domain.Action) {
|
||||
err = s.radarr(announce, action)
|
||||
go func(release domain.Release, action domain.Action) {
|
||||
err = s.radarr(release, action)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to radarr")
|
||||
//continue
|
||||
}
|
||||
}(announce, action)
|
||||
}(release, action)
|
||||
|
||||
case domain.ActionTypeSonarr:
|
||||
go func(announce domain.Announce, action domain.Action) {
|
||||
err = s.sonarr(announce, action)
|
||||
go func(release domain.Release, action domain.Action) {
|
||||
err = s.sonarr(release, action)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to sonarr")
|
||||
//continue
|
||||
}
|
||||
}(announce, action)
|
||||
}(release, action)
|
||||
|
||||
case domain.ActionTypeLidarr:
|
||||
go func(announce domain.Announce, action domain.Action) {
|
||||
err = s.lidarr(announce, action)
|
||||
go func(release domain.Release, action domain.Action) {
|
||||
err = s.lidarr(release, action)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("error sending torrent to lidarr")
|
||||
//continue
|
||||
}
|
||||
}(announce, action)
|
||||
}(release, action)
|
||||
|
||||
default:
|
||||
log.Warn().Msgf("unsupported action: %v type: %v", action.Name, action.Type)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"github.com/asaskevich/EventBus"
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/download_client"
|
||||
)
|
||||
|
@ -11,16 +12,17 @@ type Service interface {
|
|||
Delete(actionID int) error
|
||||
ToggleEnabled(actionID int) error
|
||||
|
||||
RunActions(actions []domain.Action, announce domain.Announce) error
|
||||
RunActions(actions []domain.Action, release domain.Release) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo domain.ActionRepo
|
||||
clientSvc download_client.Service
|
||||
bus EventBus.Bus
|
||||
}
|
||||
|
||||
func NewService(repo domain.ActionRepo, clientSvc download_client.Service) Service {
|
||||
return &service{repo: repo, clientSvc: clientSvc}
|
||||
func NewService(repo domain.ActionRepo, clientSvc download_client.Service, bus EventBus.Bus) Service {
|
||||
return &service{repo: repo, clientSvc: clientSvc, bus: bus}
|
||||
}
|
||||
|
||||
func (s *service) Store(action domain.Action) (*domain.Action, error) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *service) sonarr(announce domain.Announce, action domain.Action) error {
|
||||
func (s *service) sonarr(release domain.Release, action domain.Action) error {
|
||||
log.Trace().Msg("action SONARR")
|
||||
|
||||
// TODO validate data
|
||||
|
@ -39,28 +39,35 @@ func (s *service) sonarr(announce domain.Announce, action domain.Action) error {
|
|||
cfg.Password = client.Settings.Basic.Password
|
||||
}
|
||||
|
||||
r := sonarr.New(cfg)
|
||||
arr := sonarr.New(cfg)
|
||||
|
||||
release := sonarr.Release{
|
||||
Title: announce.TorrentName,
|
||||
DownloadUrl: announce.TorrentUrl,
|
||||
Size: 0,
|
||||
Indexer: announce.Site,
|
||||
r := sonarr.Release{
|
||||
Title: release.TorrentName,
|
||||
DownloadUrl: release.TorrentURL,
|
||||
Size: int64(release.Size),
|
||||
Indexer: release.Indexer,
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: time.Now().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
success, err := r.Push(release)
|
||||
success, rejections, err := arr.Push(r)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msgf("sonarr: failed to push release: %v", release)
|
||||
log.Error().Stack().Err(err).Msgf("sonarr: failed to push release: %v", r)
|
||||
return err
|
||||
}
|
||||
|
||||
if success {
|
||||
// TODO save pushed release
|
||||
log.Debug().Msgf("sonarr: successfully pushed release: %v, indexer %v to %v", release.Title, release.Indexer, client.Host)
|
||||
if !success {
|
||||
log.Debug().Msgf("sonarr: release push rejected: %v, indexer %v to %v reasons: '%v'", r.Title, r.Indexer, client.Host, rejections)
|
||||
|
||||
// save pushed release
|
||||
s.bus.Publish("release:update-push-status-rejected", release.ID, rejections)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Msgf("sonarr: successfully pushed release: %v, indexer %v to %v", r.Title, r.Indexer, client.Host)
|
||||
|
||||
s.bus.Publish("release:update-push-status", release.ID, domain.ReleasePushStatusApproved)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue