Add selectable animdl download fallback

This commit is contained in:
Dymas
2026-07-19 14:17:13 +02:00
parent 6bec0e068a
commit 6b3745c7e9
10 changed files with 282 additions and 65 deletions
+36 -2
View File
@@ -24,6 +24,7 @@ from uuid import uuid4
PROJECT_ROOT = Path(__file__).resolve().parent
ANI_CLI = os.environ.get("ANI_CLI_BIN") or shutil.which("ani-cli") or "ani-cli"
ANIPY_CLI = os.environ.get("ANIPY_CLI_BIN") or shutil.which("anipy-cli") or "anipy-cli"
ANIMDL = os.environ.get("ANIMDL_BIN") or shutil.which("animdl") or "animdl"
APP_NAME = "ani-cli-web"
VERSION_FILE = PROJECT_ROOT / "VERSION"
CHANGELOG_FILE = PROJECT_ROOT / "CHANGELOG.md"
@@ -41,6 +42,7 @@ DEBUG_MODE = False
QUALITY_CHOICES = {"best", "1080", "1080p", "720", "720p", "480", "480p", "360", "360p", "worst"}
MODE_CHOICES = {"sub", "dub"}
DOWNLOAD_METHOD_CHOICES = ("ani-cli", "anipy-cli", "animdl")
MEDIA_TYPE_CHOICES = {"tv", "movie"}
WATCHLIST_CATEGORY_LABELS = {
"watching": "Watching",
@@ -292,6 +294,7 @@ DEFAULT_CONFIG = {
"mode": os.environ.get("ANI_CLI_MODE", "sub"),
"quality": os.environ.get("ANI_CLI_QUALITY", "best"),
"anipy_cli_fallback_enabled": False,
"download_methods": ["ani-cli"],
"watchlist_auto_refresh_enabled": False,
"watchlist_auto_refresh_minutes": WATCHLIST_AUTO_REFRESH_DEFAULT_MINUTES,
"watchlist_refresh_delay_seconds": WATCHLIST_REFRESH_DELAY_DEFAULT_SECONDS,
@@ -438,6 +441,7 @@ def write_json(path, data):
def normalize_config(data):
source_has_download_methods = isinstance(data, dict) and "download_methods" in data
config = dict(DEFAULT_CONFIG)
if isinstance(data, dict):
config.update({key: data[key] for key in DEFAULT_CONFIG if key in data})
@@ -448,6 +452,7 @@ def normalize_config(data):
quality = quality[:-1]
download_dir = str(config.get("download_dir") or DEFAULT_CONFIG["download_dir"])
anipy_cli_fallback_enabled = config.get("anipy_cli_fallback_enabled")
download_methods = config.get("download_methods")
auto_refresh_enabled = config.get("watchlist_auto_refresh_enabled")
auto_refresh_minutes = config.get("watchlist_auto_refresh_minutes")
refresh_delay_seconds = config.get("watchlist_refresh_delay_seconds")
@@ -468,6 +473,18 @@ def normalize_config(data):
anipy_cli_fallback_enabled = anipy_cli_fallback_enabled.strip().lower() in {"1", "true", "yes", "on"}
else:
anipy_cli_fallback_enabled = bool(anipy_cli_fallback_enabled)
if isinstance(download_methods, str):
method_values = [part.strip().lower() for part in re.split(r"[\s,]+", download_methods) if part.strip()]
elif isinstance(download_methods, list):
method_values = [str(part or "").strip().lower() for part in download_methods]
else:
method_values = []
normalized_methods = []
for method in method_values:
if method in DOWNLOAD_METHOD_CHOICES and method not in normalized_methods:
normalized_methods.append(method)
if not normalized_methods or not source_has_download_methods:
normalized_methods = ["ani-cli", "anipy-cli"] if anipy_cli_fallback_enabled else ["ani-cli"]
if isinstance(auto_refresh_enabled, str):
auto_refresh_enabled = auto_refresh_enabled.strip().lower() in {"1", "true", "yes", "on"}
else:
@@ -501,7 +518,8 @@ def normalize_config(data):
config["mode"] = mode if mode in MODE_CHOICES else "sub"
config["quality"] = quality if quality in QUALITY_CHOICES else "best"
config["download_dir"] = str(Path(download_dir).expanduser())
config["anipy_cli_fallback_enabled"] = anipy_cli_fallback_enabled
config["download_methods"] = normalized_methods
config["anipy_cli_fallback_enabled"] = len(normalized_methods) > 1
config["watchlist_auto_refresh_enabled"] = auto_refresh_enabled
config["watchlist_auto_refresh_minutes"] = auto_refresh_minutes
config["watchlist_refresh_delay_seconds"] = refresh_delay_seconds
@@ -1131,7 +1149,7 @@ def finalize_library_files(job):
final_name = f"{library_name}{source.suffix}"
else:
ep = None
if backend == "anipy-cli" and requested_episode_values:
if backend in {"anipy-cli", "animdl"} and requested_episode_values:
ep = requested_episode_values.pop(0)
if ep is None:
ep = extract_episode_from_filename(source)
@@ -1211,6 +1229,22 @@ def command_for_job(job, backend="ani-cli", download_path=None):
if download_path:
command.extend(["-l", str(download_path)])
return command
if normalized_backend == "animdl":
query = str(job.get("query") or "").strip()
command = [
ANIMDL,
"download",
query,
"-r",
job["episodes"],
"-q",
job["quality"],
"--index",
"1",
]
if download_path:
command.extend(["-d", str(download_path)])
return command
command = [
ANI_CLI,
"-d",