fix(requests/radarr): decode tmdb lookup as single object

- Radarr's /api/v3/movie/lookup/tmdb returns a single MovieResource, not an array
- Update test fixtures to match the actual response shape
This commit is contained in:
Silo Server Migration
2026-05-25 02:22:14 -04:00
parent ee8aefb311
commit b5d9243942
2 changed files with 8 additions and 9 deletions
+5 -6
View File
@@ -140,14 +140,13 @@ func (c *Client) CheckMovieStatus(ctx context.Context, req mediarequests.Request
func (c *Client) lookupMovie(ctx context.Context, client *arrclient.Client, tmdbID int) (movieResource, error) {
values := url.Values{}
values.Set("tmdbId", strconv.Itoa(tmdbID))
var matches []movieResource
if err := client.GetJSON(ctx, "/api/v3/movie/lookup/tmdb?"+values.Encode(), &matches); err != nil {
// Radarr's /api/v3/movie/lookup/tmdb returns a single MovieResource, unlike
// /api/v3/movie/lookup which returns an array. Missing IDs return non-2xx
// (handled as HTTPError upstream), so a successful response is the movie.
var movie movieResource
if err := client.GetJSON(ctx, "/api/v3/movie/lookup/tmdb?"+values.Encode(), &movie); err != nil {
return movieResource{}, err
}
if len(matches) == 0 {
return movieResource{}, fmt.Errorf("radarr: no movie found for tmdb_id %d", tmdbID)
}
movie := matches[0]
if movie.TMDBID == 0 {
movie.TMDBID = tmdbID
}
+3 -3
View File
@@ -37,7 +37,7 @@ func TestSubmitMovieAddsLookupResult(t *testing.T) {
if got := r.URL.Query().Get("tmdbId"); got != "550" {
t.Fatalf("lookup tmdbId = %q, want 550", got)
}
w.Write([]byte(`[{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}]`))
w.Write([]byte(`{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}`))
return
}
t.Fatalf("unexpected request %s %s", r.Method, r.URL.String())
@@ -78,7 +78,7 @@ func TestSubmitMovieRecoversFromEmptyAddResponse(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v3/movie/lookup/tmdb":
w.Write([]byte(`[{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}]`))
w.Write([]byte(`{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}`))
case "/api/v3/movie":
if r.Method == http.MethodPost {
w.WriteHeader(http.StatusCreated)
@@ -125,7 +125,7 @@ func TestSubmitMovieFallsBackWhenEmptyResponseAndLookupFails(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v3/movie/lookup/tmdb":
w.Write([]byte(`[{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}]`))
w.Write([]byte(`{"title":"Fight Club","tmdbId":550,"titleSlug":"fight-club"}`))
case "/api/v3/movie":
if r.Method == http.MethodPost {
w.WriteHeader(http.StatusCreated)