0.2.63 update

This commit is contained in:
ponzischeme89
2026-08-14 11:47:32 +12:00
parent 9a8ecbdceb
commit 06b6490ac9
41 changed files with 921 additions and 179 deletions
+34 -17
View File
@@ -58,7 +58,31 @@ type RootFolder struct {
}
type QualityProfile struct {
ID int `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
}
// RequestOptions are Memby's deliberate movie-request policy. Radarr defaults are never
// allowed to choose a profile or initiate a search on Memby's behalf.
type RequestOptions struct {
QualityProfileID int
SearchImmediately bool
}
func (c *Client) RootFolders(ctx context.Context) ([]RootFolder, error) {
var roots []RootFolder
if err := c.get(ctx, "/api/v3/rootfolder", &roots); err != nil {
return nil, err
}
return roots, nil
}
func (c *Client) QualityProfiles(ctx context.Context) ([]QualityProfile, error) {
var profiles []QualityProfile
if err := c.get(ctx, "/api/v3/qualityprofile", &profiles); err != nil {
return nil, err
}
return profiles, nil
}
type APIError struct {
@@ -116,29 +140,22 @@ func (c *Client) Lookup(ctx context.Context, term string) ([]Movie, error) {
return movies, nil
}
// AddRequested adds a title, monitors it and asks Radarr to search for it immediately.
// A request that merely creates an unmonitored catalogue row never reaches a downloader,
// which is indistinguishable from a broken button to the viewer who made it.
func (c *Client) AddRequested(ctx context.Context, movie Movie) (Movie, error) {
var roots []RootFolder
if err := c.get(ctx, "/api/v3/rootfolder", &roots); err != nil {
return Movie{}, err
// AddRequested adds a monitored movie using the supplied request policy.
func (c *Client) AddRequested(ctx context.Context, movie Movie, rootFolder string, options RequestOptions) (Movie, error) {
if strings.TrimSpace(rootFolder) == "" {
return Movie{}, fmt.Errorf("radarr: request root folder is required")
}
var profiles []QualityProfile
if err := c.get(ctx, "/api/v3/qualityprofile", &profiles); err != nil {
return Movie{}, err
}
if len(roots) == 0 || len(profiles) == 0 {
return Movie{}, fmt.Errorf("radarr: no root folder or quality profile configured")
if options.QualityProfileID <= 0 {
return Movie{}, fmt.Errorf("radarr: request quality profile is required")
}
movie.ID = 0
movie.RootFolderPath = roots[0].Path
movie.QualityProfileID = profiles[0].ID
movie.RootFolderPath = rootFolder
movie.QualityProfileID = options.QualityProfileID
movie.Monitored = true
body := struct {
Movie
AddOptions map[string]bool `json:"addOptions"`
}{Movie: movie, AddOptions: map[string]bool{"searchForMovie": true}}
}{Movie: movie, AddOptions: map[string]bool{"searchForMovie": options.SearchImmediately}}
var added Movie
if err := c.post(ctx, "/api/v3/movie", body, &added); err != nil {
return Movie{}, err
+4 -8
View File
@@ -48,13 +48,9 @@ func TestCalendarUsesV3APIAndKeepsKeyInHeader(t *testing.T) {
}
}
func TestAddRequestedUsesDefaultsAndStartsSearch(t *testing.T) {
func TestAddRequestedUsesExplicitPolicyWithoutSearching(t *testing.T) {
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v3/rootfolder":
_, _ = w.Write([]byte(`[{"path":"/movies"}]`))
case "/api/v3/qualityprofile":
_, _ = w.Write([]byte(`[{"id":4}]`))
case "/api/v3/movie":
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
@@ -65,8 +61,8 @@ func TestAddRequestedUsesDefaultsAndStartsSearch(t *testing.T) {
t.Errorf("unexpected add body: %#v", body)
}
options := body["addOptions"].(map[string]any)
if options["searchForMovie"] != true {
t.Errorf("movie search was not enabled: %#v", body)
if options["searchForMovie"] != false {
t.Errorf("movie search was unexpectedly enabled: %#v", body)
}
_, _ = w.Write([]byte(`{"id":9,"tmdbId":22,"title":"Arrival"}`))
default:
@@ -76,7 +72,7 @@ func TestAddRequestedUsesDefaultsAndStartsSearch(t *testing.T) {
defer upstream.Close()
added, err := New(upstream.URL, "secret", time.Second).AddRequested(
context.Background(), Movie{TMDBID: 22, Title: "Arrival"},
context.Background(), Movie{TMDBID: 22, Title: "Arrival"}, "/movies", RequestOptions{QualityProfileID: 4},
)
if err != nil {
t.Fatal(err)