mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(lists): integrate Omegabrr (#1885)
* feat(lists): integrate Omegabrr * feat(lists): add missing lists index * feat(lists): add db repo * feat(lists): add db migrations * feat(lists): labels * feat(lists): url lists and more arrs * fix(lists): db migrations client_id wrong type * fix(lists): db fields * feat(lists): create list form wip * feat(lists): show in list and create * feat(lists): update and delete * feat(lists): trigger via webhook * feat(lists): add webhook handler * fix(arr): encode json to pointer * feat(lists): rename endpoint to lists * feat(lists): fetch tags from arr * feat(lists): process plaintext lists * feat(lists): add background refresh job * run every 6th hour with a random start delay between 1-35 seconds * feat(lists): refresh on save and improve logging * feat(lists): cast arr client to pointer * feat(lists): improve error handling * feat(lists): reset shows field with match release * feat(lists): filter opts all lists * feat(lists): trigger on update if enabled * feat(lists): update option for lists * feat(lists): show connected filters in list * feat(lists): missing listSvc dep * feat(lists): cleanup * feat(lists): typo arr list * feat(lists): radarr include original * feat(lists): rename ExcludeAlternateTitle to IncludeAlternateTitle * fix(lists): arr client type conversion to pointer * fix(actions): only log panic recover if err not nil * feat(lists): show spinner on save * feat(lists): show icon in filters list * feat(lists): change icon color in filters list * feat(lists): delete relations on filter delete
This commit is contained in:
parent
b68ae334ca
commit
221bc35371
77 changed files with 5025 additions and 254 deletions
200
pkg/arr/radarr/client.go
Normal file
200
pkg/arr/radarr/client.go
Normal file
|
@ -0,0 +1,200 @@
|
|||
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package radarr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) get(ctx context.Context, endpoint string) (int, []byte, error) {
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname)
|
||||
}
|
||||
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "could not build request: %v", reqUrl)
|
||||
}
|
||||
|
||||
if c.config.BasicAuth {
|
||||
req.SetBasicAuth(c.config.Username, c.config.Password)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "radarr.http.Do(req): %v", reqUrl)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.Body == nil {
|
||||
return resp.StatusCode, nil, errors.New("response body is nil")
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err = io.Copy(&buf, resp.Body); err != nil {
|
||||
return resp.StatusCode, nil, errors.Wrap(err, "radarr.io.Copy")
|
||||
}
|
||||
|
||||
return resp.StatusCode, buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (c *Client) getJSON(ctx context.Context, endpoint string, params url.Values, data any) error {
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse url: %s", c.config.Hostname)
|
||||
}
|
||||
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not build request")
|
||||
}
|
||||
|
||||
if c.config.BasicAuth {
|
||||
req.SetBasicAuth(c.config.Username, c.config.Password)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
req.URL.RawQuery = params.Encode()
|
||||
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "radarr.http.Do(req): %+v", req)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.Body == nil {
|
||||
return errors.New("response body is nil")
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
return errors.Wrap(err, "could not unmarshal data")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) post(ctx context.Context, endpoint string, data interface{}) (*http.Response, error) {
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname)
|
||||
}
|
||||
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not marshal data: %+v", data)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl, bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build request: %v", reqUrl)
|
||||
}
|
||||
|
||||
if c.config.BasicAuth {
|
||||
req.SetBasicAuth(c.config.Username, c.config.Password)
|
||||
}
|
||||
|
||||
req.Header.Add("X-Api-Key", c.config.APIKey)
|
||||
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
|
||||
req.Header.Set("User-Agent", "autobrr")
|
||||
|
||||
res, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return res, errors.Wrap(err, "could not make request: %+v", req)
|
||||
}
|
||||
|
||||
// validate response
|
||||
if res.StatusCode == http.StatusUnauthorized {
|
||||
return res, errors.New("unauthorized: bad credentials")
|
||||
} else if res.StatusCode == http.StatusBadRequest {
|
||||
return res, errors.New("radarr: bad request")
|
||||
} else if res.StatusCode != http.StatusOK {
|
||||
return res, errors.New("radarr: bad request")
|
||||
}
|
||||
|
||||
// return raw response and let the caller handle json unmarshal of body
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) postBody(ctx context.Context, endpoint string, data interface{}) (int, []byte, error) {
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "could not parse url: %s", c.config.Hostname)
|
||||
}
|
||||
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "could not marshal data: %+v", data)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl, bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "could not build request: %v", reqUrl)
|
||||
}
|
||||
|
||||
if c.config.BasicAuth {
|
||||
req.SetBasicAuth(c.config.Username, c.config.Password)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "radarr.http.Do(req): %+v", req)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.Body == nil {
|
||||
return resp.StatusCode, nil, errors.New("response body is nil")
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err = io.Copy(&buf, resp.Body); err != nil {
|
||||
return resp.StatusCode, nil, errors.Wrap(err, "radarr.io.Copy")
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
return resp.StatusCode, buf.Bytes(), nil
|
||||
} else if resp.StatusCode < 200 || resp.StatusCode > 401 {
|
||||
return resp.StatusCode, buf.Bytes(), errors.New("radarr: bad request: %v (status: %s): %s", resp.Request.RequestURI, resp.Status, buf.String())
|
||||
}
|
||||
|
||||
return resp.StatusCode, buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (c *Client) setHeaders(req *http.Request) {
|
||||
if req.Body != nil {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "autobrr")
|
||||
|
||||
req.Header.Set("X-Api-Key", c.config.APIKey)
|
||||
}
|
147
pkg/arr/radarr/radarr.go
Normal file
147
pkg/arr/radarr/radarr.go
Normal file
|
@ -0,0 +1,147 @@
|
|||
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package radarr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/arr"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/sharedhttp"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Hostname string
|
||||
APIKey string
|
||||
|
||||
// basic auth username and password
|
||||
BasicAuth bool
|
||||
Username string
|
||||
Password string
|
||||
|
||||
Log *log.Logger
|
||||
}
|
||||
|
||||
type ClientInterface interface {
|
||||
Test(ctx context.Context) (*SystemStatusResponse, error)
|
||||
Push(ctx context.Context, release Release) ([]string, error)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
config Config
|
||||
http *http.Client
|
||||
|
||||
Log *log.Logger
|
||||
}
|
||||
|
||||
func New(config Config) *Client {
|
||||
httpClient := &http.Client{
|
||||
Timeout: time.Second * 120,
|
||||
Transport: sharedhttp.Transport,
|
||||
}
|
||||
|
||||
c := &Client{
|
||||
config: config,
|
||||
http: httpClient,
|
||||
Log: log.New(io.Discard, "", log.LstdFlags),
|
||||
}
|
||||
|
||||
if config.Log != nil {
|
||||
c.Log = config.Log
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) Test(ctx context.Context) (*SystemStatusResponse, error) {
|
||||
status, res, err := c.get(ctx, "system/status")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "radarr error running test")
|
||||
}
|
||||
|
||||
if status == http.StatusUnauthorized {
|
||||
return nil, errors.New("unauthorized: bad credentials")
|
||||
}
|
||||
|
||||
response := SystemStatusResponse{}
|
||||
if err = json.Unmarshal(res, &response); err != nil {
|
||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||
}
|
||||
|
||||
c.Log.Printf("radarr system/status status: (%v) response: %v\n", status, string(res))
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (c *Client) Push(ctx context.Context, release Release) ([]string, error) {
|
||||
status, res, err := c.postBody(ctx, "release/push", release)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error push release")
|
||||
}
|
||||
|
||||
c.Log.Printf("radarr release/push status: (%v) response: %v\n", status, string(res))
|
||||
|
||||
if status == http.StatusBadRequest {
|
||||
badRequestResponses := make([]*BadRequestResponse, 0)
|
||||
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
|
||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||
}
|
||||
|
||||
rejections := []string{}
|
||||
for _, response := range badRequestResponses {
|
||||
rejections = append(rejections, response.String())
|
||||
}
|
||||
|
||||
return rejections, nil
|
||||
}
|
||||
|
||||
pushResponse := make([]PushResponse, 0)
|
||||
if err = json.Unmarshal(res, &pushResponse); err != nil {
|
||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||
}
|
||||
|
||||
// log and return if rejected
|
||||
if pushResponse[0].Rejected {
|
||||
rejections := strings.Join(pushResponse[0].Rejections, ", ")
|
||||
|
||||
c.Log.Printf("radarr release/push rejected %v reasons: %q\n", release.Title, rejections)
|
||||
return pushResponse[0].Rejections, nil
|
||||
}
|
||||
|
||||
// success true
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetMovies(ctx context.Context, tmdbID int64) ([]Movie, error) {
|
||||
params := make(url.Values)
|
||||
if tmdbID != 0 {
|
||||
params.Set("tmdbId", strconv.FormatInt(tmdbID, 10))
|
||||
}
|
||||
|
||||
data := make([]Movie, 0)
|
||||
err := c.getJSON(ctx, "movie", params, &data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get tags")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetTags(ctx context.Context) ([]*arr.Tag, error) {
|
||||
data := make([]*arr.Tag, 0)
|
||||
err := c.getJSON(ctx, "tag", nil, &data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get tags")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
239
pkg/arr/radarr/radarr_test.go
Normal file
239
pkg/arr/radarr/radarr_test.go
Normal file
|
@ -0,0 +1,239 @@
|
|||
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
//go:build integration
|
||||
|
||||
package radarr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_client_Push(t *testing.T) {
|
||||
// disable logger
|
||||
zerolog.SetGlobalLevel(zerolog.Disabled)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
ts := httptest.NewServer(mux)
|
||||
defer ts.Close()
|
||||
|
||||
key := "mock-key"
|
||||
|
||||
mux.HandleFunc("/api/v3/release/push", func(w http.ResponseWriter, r *http.Request) {
|
||||
// request validation logic
|
||||
apiKey := r.Header.Get("X-Api-Key")
|
||||
if apiKey != "" {
|
||||
if apiKey != key {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write(nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Errorf("expected error to be nil got %v", err)
|
||||
}
|
||||
|
||||
if strings.Contains(string(data), "Minx 1 epi 9 2160p") {
|
||||
jsonPayload, _ := os.ReadFile("testdata/release_push_parse_error.json")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(jsonPayload)
|
||||
return
|
||||
}
|
||||
|
||||
// read json response
|
||||
jsonPayload, _ := os.ReadFile("testdata/release_push_response.json")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(jsonPayload)
|
||||
})
|
||||
|
||||
type fields struct {
|
||||
config Config
|
||||
}
|
||||
type args struct {
|
||||
release Release
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
rejections []string
|
||||
err error
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "push",
|
||||
fields: fields{
|
||||
config: Config{
|
||||
Hostname: ts.URL,
|
||||
APIKey: "",
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
},
|
||||
args: args{release: Release{
|
||||
Title: "Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP",
|
||||
DownloadUrl: "https://www.test.org/rss/download/0000001/00000000000000000000/Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP.torrent",
|
||||
Size: 0,
|
||||
Indexer: "test",
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: "2021-08-21T15:36:00Z",
|
||||
}},
|
||||
rejections: []string{"Could not find Some Old Movie"},
|
||||
},
|
||||
{
|
||||
name: "push_error",
|
||||
fields: fields{
|
||||
config: Config{
|
||||
Hostname: ts.URL,
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
},
|
||||
args: args{release: Release{
|
||||
Title: "Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP",
|
||||
DownloadUrl: "https://www.test.org/rss/download/0000001/00000000000000000000/Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP.torrent",
|
||||
Size: 0,
|
||||
Indexer: "test",
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: "2021-08-21T15:36:00Z",
|
||||
}},
|
||||
rejections: []string{"Could not find Some Old Movie"},
|
||||
},
|
||||
{
|
||||
name: "push_parse_error",
|
||||
fields: fields{
|
||||
config: Config{
|
||||
Hostname: ts.URL,
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
},
|
||||
args: args{release: Release{
|
||||
Title: "Minx 1 epi 9 2160p",
|
||||
DownloadUrl: "https://www.test.org/rss/download/0000001/00000000000000000000/Minx.1.epi.9.2160p.torrent",
|
||||
Size: 0,
|
||||
Indexer: "test",
|
||||
DownloadProtocol: "torrent",
|
||||
Protocol: "torrent",
|
||||
PublishDate: "2021-08-21T15:36:00Z",
|
||||
}},
|
||||
rejections: []string{"[error: ] Title: Unable to parse - got value: Minx 1 epi 9 2160p"},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := New(tt.fields.config)
|
||||
|
||||
rejections, err := c.Push(context.Background(), tt.args.release)
|
||||
assert.Equal(t, tt.rejections, rejections)
|
||||
if tt.wantErr && assert.Error(t, err) {
|
||||
assert.Equal(t, tt.err, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_client_Test(t *testing.T) {
|
||||
// disable logger
|
||||
zerolog.SetGlobalLevel(zerolog.Disabled)
|
||||
|
||||
key := "mock-key"
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
apiKey := r.Header.Get("X-Api-Key")
|
||||
if apiKey != "" {
|
||||
if apiKey != key {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write(nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
jsonPayload, _ := os.ReadFile("testdata/system_status_response.json")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(jsonPayload)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg Config
|
||||
want *SystemStatusResponse
|
||||
expectedErr string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "fetch",
|
||||
cfg: Config{
|
||||
Hostname: srv.URL,
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
want: &SystemStatusResponse{Version: "3.2.2.5080"},
|
||||
expectedErr: "",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "fetch_unauthorized",
|
||||
cfg: Config{
|
||||
Hostname: srv.URL,
|
||||
APIKey: "bad-mock-key",
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
expectedErr: "unauthorized: bad credentials",
|
||||
},
|
||||
{
|
||||
name: "fetch_subfolder",
|
||||
cfg: Config{
|
||||
Hostname: srv.URL + "/radarr",
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
want: &SystemStatusResponse{Version: "3.2.2.5080"},
|
||||
expectedErr: "",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := New(tt.cfg)
|
||||
|
||||
got, err := c.Test(context.Background())
|
||||
if tt.wantErr && assert.Error(t, err) {
|
||||
assert.EqualErrorf(t, err, tt.expectedErr, "Error should be: %v, got: %v", tt.wantErr, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
8
pkg/arr/radarr/testdata/release_push_parse_error.json
vendored
Normal file
8
pkg/arr/radarr/testdata/release_push_parse_error.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
[
|
||||
{
|
||||
"propertyName": "Title",
|
||||
"errorMessage": "Unable to parse",
|
||||
"attemptedValue": "Minx 1 epi 9 2160p",
|
||||
"severity": "error"
|
||||
}
|
||||
]
|
54
pkg/arr/radarr/testdata/release_push_response.json
vendored
Normal file
54
pkg/arr/radarr/testdata/release_push_response.json
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
[
|
||||
{
|
||||
"guid": "PUSH-https://www.test.org/rss/download/0000001/00000000000000000000/Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP.torrent",
|
||||
"quality": {
|
||||
"quality": {
|
||||
"id": 30,
|
||||
"name": "Remux-1080p",
|
||||
"source": "bluray",
|
||||
"resolution": 1080,
|
||||
"modifier": "remux"
|
||||
},
|
||||
"revision": {
|
||||
"version": 1,
|
||||
"real": 0,
|
||||
"isRepack": false
|
||||
}
|
||||
},
|
||||
"customFormats": [],
|
||||
"customFormatScore": 0,
|
||||
"qualityWeight": 1901,
|
||||
"age": 0,
|
||||
"ageHours": 0.028290299305555554,
|
||||
"ageMinutes": 1.69741874,
|
||||
"size": 0,
|
||||
"indexerId": 0,
|
||||
"indexer": "test",
|
||||
"releaseGroup": "NOGROUP",
|
||||
"releaseHash": "",
|
||||
"title": "Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP",
|
||||
"sceneSource": false,
|
||||
"movieTitle": "Twister",
|
||||
"languages": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "English"
|
||||
}
|
||||
],
|
||||
"approved": false,
|
||||
"temporarilyRejected": false,
|
||||
"rejected": true,
|
||||
"tmdbId": 0,
|
||||
"imdbId": 0,
|
||||
"rejections": [
|
||||
"Could not find Some Old Movie"
|
||||
],
|
||||
"publishDate": "2021-08-21T15:36:00Z",
|
||||
"downloadUrl": "https://www.test.org/rss/download/0000001/00000000000000000000/Some.Old.Movie.1996.Remastered.1080p.BluRay.REMUX.AVC.MULTI.TrueHD.Atmos.7.1-NOGROUP.torrent",
|
||||
"downloadAllowed": false,
|
||||
"releaseWeight": 0,
|
||||
"indexerFlags": [],
|
||||
"edition": "Remastered",
|
||||
"protocol": "torrent"
|
||||
}
|
||||
]
|
28
pkg/arr/radarr/testdata/system_status_response.json
vendored
Normal file
28
pkg/arr/radarr/testdata/system_status_response.json
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": "3.2.2.5080",
|
||||
"buildTime": "2021-06-03T11:51:33Z",
|
||||
"isDebug": false,
|
||||
"isProduction": true,
|
||||
"isAdmin": false,
|
||||
"isUserInteractive": true,
|
||||
"startupPath": "/opt/Radarr",
|
||||
"appData": "/home/test/.config/Radarr",
|
||||
"osName": "debian",
|
||||
"osVersion": "10",
|
||||
"isNetCore": true,
|
||||
"isMono": false,
|
||||
"isLinux": true,
|
||||
"isOsx": false,
|
||||
"isWindows": false,
|
||||
"isDocker": false,
|
||||
"mode": "console",
|
||||
"branch": "master",
|
||||
"authentication": "none",
|
||||
"sqliteVersion": "3.27.2",
|
||||
"migrationVersion": 195,
|
||||
"urlBase": "/radarr",
|
||||
"runtimeVersion": "5.0.5",
|
||||
"runtimeName": "netCore",
|
||||
"startTime": "2021-08-20T20:49:42Z",
|
||||
"packageUpdateMechanism": "builtIn"
|
||||
}
|
135
pkg/arr/radarr/types.go
Normal file
135
pkg/arr/radarr/types.go
Normal file
|
@ -0,0 +1,135 @@
|
|||
package radarr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/arr"
|
||||
)
|
||||
|
||||
type Movie struct {
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
MinimumAvailability string `json:"minimumAvailability,omitempty"`
|
||||
QualityProfileID int64 `json:"qualityProfileId,omitempty"`
|
||||
TmdbID int64 `json:"tmdbId,omitempty"`
|
||||
OriginalTitle string `json:"originalTitle,omitempty"`
|
||||
AlternateTitles []*AlternativeTitle `json:"alternateTitles,omitempty"`
|
||||
SecondaryYearSourceID int `json:"secondaryYearSourceId,omitempty"`
|
||||
SortTitle string `json:"sortTitle,omitempty"`
|
||||
SizeOnDisk int64 `json:"sizeOnDisk,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Overview string `json:"overview,omitempty"`
|
||||
InCinemas time.Time `json:"inCinemas,omitempty"`
|
||||
PhysicalRelease time.Time `json:"physicalRelease,omitempty"`
|
||||
DigitalRelease time.Time `json:"digitalRelease,omitempty"`
|
||||
Images []*arr.Image `json:"images,omitempty"`
|
||||
Website string `json:"website,omitempty"`
|
||||
Year int `json:"year,omitempty"`
|
||||
YouTubeTrailerID string `json:"youTubeTrailerId,omitempty"`
|
||||
Studio string `json:"studio,omitempty"`
|
||||
FolderName string `json:"folderName,omitempty"`
|
||||
Runtime int `json:"runtime,omitempty"`
|
||||
CleanTitle string `json:"cleanTitle,omitempty"`
|
||||
ImdbID string `json:"imdbId,omitempty"`
|
||||
TitleSlug string `json:"titleSlug,omitempty"`
|
||||
Certification string `json:"certification,omitempty"`
|
||||
Genres []string `json:"genres,omitempty"`
|
||||
Tags []int `json:"tags,omitempty"`
|
||||
Added time.Time `json:"added,omitempty"`
|
||||
Ratings *arr.Ratings `json:"ratings,omitempty"`
|
||||
MovieFile *MovieFile `json:"movieFile,omitempty"`
|
||||
Collection *Collection `json:"collection,omitempty"`
|
||||
HasFile bool `json:"hasFile,omitempty"`
|
||||
IsAvailable bool `json:"isAvailable,omitempty"`
|
||||
Monitored bool `json:"monitored"`
|
||||
}
|
||||
|
||||
type AlternativeTitle struct {
|
||||
MovieID int `json:"movieId"`
|
||||
Title string `json:"title"`
|
||||
SourceType string `json:"sourceType"`
|
||||
SourceID int `json:"sourceId"`
|
||||
Votes int `json:"votes"`
|
||||
VoteCount int `json:"voteCount"`
|
||||
Language *arr.Value `json:"language"`
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
type MovieFile struct {
|
||||
ID int64 `json:"id"`
|
||||
MovieID int64 `json:"movieId"`
|
||||
RelativePath string `json:"relativePath"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
DateAdded time.Time `json:"dateAdded"`
|
||||
SceneName string `json:"sceneName"`
|
||||
IndexerFlags int64 `json:"indexerFlags"`
|
||||
Quality *arr.Quality `json:"quality"`
|
||||
MediaInfo *MediaInfo `json:"mediaInfo"`
|
||||
QualityCutoffNotMet bool `json:"qualityCutoffNotMet"`
|
||||
Languages []*arr.Value `json:"languages"`
|
||||
ReleaseGroup string `json:"releaseGroup"`
|
||||
Edition string `json:"edition"`
|
||||
}
|
||||
|
||||
type MediaInfo struct {
|
||||
AudioAdditionalFeatures string `json:"audioAdditionalFeatures"`
|
||||
AudioBitrate int `json:"audioBitrate"`
|
||||
AudioChannels float64 `json:"audioChannels"`
|
||||
AudioCodec string `json:"audioCodec"`
|
||||
AudioLanguages string `json:"audioLanguages"`
|
||||
AudioStreamCount int `json:"audioStreamCount"`
|
||||
VideoBitDepth int `json:"videoBitDepth"`
|
||||
VideoBitrate int `json:"videoBitrate"`
|
||||
VideoCodec string `json:"videoCodec"`
|
||||
VideoFps float64 `json:"videoFps"`
|
||||
Resolution string `json:"resolution"`
|
||||
RunTime string `json:"runTime"`
|
||||
ScanType string `json:"scanType"`
|
||||
Subtitles string `json:"subtitles"`
|
||||
}
|
||||
|
||||
type Collection struct {
|
||||
Name string `json:"name"`
|
||||
TmdbID int64 `json:"tmdbId"`
|
||||
Images []*arr.Image `json:"images"`
|
||||
}
|
||||
|
||||
type Release struct {
|
||||
Title string `json:"title"`
|
||||
InfoUrl string `json:"infoUrl,omitempty"`
|
||||
DownloadUrl string `json:"downloadUrl,omitempty"`
|
||||
MagnetUrl string `json:"magnetUrl,omitempty"`
|
||||
Size uint64 `json:"size"`
|
||||
Indexer string `json:"indexer"`
|
||||
DownloadProtocol string `json:"downloadProtocol"`
|
||||
Protocol string `json:"protocol"`
|
||||
PublishDate string `json:"publishDate"`
|
||||
DownloadClientId int `json:"downloadClientId,omitempty"`
|
||||
DownloadClient string `json:"downloadClient,omitempty"`
|
||||
}
|
||||
|
||||
type PushResponse struct {
|
||||
Approved bool `json:"approved"`
|
||||
Rejected bool `json:"rejected"`
|
||||
TempRejected bool `json:"temporarilyRejected"`
|
||||
Rejections []string `json:"rejections"`
|
||||
}
|
||||
|
||||
type SystemStatusResponse struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type BadRequestResponse struct {
|
||||
Severity string `json:"severity"`
|
||||
ErrorCode string `json:"errorCode"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
PropertyName string `json:"propertyName"`
|
||||
AttemptedValue string `json:"attemptedValue"`
|
||||
}
|
||||
|
||||
func (r *BadRequestResponse) String() string {
|
||||
return fmt.Sprintf("[%s: %s] %s: %s - got value: %s", r.Severity, r.ErrorCode, r.PropertyName, r.ErrorMessage, r.AttemptedValue)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue