feat: add seasons from request details
This commit is contained in:
@@ -369,6 +369,38 @@ def _episode_availability(episodes: Any) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _unmonitored_season_options(series: Any, episodes: Any) -> List[Dict[str, int]]:
|
||||
"""Describe regular Sonarr seasons that can be added to an existing request."""
|
||||
if not isinstance(series, dict) or not isinstance(series.get("seasons"), list):
|
||||
return []
|
||||
episode_rows = [episode for episode in episodes if isinstance(episode, dict)] if isinstance(episodes, list) else []
|
||||
options: List[Dict[str, int]] = []
|
||||
for season in series["seasons"]:
|
||||
if not isinstance(season, dict) or season.get("monitored") is not False:
|
||||
continue
|
||||
season_number = season.get("seasonNumber")
|
||||
if not isinstance(season_number, int) or season_number <= 0:
|
||||
continue
|
||||
matching = [episode for episode in episode_rows if episode.get("seasonNumber") == season_number]
|
||||
statistics = season.get("statistics") if isinstance(season.get("statistics"), dict) else {}
|
||||
episode_count = statistics.get("totalEpisodeCount")
|
||||
if not isinstance(episode_count, int):
|
||||
episode_count = statistics.get("episodeCount")
|
||||
if not isinstance(episode_count, int):
|
||||
episode_count = len(matching)
|
||||
available = statistics.get("episodeFileCount")
|
||||
if not isinstance(available, int):
|
||||
available = sum(1 for episode in matching if episode.get("hasFile") is True)
|
||||
options.append(
|
||||
{
|
||||
"seasonNumber": season_number,
|
||||
"episodeCount": max(0, episode_count),
|
||||
"available": max(0, available),
|
||||
}
|
||||
)
|
||||
return sorted(options, key=lambda item: item["seasonNumber"])
|
||||
|
||||
|
||||
def _summarize_qbit(torrents: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
if not torrents:
|
||||
return {"state": "idle", "message": "0 active downloads."}
|
||||
@@ -939,6 +971,7 @@ def _build_presentation(
|
||||
"missing": missing,
|
||||
"total": total,
|
||||
"seasons": availability.get("seasons") or [],
|
||||
"unmonitoredSeasons": arr_details.get("unmonitoredSeasons") or [],
|
||||
"missingEpisodes": arr_details.get("missingEpisodes") or {},
|
||||
},
|
||||
{
|
||||
@@ -1240,6 +1273,7 @@ async def build_snapshot(request_id: str) -> Snapshot:
|
||||
"state": await read_search_status(sonarr, RequestType.tv, series_id, episodes)
|
||||
}
|
||||
arr_details["availability"] = _episode_availability(episodes)
|
||||
arr_details["unmonitoredSeasons"] = _unmonitored_season_options(arr_item, episodes)
|
||||
counts = arr_details["availability"]
|
||||
arr_state = "available" if counts.get("total", 0) > 0 and not counts.get("missing") else "added"
|
||||
missing_by_season = _missing_episode_numbers_by_season(episodes)
|
||||
|
||||
Reference in New Issue
Block a user