Fallback manual grab to qBittorrent
This commit is contained in:
@@ -67,3 +67,9 @@ class QBittorrentClient(ApiClient):
|
|||||||
await self._post_form("/api/v2/torrents/start", data={"hashes": hashes})
|
await self._post_form("/api/v2/torrents/start", data={"hashes": hashes})
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
async def add_torrent_url(self, url: str, category: Optional[str] = None) -> None:
|
||||||
|
data: Dict[str, Any] = {"urls": url}
|
||||||
|
if category:
|
||||||
|
data["category"] = category
|
||||||
|
await self._post_form("/api/v2/torrents/add", data=data)
|
||||||
|
|||||||
@@ -1569,6 +1569,7 @@ async def action_grab(
|
|||||||
snapshot = await build_snapshot(request_id)
|
snapshot = await build_snapshot(request_id)
|
||||||
guid = payload.get("guid")
|
guid = payload.get("guid")
|
||||||
indexer_id = payload.get("indexerId")
|
indexer_id = payload.get("indexerId")
|
||||||
|
download_url = payload.get("downloadUrl")
|
||||||
if not guid or not indexer_id:
|
if not guid or not indexer_id:
|
||||||
raise HTTPException(status_code=400, detail="Missing guid or indexerId")
|
raise HTTPException(status_code=400, detail="Missing guid or indexerId")
|
||||||
|
|
||||||
@@ -1580,6 +1581,28 @@ async def action_grab(
|
|||||||
try:
|
try:
|
||||||
response = await client.grab_release(str(guid), int(indexer_id))
|
response = await client.grab_release(str(guid), int(indexer_id))
|
||||||
except httpx.HTTPStatusError as exc:
|
except httpx.HTTPStatusError as exc:
|
||||||
|
status_code = exc.response.status_code if exc.response is not None else 502
|
||||||
|
if status_code == 404 and download_url:
|
||||||
|
qbit = QBittorrentClient(
|
||||||
|
runtime.qbittorrent_base_url,
|
||||||
|
runtime.qbittorrent_username,
|
||||||
|
runtime.qbittorrent_password,
|
||||||
|
)
|
||||||
|
if not qbit.configured():
|
||||||
|
raise HTTPException(status_code=400, detail="qBittorrent not configured")
|
||||||
|
try:
|
||||||
|
await qbit.add_torrent_url(str(download_url))
|
||||||
|
except httpx.HTTPStatusError as qbit_exc:
|
||||||
|
raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc
|
||||||
|
await asyncio.to_thread(
|
||||||
|
save_action,
|
||||||
|
request_id,
|
||||||
|
"grab",
|
||||||
|
"Grab release",
|
||||||
|
"ok",
|
||||||
|
"Sent to qBittorrent via Prowlarr.",
|
||||||
|
)
|
||||||
|
return {"status": "ok", "message": "Sent to qBittorrent.", "via": "qbittorrent"}
|
||||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
save_action, request_id, "grab", "Grab release", "ok", "Grab sent to Sonarr."
|
save_action, request_id, "grab", "Grab release", "ok", "Grab sent to Sonarr."
|
||||||
@@ -1592,6 +1615,28 @@ async def action_grab(
|
|||||||
try:
|
try:
|
||||||
response = await client.grab_release(str(guid), int(indexer_id))
|
response = await client.grab_release(str(guid), int(indexer_id))
|
||||||
except httpx.HTTPStatusError as exc:
|
except httpx.HTTPStatusError as exc:
|
||||||
|
status_code = exc.response.status_code if exc.response is not None else 502
|
||||||
|
if status_code == 404 and download_url:
|
||||||
|
qbit = QBittorrentClient(
|
||||||
|
runtime.qbittorrent_base_url,
|
||||||
|
runtime.qbittorrent_username,
|
||||||
|
runtime.qbittorrent_password,
|
||||||
|
)
|
||||||
|
if not qbit.configured():
|
||||||
|
raise HTTPException(status_code=400, detail="qBittorrent not configured")
|
||||||
|
try:
|
||||||
|
await qbit.add_torrent_url(str(download_url))
|
||||||
|
except httpx.HTTPStatusError as qbit_exc:
|
||||||
|
raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc
|
||||||
|
await asyncio.to_thread(
|
||||||
|
save_action,
|
||||||
|
request_id,
|
||||||
|
"grab",
|
||||||
|
"Grab release",
|
||||||
|
"ok",
|
||||||
|
"Sent to qBittorrent via Prowlarr.",
|
||||||
|
)
|
||||||
|
return {"status": "ok", "message": "Sent to qBittorrent.", "via": "qbittorrent"}
|
||||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
save_action, request_id, "grab", "Grab release", "ok", "Grab sent to Radarr."
|
save_action, request_id, "grab", "Grab release", "ok", "Grab sent to Radarr."
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ type ReleaseOption = {
|
|||||||
leechers?: number
|
leechers?: number
|
||||||
protocol?: string
|
protocol?: string
|
||||||
infoUrl?: string
|
infoUrl?: string
|
||||||
|
downloadUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SnapshotHistory = {
|
type SnapshotHistory = {
|
||||||
@@ -589,6 +590,7 @@ export default function RequestTimelinePage({ params }: { params: { id: string }
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
guid: release.guid,
|
guid: release.guid,
|
||||||
indexerId: release.indexerId,
|
indexerId: release.indexerId,
|
||||||
|
downloadUrl: release.downloadUrl,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user