Monitor media before issue repair searches
This commit is contained in:
@@ -141,6 +141,8 @@ def _operation_result_message(
|
||||
return "Sonarr removed the existing episode file so it can be replaced."
|
||||
count = len(_result_items(result))
|
||||
return f"Sonarr found {_count_message(count, 'downloaded episode file')}."
|
||||
if service == "Sonarr" and normalized_path.endswith("/episode/monitor") and normalized_method == "PUT":
|
||||
return "Sonarr marked the selected episodes as wanted."
|
||||
if service == "Sonarr" and "/episode" in normalized_path and normalized_method == "GET":
|
||||
episodes = _result_items(result)
|
||||
available = sum(1 for item in episodes if isinstance(item, dict) and item.get("hasFile") is True)
|
||||
|
||||
@@ -39,6 +39,15 @@ class RadarrClient(ApiClient):
|
||||
async def search(self, movie_id: int) -> Optional[Dict[str, Any]]:
|
||||
return await self.post("/api/v3/command", payload={"name": "MoviesSearch", "movieIds": [movie_id]})
|
||||
|
||||
async def monitor_movie(
|
||||
self, movie_id: int, monitored: bool = True
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
movie = await self.get_movie(movie_id)
|
||||
if not isinstance(movie, dict):
|
||||
raise ValueError("Radarr did not return the movie before updating its monitored state")
|
||||
movie["monitored"] = monitored
|
||||
return await self.update_movie(movie)
|
||||
|
||||
async def delete_movie_file(self, movie_file_id: int) -> Optional[Any]:
|
||||
return await self.delete(
|
||||
f"/api/v3/moviefile/{movie_file_id}",
|
||||
|
||||
@@ -57,6 +57,14 @@ class SonarrClient(ApiClient):
|
||||
async def search_episodes(self, episode_ids: list[int]) -> Optional[Dict[str, Any]]:
|
||||
return await self.post("/api/v3/command", payload={"name": "EpisodeSearch", "episodeIds": episode_ids})
|
||||
|
||||
async def monitor_episodes(
|
||||
self, episode_ids: list[int], monitored: bool = True
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
return await self.put(
|
||||
"/api/v3/episode/monitor",
|
||||
payload={"episodeIds": episode_ids, "monitored": monitored},
|
||||
)
|
||||
|
||||
async def delete_episode_file(self, episode_file_id: int) -> Optional[Any]:
|
||||
return await self.delete(
|
||||
f"/api/v3/episodefile/{episode_file_id}",
|
||||
|
||||
@@ -1896,8 +1896,8 @@ def _issue_episode_payloads(
|
||||
"released": released,
|
||||
"monitored": monitored,
|
||||
"has_file": has_file,
|
||||
"missing": released and monitored and not has_file,
|
||||
"best_fit": released and monitored and not has_file,
|
||||
"missing": released and not has_file,
|
||||
"best_fit": released and not has_file,
|
||||
"file_id": episode.get("episodeFileId") if has_file else None,
|
||||
}
|
||||
)
|
||||
@@ -2154,6 +2154,7 @@ async def action_replace_media(
|
||||
radarr = RadarrClient(runtime.radarr_base_url, runtime.radarr_api_key)
|
||||
if not radarr.configured():
|
||||
raise HTTPException(status_code=400, detail="Radarr is not configured")
|
||||
await radarr.monitor_movie(movie_id, True)
|
||||
await radarr.delete_movie_file(file_ids[0])
|
||||
await radarr.search(movie_id)
|
||||
elif snapshot.request_type == RequestType.tv:
|
||||
@@ -2184,6 +2185,7 @@ async def action_replace_media(
|
||||
if not episode_ids:
|
||||
raise HTTPException(status_code=409, detail="Sonarr could not match episodes to this file")
|
||||
target_names = [_replacement_file_name(file_data) for file_data in selected_files]
|
||||
await sonarr.monitor_episodes(episode_ids, True)
|
||||
for selected_file_id in file_ids:
|
||||
await sonarr.delete_episode_file(selected_file_id)
|
||||
await sonarr.search_episodes(episode_ids)
|
||||
@@ -2295,6 +2297,7 @@ async def action_search_missing_media(
|
||||
radarr = RadarrClient(runtime.radarr_base_url, runtime.radarr_api_key)
|
||||
if not radarr.configured():
|
||||
raise HTTPException(status_code=400, detail="Radarr is not configured")
|
||||
await radarr.monitor_movie(collector_id, True)
|
||||
await radarr.search(collector_id)
|
||||
message = "Radarr started searching for the missing movie."
|
||||
searched_ids: List[int] = []
|
||||
@@ -2319,14 +2322,17 @@ async def action_search_missing_media(
|
||||
item_id
|
||||
for item_id, episode in episode_map.items()
|
||||
if _released_episode(episode)
|
||||
and episode.get("monitored") is not False
|
||||
and not (
|
||||
episode.get("hasFile") is True
|
||||
or (isinstance(episode.get("episodeFileId"), int) and episode.get("episodeFileId") > 0)
|
||||
)
|
||||
and (not season_numbers or episode.get("seasonNumber") in season_numbers)
|
||||
and (
|
||||
(season_numbers and episode.get("seasonNumber") in season_numbers)
|
||||
or (not season_numbers and episode.get("monitored") is not False)
|
||||
)
|
||||
]
|
||||
if searched_ids:
|
||||
await sonarr.monitor_episodes(searched_ids, True)
|
||||
await sonarr.search_episodes(searched_ids)
|
||||
message = f"Sonarr started searching for {len(searched_ids)} selected missing episode(s)."
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user