Discover Sonarr episode downloads and keep live tracker updating
This commit is contained in:
@@ -56,6 +56,7 @@ from ..db import (
|
||||
active_repair_request_ids,
|
||||
)
|
||||
from ..services.media_repair import current_cycle_torrents
|
||||
from ..services.download_labels import label_episode_downloads
|
||||
from ..models import Snapshot, TriageResult, RequestType
|
||||
from ..services.snapshot import (
|
||||
_summarize_qbit,
|
||||
@@ -2734,6 +2735,22 @@ async def get_download_progress(
|
||||
raise HTTPException(status_code=503, detail="qBittorrent is not configured")
|
||||
|
||||
try:
|
||||
# Discover new jobs from the collector, not only yesterday's hashes or
|
||||
# legacy Magent tags. Sonarr-owned downloads do not have those tags.
|
||||
queue = None
|
||||
request = await asyncio.to_thread(get_request_cache_payload, int(request_id))
|
||||
if not isinstance(request, dict) and seerr.configured():
|
||||
request = await seerr.get_request(request_id)
|
||||
media = (request or {}).get("media") or {}
|
||||
if (request or {}).get("type") == "tv" and media.get("tvdbId"):
|
||||
collector = SonarrClient(runtime.sonarr_base_url, runtime.sonarr_api_key)
|
||||
items = await collector.get_series_by_tvdb_id(int(media["tvdbId"]))
|
||||
item = items[0] if isinstance(items, list) and items else None
|
||||
if item and item.get("id"):
|
||||
queue = await collector.get_queue(int(item["id"]))
|
||||
queue = {**queue, "records": [r for r in _queue_records(queue) if r.get("seriesId") == item["id"]]}
|
||||
hashes.extend(_download_ids(_queue_records(queue)))
|
||||
hashes = list(dict.fromkeys(h.strip().lower() for h in hashes if h.strip()))
|
||||
if hashes:
|
||||
result = await qbittorrent.get_torrents_by_hashes("|".join(hashes))
|
||||
else:
|
||||
@@ -2742,7 +2759,7 @@ async def get_download_progress(
|
||||
logger.warning("Live qBittorrent progress failed request_id=%s: %s", request_id, exc)
|
||||
raise HTTPException(status_code=502, detail="Live download progress is temporarily unavailable") from exc
|
||||
|
||||
torrents = current_cycle_torrents(result, cycle)
|
||||
torrents = label_episode_downloads(current_cycle_torrents(result, cycle), queue)
|
||||
for torrent in torrents:
|
||||
if isinstance(torrent, dict):
|
||||
torrent["progressPercent"] = _torrent_progress(torrent)
|
||||
|
||||
Reference in New Issue
Block a user