Resolve Arr metadata before adding media
This commit is contained in:
@@ -337,17 +337,25 @@ def _extract_requested_by_id(request_data: Any) -> Optional[int]:
|
||||
def _format_upstream_error(service: str, exc: httpx.HTTPStatusError) -> str:
|
||||
response = exc.response
|
||||
status = response.status_code if response is not None else "unknown"
|
||||
body = ""
|
||||
message = ""
|
||||
if response is not None:
|
||||
try:
|
||||
payload = response.json()
|
||||
body = json.dumps(payload, ensure_ascii=True)
|
||||
if isinstance(payload, dict):
|
||||
message = str(payload.get("message") or payload.get("error") or "").strip()
|
||||
elif isinstance(payload, list):
|
||||
validation_messages = [
|
||||
str(item.get("errorMessage") or item.get("message") or "").strip()
|
||||
for item in payload
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
message = "; ".join(item for item in validation_messages if item)
|
||||
except ValueError:
|
||||
body = response.text
|
||||
body = body.strip() if body else ""
|
||||
if body:
|
||||
return f"{service} error {status}: {body}"
|
||||
return f"{service} error {status}."
|
||||
message = response.text.strip()
|
||||
if message:
|
||||
compact_message = " ".join(message.split())[:500]
|
||||
return f"{service} could not complete the request ({status}): {compact_message}"
|
||||
return f"{service} could not complete the request ({status})."
|
||||
|
||||
|
||||
def _request_display_name(request_data: Any) -> Optional[str]:
|
||||
@@ -2318,6 +2326,12 @@ async def action_readd(request_id: str, user: Dict[str, str] = Depends(get_curre
|
||||
save_action, request_id, "readd_to_arr", "Re-add to Sonarr/Radarr", "failed", detail
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
except ValueError as exc:
|
||||
detail = f"Sonarr could not add this series: {exc}"
|
||||
await asyncio.to_thread(
|
||||
save_action, request_id, "readd_to_arr", "Re-add to Sonarr/Radarr", "failed", detail
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
await asyncio.to_thread(
|
||||
save_action,
|
||||
request_id,
|
||||
@@ -2353,9 +2367,17 @@ async def action_readd(request_id: str, user: Dict[str, str] = Depends(get_curre
|
||||
)
|
||||
return {"status": "ok", "message": message, "movieId": movie_id}
|
||||
root_folder = await _resolve_root_folder_path(client, runtime.radarr_root_folder, "Radarr")
|
||||
title = snapshot.title
|
||||
if title in {None, "", "Unknown"}:
|
||||
title = (
|
||||
media.get("title")
|
||||
or media.get("name")
|
||||
or jelly.get("title")
|
||||
or jelly.get("name")
|
||||
)
|
||||
try:
|
||||
response = await client.add_movie(
|
||||
int(tmdb_id), runtime.radarr_quality_profile_id, root_folder
|
||||
int(tmdb_id), runtime.radarr_quality_profile_id, root_folder, title=title
|
||||
)
|
||||
except httpx.HTTPStatusError as exc:
|
||||
detail = _format_upstream_error("Radarr", exc)
|
||||
@@ -2363,6 +2385,12 @@ async def action_readd(request_id: str, user: Dict[str, str] = Depends(get_curre
|
||||
save_action, request_id, "readd_to_arr", "Re-add to Sonarr/Radarr", "failed", detail
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
except ValueError as exc:
|
||||
detail = f"Radarr could not add this movie: {exc}"
|
||||
await asyncio.to_thread(
|
||||
save_action, request_id, "readd_to_arr", "Re-add to Sonarr/Radarr", "failed", detail
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
await asyncio.to_thread(
|
||||
save_action,
|
||||
request_id,
|
||||
|
||||
Reference in New Issue
Block a user