feat: add usenet support (#543)

* 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>
This commit is contained in:
Kyle Sanderson 2023-03-04 11:27:18 -08:00 committed by GitHub
parent b2d93d50c5
commit 13a74f7cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1588 additions and 37 deletions

View file

@ -0,0 +1,52 @@
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
}