mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00

* feat(autobrr): implement usenet support * feat(sonarr): implement usenet support * feat(radarr): implement usenet support * feat(announce): implement usenet support * announce: cast a line * feat(release): prevent unknown protocol transfer * release: lines for days. * feat: add newznab and sabnzbd support * feat: add category to sabnzbd * feat(newznab): map categories * feat(newznab): map categories --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com> Co-authored-by: ze0s <ze0s@riseup.net>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package action
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
"github.com/autobrr/autobrr/pkg/errors"
|
|
"github.com/autobrr/autobrr/pkg/sabnzbd"
|
|
)
|
|
|
|
func (s *service) sabnzbd(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
|
s.log.Trace().Msg("action Sabnzbd")
|
|
|
|
if release.Protocol != domain.ReleaseProtocolNzb {
|
|
return nil, errors.New("action type: %s invalid protocol: %s", action.Type, release.Protocol)
|
|
}
|
|
|
|
// get client for action
|
|
client, err := s.clientSvc.FindByID(ctx, action.ClientID)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "sonarr could not find client: %d", action.ClientID)
|
|
}
|
|
|
|
// return early if no client found
|
|
if client == nil {
|
|
return nil, errors.New("no sabnzbd client found by id: %d", action.ClientID)
|
|
}
|
|
|
|
opts := sabnzbd.Options{
|
|
Addr: client.Host,
|
|
ApiKey: client.Settings.APIKey,
|
|
Log: nil,
|
|
}
|
|
|
|
if client.Settings.Basic.Auth {
|
|
opts.BasicUser = client.Settings.Basic.Username
|
|
opts.BasicPass = client.Settings.Basic.Password
|
|
}
|
|
|
|
sab := sabnzbd.New(opts)
|
|
|
|
ids, err := sab.AddFromUrl(ctx, sabnzbd.AddNzbRequest{Url: release.TorrentURL, Category: action.Category})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not add nzb to sabnzbd")
|
|
}
|
|
|
|
s.log.Trace().Msgf("nzb successfully added to client: '%+v'", ids)
|
|
|
|
s.log.Info().Msgf("nzb successfully added to client: '%s'", client.Name)
|
|
|
|
return nil, nil
|
|
}
|