-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebrid.py
More file actions
executable file
·42 lines (34 loc) · 1.48 KB
/
Copy pathdebrid.py
File metadata and controls
executable file
·42 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Multi-debrid abstraction.
When MULTI_DEBRID_ENABLED is true, check_cached_multi() queries all configured
providers (TorBox + RealDebrid). The candidate selector in processor.py uses
this to prefer cached releases across providers, falling back to a second
debrid if TorBox doesn't have a release cached.
Currently TorBox is primary and RealDebrid is fallback only - they don't share
.strm files, so a RealDebrid-only release would need RD-specific URL handling
that the .strm generator can't produce yet. The plumbing is in place for when
that's added.
"""
import logging
import torbox
log = logging.getLogger(__name__)
def check_cached_multi(hashes: list[str]) -> dict[str, set[str]]:
"""Return {provider: set_of_cached_hashes}. Empty providers omitted.
Raises torbox.RateLimited if TorBox returns 429/403 so callers can apply
a proper backoff instead of treating an empty result as "nothing cached"."""
out: dict[str, set[str]] = {}
if not hashes:
return out
out["torbox"] = torbox.check_cached(hashes) # may raise RateLimited
try:
import realdebrid
if realdebrid.is_configured():
out["realdebrid"] = realdebrid.check_cached(hashes)
except Exception as exc:
log.warning("RealDebrid check failed: %s", exc)
return out
def any_cached(hashes: list[str]) -> set[str]:
"""Hashes cached on any provider."""
result: set[str] = set()
for s in check_cached_multi(hashes).values():
result |= s
return result