Add selectable animdl download fallback
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 0.49.0 - 2026-07-19
|
||||
|
||||
- Added `animdl` as a third queue download backend and Docker-installed fallback tool.
|
||||
- Replaced the single `anipy-cli` fallback toggle with selectable download methods for `ani-cli`, `anipy-cli`, and `animdl`; queue jobs try the checked methods in that order.
|
||||
- Exposed `animdl` availability and version in the Config page runtime checks.
|
||||
|
||||
## 0.48.3 - 2026-07-17
|
||||
|
||||
- Added Jellyfin handoff jobs to the Queue page so manual copy jobs appear alongside downloads with live progress, moved-file counts, and recent handoff activity.
|
||||
|
||||
+3
-2
@@ -49,8 +49,9 @@ RUN curl -fL "${YT_DLP_RELEASE_URL}" -o /usr/local/bin/yt-dlp \
|
||||
&& chmod 0755 /usr/local/bin/yt-dlp \
|
||||
&& yt-dlp --version
|
||||
|
||||
RUN python3 -m pip install --no-cache-dir anipy-cli \
|
||||
&& anipy-cli --version
|
||||
RUN python3 -m pip install --no-cache-dir anipy-cli animdl \
|
||||
&& anipy-cli --version \
|
||||
&& animdl --version
|
||||
|
||||
RUN git clone --depth 1 --branch "${ANI_CLI_WEB_BRANCH}" "${ANI_CLI_WEB}" /app \
|
||||
&& rm -rf /app/.git \
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
Local web UI for a system-wide `ani-cli` install.
|
||||
|
||||
Current version: `0.48.3`
|
||||
Current version: `0.49.0`
|
||||
|
||||
## What it does
|
||||
|
||||
- Search anime in `sub` or `dub`, with poster-style results shown below the selection panel and the first English alternate title when available
|
||||
- Queue downloads with folder, quality, media type, season, and episode controls
|
||||
- Optionally retry failed `ani-cli` downloads with `anipy-cli`
|
||||
- Choose which download backends queue jobs may use: `ani-cli`, `anipy-cli`, and `animdl`
|
||||
- Track shows in a watchlist with `Watching`, `Planned`, `Finished`, and `Dropped` categories
|
||||
- Expose a small JSON summary endpoint for Homepage dashboard widgets
|
||||
- Refresh watchlist episode counts manually or on a schedule
|
||||
@@ -22,14 +22,14 @@ Current version: `0.48.3`
|
||||
- `/`: Search and queue downloads, with poster-card search results below the selection box and alternate English titles under the main name when available
|
||||
- `/queue`: Monitor downloads and Jellyfin handoff jobs, inspect logs, retry failed downloads, avoid duplicate re-queues for the same failed download, clear failed jobs, and remove finished jobs
|
||||
- `/watchlist`: Track shows, refresh them, download all available episodes, and manage auto-download settings such as `Source name`, library `Name`, season, and episode offset
|
||||
- `/config`: Save defaults, toggle `anipy-cli` fallback retries, schedule refreshes, configure Jellyfin and Discord, monitor Jellyfin handoff progress, and view runtime info and the changelog
|
||||
- `/config`: Save defaults, choose queue download methods and fallback retries, schedule refreshes, configure Jellyfin and Discord, monitor Jellyfin handoff progress, and view runtime info and the changelog
|
||||
|
||||
## Quick start
|
||||
|
||||
Requirements:
|
||||
|
||||
- `ani-cli` installed and available in `PATH`
|
||||
- Optional: `anipy-cli` installed and available in `PATH` if you want automatic fallback retries outside Docker
|
||||
- Optional: `anipy-cli` and/or `animdl` installed and available in `PATH` if you want automatic fallback retries outside Docker
|
||||
- Common runtime tools used by `ani-cli`, especially `curl`, `ffmpeg`, `fzf`, `grep`, `openssl`, `sed`, `aria2c`, `botan`, and `yt-dlp`
|
||||
|
||||
Run locally:
|
||||
@@ -51,6 +51,7 @@ Useful flags and env:
|
||||
- `ANI_CLI_WEB_PORT=8421`
|
||||
- `ANI_CLI_BIN=/path/to/ani-cli`
|
||||
- `ANIPY_CLI_BIN=/path/to/anipy-cli`
|
||||
- `ANIMDL_BIN=/path/to/animdl`
|
||||
|
||||
## Docker
|
||||
|
||||
@@ -95,7 +96,7 @@ Docker notes:
|
||||
- `UPDATE_ON_START=true` runs `ani-cli --update` before startup
|
||||
- `ANI_CLI_WEB_BRANCH` lets the image clone a specific `ani-cli-web` branch at build time
|
||||
- `botan` is installed inside the container for providers or scripts that need Botan cryptography tooling
|
||||
- `anipy-cli` is installed systemwide inside the container, so fallback retries are available without extra container setup
|
||||
- `anipy-cli` and `animdl` are installed systemwide inside the container, so fallback retries are available without extra container setup
|
||||
|
||||
## Key behavior
|
||||
|
||||
@@ -117,9 +118,11 @@ Docker notes:
|
||||
### Download fallback
|
||||
|
||||
- Optional and configured from `/config`
|
||||
- When enabled, a failed `ani-cli` queue job retries once with `anipy-cli`
|
||||
- Fallback retries keep the queued episode numbers when the downloaded `anipy-cli` filenames are renumbered from `1`
|
||||
- Docker images install `anipy-cli` automatically; non-Docker installs should provide it in `PATH` themselves
|
||||
- Queue jobs can use any checked combination of `ani-cli`, `anipy-cli`, and `animdl`
|
||||
- Checked methods are tried in this order: `ani-cli`, `anipy-cli`, then `animdl`
|
||||
- Selecting one method disables fallback retry; selecting multiple methods makes later methods automatic fallbacks
|
||||
- Fallback retries keep the queued episode numbers when fallback downloader filenames are renumbered from `1`
|
||||
- Docker images install `anipy-cli` and `animdl` automatically; non-Docker installs should provide the selected tools in `PATH` themselves
|
||||
|
||||
### Queue retries
|
||||
|
||||
@@ -162,7 +165,7 @@ The Config page runtime panel shows:
|
||||
|
||||
- `ani-cli-web` version loaded from `VERSION`
|
||||
- Installed `ani-cli` version
|
||||
- Installed `anipy-cli` version and dependency status
|
||||
- Installed `anipy-cli` and `animdl` versions and dependency status
|
||||
- A `Changelog` button that opens a scrollable viewer backed by `CHANGELOG.md`
|
||||
|
||||
## Remote access
|
||||
@@ -211,6 +214,7 @@ Most users only need these environment variables:
|
||||
|
||||
- `ANI_CLI_BIN`
|
||||
- `ANIPY_CLI_BIN`
|
||||
- `ANIMDL_BIN`
|
||||
- `ANI_CLI_WEB_HOST`
|
||||
- `ANI_CLI_WEB_PORT`
|
||||
- `ANI_CLI_WEB_ALLOW_REMOTE`
|
||||
|
||||
@@ -2766,6 +2766,8 @@ def save_runtime_config(config):
|
||||
current = get_config_snapshot(fallback=DEFAULT_CONFIG)
|
||||
merged = dict(current)
|
||||
if isinstance(config, dict):
|
||||
if "anipy_cli_fallback_enabled" in config and "download_methods" not in config:
|
||||
merged.pop("download_methods", None)
|
||||
merged.update(config)
|
||||
normalized = normalize_config(merged)
|
||||
previous_fingerprint = remote_access_session_fingerprint(current)
|
||||
|
||||
+36
-2
@@ -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",
|
||||
|
||||
+19
-11
@@ -463,6 +463,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
<p id="versionLine">Loading version...</p>
|
||||
<p id="aniCliVersionLine">Detecting ani-cli version...</p>
|
||||
<p id="anipyCliVersionLine">Detecting anipy-cli fallback...</p>
|
||||
<p id="animdlVersionLine">Detecting animdl fallback...</p>
|
||||
<p>Saved settings live in `.ani-cli-web/config.json` inside this project.</p>
|
||||
</div>
|
||||
<button class="ghost wide-button" id="openChangelogBtn" type="button">Changelog</button>
|
||||
@@ -512,18 +513,15 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
<div class="toolbar">
|
||||
<div>
|
||||
<h2>Download fallback</h2>
|
||||
<p class="muted">If a queued `ani-cli` download fails, optionally retry it once with `anipy-cli`.</p>
|
||||
<p class="muted">Choose the download methods queue jobs may use, in fallback order.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label>Automatic retry with anipy-cli
|
||||
<select id="anipyCliFallbackEnabled">
|
||||
<option value="false">Disabled</option>
|
||||
<option value="true">Enabled</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="check-grid">
|
||||
<label class="check-item"><input class="download-method" type="checkbox" value="ani-cli"> <span>ani-cli</span></label>
|
||||
<label class="check-item"><input class="download-method" type="checkbox" value="anipy-cli"> <span>anipy-cli</span></label>
|
||||
<label class="check-item"><input class="download-method" type="checkbox" value="animdl"> <span>animdl</span></label>
|
||||
</div>
|
||||
<div class="field-hint">This only kicks in after an `ani-cli` failure. Install `anipy-cli` separately and keep it in `PATH` if you enable this option.</div>
|
||||
<div class="field-hint">Jobs try checked methods in this order: ani-cli, anipy-cli, animdl. With one method checked, fallback retry is disabled.</div>
|
||||
</section>
|
||||
|
||||
<section class="settings settings-main">
|
||||
@@ -687,6 +685,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
quality: "best",
|
||||
download_dir: "",
|
||||
anipy_cli_fallback_enabled: false,
|
||||
download_methods: ["ani-cli"],
|
||||
watchlist_auto_refresh_enabled: false,
|
||||
watchlist_auto_refresh_minutes: 60,
|
||||
watchlist_refresh_delay_seconds: 5,
|
||||
@@ -748,12 +747,17 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
return [...document.querySelectorAll(".webhook-event:checked")].map((input) => input.value);
|
||||
}
|
||||
|
||||
function selectedDownloadMethods() {
|
||||
const methods = [...document.querySelectorAll(".download-method:checked")].map((input) => input.value);
|
||||
return methods.length ? methods : ["ani-cli"];
|
||||
}
|
||||
|
||||
function formConfigPayload() {
|
||||
return {
|
||||
download_dir: $("downloadDir").value,
|
||||
mode: $("configMode").value,
|
||||
quality: $("configQuality").value,
|
||||
anipy_cli_fallback_enabled: $("anipyCliFallbackEnabled").value === "true",
|
||||
download_methods: selectedDownloadMethods(),
|
||||
watchlist_auto_refresh_enabled: $("watchlistAutoRefreshEnabled").value === "true",
|
||||
watchlist_auto_refresh_minutes: $("watchlistAutoRefreshMinutes").value,
|
||||
watchlist_refresh_delay_seconds: $("watchlistRefreshDelaySeconds").value,
|
||||
@@ -773,7 +777,10 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
$("downloadDir").value = data.download_dir;
|
||||
$("configMode").value = data.mode;
|
||||
$("configQuality").value = data.quality;
|
||||
$("anipyCliFallbackEnabled").value = String(Boolean(data.anipy_cli_fallback_enabled));
|
||||
const methods = new Set(data.download_methods || ["ani-cli"]);
|
||||
for (const input of document.querySelectorAll(".download-method")) {
|
||||
input.checked = methods.has(input.value);
|
||||
}
|
||||
$("watchlistAutoRefreshEnabled").value = String(Boolean(data.watchlist_auto_refresh_enabled));
|
||||
$("watchlistAutoRefreshMinutes").value = data.watchlist_auto_refresh_minutes;
|
||||
$("watchlistRefreshDelaySeconds").value = data.watchlist_refresh_delay_seconds;
|
||||
@@ -984,6 +991,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
$("versionLine").textContent = `${data.name} ${data.version}`;
|
||||
$("aniCliVersionLine").textContent = `ani-cli ${data.ani_cli_version || "Unavailable"}`;
|
||||
$("anipyCliVersionLine").textContent = `anipy-cli ${data.anipy_cli_version || "Unavailable"}`;
|
||||
$("animdlVersionLine").textContent = `animdl ${data.animdl_version || "Unavailable"}`;
|
||||
}
|
||||
|
||||
async function openChangelog() {
|
||||
|
||||
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
from urllib.parse import parse_qs, unquote, urlencode, urlparse, urlunparse
|
||||
|
||||
from app_support import (
|
||||
ANIMDL,
|
||||
ANI_CLI,
|
||||
ANIPY_CLI,
|
||||
APP_NAME,
|
||||
@@ -94,6 +95,7 @@ def dependency_status():
|
||||
result = {name: bool(shutil.which(name)) for name in checks}
|
||||
result["ani-cli"] = cli_executable_exists(ANI_CLI)
|
||||
result["anipy-cli"] = cli_executable_exists(ANIPY_CLI)
|
||||
result["animdl"] = cli_executable_exists(ANIMDL)
|
||||
return result
|
||||
|
||||
|
||||
@@ -248,6 +250,22 @@ def installed_anipy_cli_version():
|
||||
return version or "Unavailable"
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def installed_animdl_version():
|
||||
try:
|
||||
completed = subprocess.run(
|
||||
[ANIMDL, "--version"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=6,
|
||||
)
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return "Unavailable"
|
||||
version = str(completed.stdout or completed.stderr or "").strip()
|
||||
return version or "Unavailable"
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
server_version = "AniCliWeb/1.0"
|
||||
remote_session_cookie_name = "ani_cli_web_session"
|
||||
@@ -629,6 +647,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"version": VERSION,
|
||||
"ani_cli_version": installed_ani_cli_version(),
|
||||
"anipy_cli_version": installed_anipy_cli_version(),
|
||||
"animdl_version": installed_animdl_version(),
|
||||
}
|
||||
)
|
||||
elif parsed.path == "/api/changelog":
|
||||
|
||||
+62
-38
@@ -13,7 +13,10 @@ import time
|
||||
import re
|
||||
|
||||
from app_support import (
|
||||
ANIMDL,
|
||||
ANIPY_CLI,
|
||||
ANI_CLI,
|
||||
DOWNLOAD_METHOD_CHOICES,
|
||||
MAX_LOG_LINES,
|
||||
PROJECT_ROOT,
|
||||
QUEUE_PATH,
|
||||
@@ -37,6 +40,11 @@ from app_support import (
|
||||
|
||||
LOG_PERSIST_INTERVAL_SECONDS = 0.75
|
||||
LOG_PERSIST_LINE_BATCH = 8
|
||||
DOWNLOAD_BACKEND_COMMANDS = {
|
||||
"ani-cli": ANI_CLI,
|
||||
"anipy-cli": ANIPY_CLI,
|
||||
"animdl": ANIMDL,
|
||||
}
|
||||
JOB_STRUCTURED_COLUMNS = (
|
||||
"show_id",
|
||||
"title",
|
||||
@@ -1490,34 +1498,46 @@ class DownloadQueue:
|
||||
self._cleanup_staging_dir(job)
|
||||
|
||||
def _command_attempts(self, job, staging_dir):
|
||||
config = normalize_config(self.config_getter() or {})
|
||||
attempts = [
|
||||
{
|
||||
"backend": "ani-cli",
|
||||
"command": command_for_job(job, backend="ani-cli"),
|
||||
"env": {
|
||||
**os.environ.copy(),
|
||||
"ANI_CLI_DOWNLOAD_DIR": str(staging_dir),
|
||||
"ANI_CLI_MODE": job["mode"],
|
||||
"ANI_CLI_QUALITY": job["quality"],
|
||||
"TERM": os.environ.get("TERM", "xterm-256color"),
|
||||
},
|
||||
}
|
||||
]
|
||||
fallback_enabled = bool(config.get("anipy_cli_fallback_enabled"))
|
||||
fallback_available = cli_executable_exists(ANIPY_CLI)
|
||||
if fallback_enabled and fallback_available:
|
||||
attempts.append(
|
||||
{
|
||||
"backend": "anipy-cli",
|
||||
"command": command_for_job(job, backend="anipy-cli", download_path=staging_dir),
|
||||
def attempt_for(method):
|
||||
if method == "ani-cli":
|
||||
return {
|
||||
"backend": "ani-cli",
|
||||
"command": command_for_job(job, backend="ani-cli"),
|
||||
"env": {
|
||||
**os.environ.copy(),
|
||||
"ANI_CLI_DOWNLOAD_DIR": str(staging_dir),
|
||||
"ANI_CLI_MODE": job["mode"],
|
||||
"ANI_CLI_QUALITY": job["quality"],
|
||||
"TERM": os.environ.get("TERM", "xterm-256color"),
|
||||
},
|
||||
}
|
||||
)
|
||||
return attempts, fallback_enabled, fallback_available
|
||||
return {
|
||||
"backend": method,
|
||||
"command": command_for_job(job, backend=method, download_path=staging_dir),
|
||||
"env": {
|
||||
**os.environ.copy(),
|
||||
"TERM": os.environ.get("TERM", "xterm-256color"),
|
||||
},
|
||||
}
|
||||
|
||||
config = normalize_config(self.config_getter() or {})
|
||||
selected_methods = [
|
||||
method
|
||||
for method in config.get("download_methods") or ["ani-cli"]
|
||||
if method in DOWNLOAD_METHOD_CHOICES
|
||||
]
|
||||
if not selected_methods:
|
||||
selected_methods = ["ani-cli"]
|
||||
attempts = []
|
||||
unavailable_methods = []
|
||||
for method in selected_methods:
|
||||
if not cli_executable_exists(DOWNLOAD_BACKEND_COMMANDS.get(method)):
|
||||
unavailable_methods.append(method)
|
||||
continue
|
||||
attempts.append(attempt_for(method))
|
||||
if not attempts:
|
||||
attempts.append(attempt_for(selected_methods[0]))
|
||||
return attempts, selected_methods, unavailable_methods
|
||||
|
||||
def _run(self):
|
||||
while not self.stop_event.is_set():
|
||||
@@ -1533,7 +1553,7 @@ class DownloadQueue:
|
||||
target_dir = job_output_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
attempts, fallback_enabled, fallback_available = self._command_attempts(job, staging_dir)
|
||||
attempts, selected_methods, unavailable_methods = self._command_attempts(job, staging_dir)
|
||||
primary_command = attempts[0]["command"]
|
||||
|
||||
with self.lock:
|
||||
@@ -1543,17 +1563,21 @@ class DownloadQueue:
|
||||
job["command"] = printable_command(primary_command)
|
||||
job["staging_dir"] = str(staging_dir)
|
||||
job["target_dir"] = str(target_dir)
|
||||
job["download_backend"] = "ani-cli"
|
||||
job["download_backend"] = attempts[0]["backend"]
|
||||
job["fallback_used"] = False
|
||||
job["log"] = [
|
||||
f"Starting: {job['command']}",
|
||||
f"Staging in: {job['staging_dir']}",
|
||||
f"Final folder: {job['target_dir']}",
|
||||
f"Download methods: {', '.join(selected_methods)}",
|
||||
]
|
||||
if fallback_enabled and fallback_available:
|
||||
job["log"].append("anipy-cli fallback is enabled and will retry automatically if ani-cli fails.")
|
||||
elif fallback_enabled:
|
||||
job["log"].append("anipy-cli fallback is enabled, but anipy-cli is not installed or not executable.")
|
||||
if len(attempts) > 1:
|
||||
job["log"].append("Fallback retry is enabled for the selected download methods.")
|
||||
if unavailable_methods:
|
||||
job["log"].append(
|
||||
"Skipped unavailable download method"
|
||||
f"{'s' if len(unavailable_methods) != 1 else ''}: {', '.join(unavailable_methods)}."
|
||||
)
|
||||
job["cancel_requested"] = False
|
||||
job["_dirty_log_lines"] = 0
|
||||
self._save_job_locked(job)
|
||||
@@ -1593,8 +1617,8 @@ class DownloadQueue:
|
||||
)
|
||||
except Exception as exc:
|
||||
if should_fallback:
|
||||
self._append_log(job, f"ani-cli could not start: {exc}")
|
||||
self._append_log(job, "Retrying with anipy-cli fallback.")
|
||||
self._append_log(job, f"{backend} could not start: {exc}")
|
||||
self._append_log(job, f"Retrying with {attempts[index + 1]['backend']} fallback.")
|
||||
self._cleanup_staging_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
continue
|
||||
@@ -1621,9 +1645,9 @@ class DownloadQueue:
|
||||
if job.get("cancel_requested"):
|
||||
break
|
||||
|
||||
if backend == "ani-cli" and exit_code != 0 and should_fallback:
|
||||
self._append_log(job, f"ani-cli failed with exit code {exit_code}.")
|
||||
self._append_log(job, "Retrying with anipy-cli fallback.")
|
||||
if exit_code != 0 and should_fallback:
|
||||
self._append_log(job, f"{backend} failed with exit code {exit_code}.")
|
||||
self._append_log(job, f"Retrying with {attempts[index + 1]['backend']} fallback.")
|
||||
self._cleanup_staging_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
continue
|
||||
@@ -1634,10 +1658,10 @@ class DownloadQueue:
|
||||
except Exception as exc:
|
||||
finalize_error = exc
|
||||
no_files_downloaded = "No downloaded files were found in the staging folder" in str(exc)
|
||||
if backend == "ani-cli" and no_files_downloaded and should_fallback:
|
||||
if no_files_downloaded and should_fallback:
|
||||
self._append_log(
|
||||
job,
|
||||
"ani-cli exited without downloading any files. Retrying with anipy-cli fallback.",
|
||||
f"{backend} exited without downloading any files. Retrying with {attempts[index + 1]['backend']} fallback.",
|
||||
)
|
||||
self._cleanup_staging_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -1674,8 +1698,8 @@ class DownloadQueue:
|
||||
cleanup_staging = True
|
||||
elif exit_code == 0:
|
||||
job["status"] = "done"
|
||||
if successful_backend == "anipy-cli":
|
||||
job.setdefault("log", []).append("Fallback download completed with anipy-cli.")
|
||||
if successful_backend and successful_backend != attempts[0]["backend"]:
|
||||
job.setdefault("log", []).append(f"Fallback download completed with {successful_backend}.")
|
||||
for path in moved_files:
|
||||
job.setdefault("log", []).append(f"Saved: {path}")
|
||||
job.setdefault("log", []).append("Download completed.")
|
||||
|
||||
+121
-2
@@ -779,6 +779,36 @@ class QueueApiTests(unittest.TestCase):
|
||||
)
|
||||
self.assertTrue(Path(moved[0]).exists())
|
||||
|
||||
def test_tv_finalizer_uses_requested_episode_numbers_for_animdl_fallback(self):
|
||||
with tempfile.TemporaryDirectory() as temp_root:
|
||||
job = APP.app_support.build_job(
|
||||
{
|
||||
"query": "Fallback Show",
|
||||
"title": "Fallback Show",
|
||||
"anime_name": "Fallback Show",
|
||||
"media_type": "tv",
|
||||
"mode": "sub",
|
||||
"quality": "best",
|
||||
"episodes": "12",
|
||||
"download_dir": temp_root,
|
||||
"season": "2",
|
||||
},
|
||||
{"mode": "sub", "quality": "best", "download_dir": temp_root},
|
||||
)
|
||||
job["download_backend"] = "animdl"
|
||||
staging_dir = APP.app_support.job_staging_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
source = staging_dir / "Fallback Show - S02E01.mp4"
|
||||
source.write_bytes(b"fallback")
|
||||
|
||||
moved = APP.app_support.finalize_library_files(job)
|
||||
|
||||
self.assertEqual(
|
||||
moved,
|
||||
[f"{temp_root}/tv/Fallback Show/Season 02/Fallback Show - S02E12.mp4"],
|
||||
)
|
||||
self.assertTrue(Path(moved[0]).exists())
|
||||
|
||||
def test_shutdown_wait_cancels_active_process_for_deterministic_teardown(self):
|
||||
queue = object.__new__(APP.DownloadQueue)
|
||||
queue.lock = threading.RLock()
|
||||
@@ -1006,6 +1036,51 @@ class DownloadQueueWorkerFailureTests(unittest.TestCase):
|
||||
self.assertEqual(commands[1][0], APP.app_support.ANIPY_CLI)
|
||||
self.assertIn("Fallback download completed with anipy-cli.", stored["log"])
|
||||
|
||||
def test_selected_download_methods_retry_through_animdl(self):
|
||||
queue = APP.DownloadQueue(
|
||||
lambda: {
|
||||
"mode": "sub",
|
||||
"quality": "best",
|
||||
"download_dir": "/tmp/example",
|
||||
"download_methods": ["ani-cli", "anipy-cli", "animdl"],
|
||||
},
|
||||
start_worker=False,
|
||||
)
|
||||
job = queue.add({"query": "Queue Show", "title": "Queue Show", "season": "1", "episodes": "1"})
|
||||
commands = []
|
||||
|
||||
class FakeProc:
|
||||
def __init__(self, pid, stdout, exit_code):
|
||||
self.pid = pid
|
||||
self.stdout = stdout
|
||||
self._exit_code = exit_code
|
||||
|
||||
def wait(self):
|
||||
return self._exit_code
|
||||
|
||||
processes = [
|
||||
FakeProc(4321, ["ani-cli attempt\n"], 1),
|
||||
FakeProc(5432, ["anipy-cli attempt\n"], 1),
|
||||
FakeProc(6543, ["animdl attempt\n"], 0),
|
||||
]
|
||||
|
||||
def fake_popen(command, **kwargs):
|
||||
commands.append(command)
|
||||
return processes.pop(0)
|
||||
|
||||
with mock.patch.object(queue_jobs, "cli_executable_exists", return_value=True), mock.patch.object(
|
||||
queue_jobs.subprocess, "Popen", side_effect=fake_popen
|
||||
), mock.patch.object(
|
||||
queue_jobs, "finalize_library_files", return_value=["/tmp/example/Queue Show - S01E01.mp4"]
|
||||
):
|
||||
queue._run_job(job)
|
||||
|
||||
stored = queue._find(job["id"])
|
||||
self.assertEqual(stored["status"], "done")
|
||||
self.assertTrue(stored["fallback_used"])
|
||||
self.assertEqual([command[0] for command in commands], [APP.app_support.ANI_CLI, APP.app_support.ANIPY_CLI, APP.app_support.ANIMDL])
|
||||
self.assertIn("Fallback download completed with animdl.", stored["log"])
|
||||
|
||||
|
||||
class WatchlistRefreshAllTests(unittest.TestCase):
|
||||
def test_refresh_all_iterates_only_watching_and_planned_show_ids(self):
|
||||
@@ -1849,6 +1924,25 @@ class WatchlistCompletionTests(unittest.TestCase):
|
||||
self.assertIn("-l", command)
|
||||
self.assertEqual(command[-1], "/tmp/anipy-staging")
|
||||
|
||||
def test_command_for_job_builds_animdl_download_command(self):
|
||||
command = APP.app_support.command_for_job(
|
||||
{
|
||||
"query": "Re:Zero",
|
||||
"quality": "720",
|
||||
"episodes": "1-3",
|
||||
"mode": "dub",
|
||||
},
|
||||
backend="animdl",
|
||||
download_path="/tmp/animdl-staging",
|
||||
)
|
||||
|
||||
self.assertEqual(command[0], APP.app_support.ANIMDL)
|
||||
self.assertEqual(command[1:4], ["download", "Re:Zero", "-r"])
|
||||
self.assertIn("-q", command)
|
||||
self.assertIn("--index", command)
|
||||
self.assertIn("-d", command)
|
||||
self.assertEqual(command[-1], "/tmp/animdl-staging")
|
||||
|
||||
def test_download_watchlist_item_queues_full_episode_range_for_selected_mode(self):
|
||||
item = {
|
||||
"show_id": "show-42",
|
||||
@@ -2330,6 +2424,7 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
self.assertEqual(config["watchlist_auto_refresh_minutes"], 60)
|
||||
self.assertEqual(config["watchlist_refresh_delay_seconds"], 5)
|
||||
self.assertFalse(config["anipy_cli_fallback_enabled"])
|
||||
self.assertEqual(config["download_methods"], ["ani-cli"])
|
||||
self.assertFalse(config["auto_download_enabled"])
|
||||
self.assertEqual(config["auto_download_mode"], "dub")
|
||||
self.assertEqual(config["auto_download_quality"], "best")
|
||||
@@ -2355,6 +2450,7 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
self.assertTrue(config["anipy_cli_fallback_enabled"])
|
||||
self.assertEqual(config["download_methods"], ["ani-cli", "anipy-cli"])
|
||||
self.assertTrue(config["watchlist_auto_refresh_enabled"])
|
||||
self.assertEqual(config["watchlist_auto_refresh_minutes"], 15)
|
||||
self.assertEqual(config["watchlist_refresh_delay_seconds"], 7)
|
||||
@@ -2365,6 +2461,16 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
self.assertIn("jellyfin", config["jellyfin_tv_dir"])
|
||||
self.assertIn("jellyfin", config["jellyfin_movie_dir"])
|
||||
|
||||
def test_normalize_config_filters_download_methods(self):
|
||||
config = APP.normalize_config(
|
||||
{
|
||||
"download_methods": ["animdl", "bad-method", "anipy-cli", "animdl"],
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(config["download_methods"], ["animdl", "anipy-cli"])
|
||||
self.assertTrue(config["anipy_cli_fallback_enabled"])
|
||||
|
||||
def test_normalize_config_filters_discord_webhook_events(self):
|
||||
config = APP.normalize_config(
|
||||
{
|
||||
@@ -2952,6 +3058,7 @@ class HandlerRouteTests(unittest.TestCase):
|
||||
APP.Handler.do_POST(handler)
|
||||
self.assertEqual(handler.json_status, HTTPStatus.OK)
|
||||
self.assertTrue(handler.json_payload["anipy_cli_fallback_enabled"])
|
||||
self.assertEqual(handler.json_payload["download_methods"], ["ani-cli", "anipy-cli"])
|
||||
self.assertTrue(handler.json_payload["watchlist_auto_refresh_enabled"])
|
||||
self.assertEqual(handler.json_payload["watchlist_auto_refresh_minutes"], 25)
|
||||
self.assertEqual(handler.json_payload["watchlist_refresh_delay_seconds"], 9)
|
||||
@@ -2962,6 +3069,14 @@ class HandlerRouteTests(unittest.TestCase):
|
||||
self.assertEqual(handler.json_payload["jellyfin_tv_dir"], "/tmp/jellyfin-tv")
|
||||
self.assertEqual(handler.json_payload["jellyfin_movie_dir"], "/tmp/jellyfin-movies")
|
||||
|
||||
def test_config_post_accepts_download_methods(self):
|
||||
body = b'{"download_dir":"/tmp/example","mode":"sub","quality":"best","download_methods":["ani-cli","animdl"]}'
|
||||
handler = DummyHandler("/api/config", body=body, content_length=len(body))
|
||||
APP.Handler.do_POST(handler)
|
||||
self.assertEqual(handler.json_status, HTTPStatus.OK)
|
||||
self.assertEqual(handler.json_payload["download_methods"], ["ani-cli", "animdl"])
|
||||
self.assertTrue(handler.json_payload["anipy_cli_fallback_enabled"])
|
||||
|
||||
def test_version_route_includes_cli_versions(self):
|
||||
handler = DummyHandler("/api/version")
|
||||
APP.Handler.do_GET(handler)
|
||||
@@ -2970,12 +3085,14 @@ class HandlerRouteTests(unittest.TestCase):
|
||||
self.assertEqual(handler.json_payload["version"], APP.VERSION)
|
||||
self.assertIn("ani_cli_version", handler.json_payload)
|
||||
self.assertIn("anipy_cli_version", handler.json_payload)
|
||||
self.assertIn("animdl_version", handler.json_payload)
|
||||
|
||||
def test_dependencies_route_reports_anipy_cli_status(self):
|
||||
def test_dependencies_route_reports_fallback_tool_status(self):
|
||||
handler = DummyHandler("/api/dependencies")
|
||||
APP.Handler.do_GET(handler)
|
||||
self.assertEqual(handler.json_status, HTTPStatus.OK)
|
||||
self.assertIn("anipy-cli", handler.json_payload)
|
||||
self.assertIn("animdl", handler.json_payload)
|
||||
|
||||
def test_clear_failed_route_removes_failed_jobs(self):
|
||||
with APP.DOWNLOAD_QUEUE._connect() as conn:
|
||||
@@ -3542,9 +3659,11 @@ class TemplateHelperTests(unittest.TestCase):
|
||||
self.assertIn("justify-items: stretch;", APP.CONFIG_HTML)
|
||||
self.assertIn('id="aniCliVersionLine"', APP.CONFIG_HTML)
|
||||
self.assertIn('id="anipyCliVersionLine"', APP.CONFIG_HTML)
|
||||
self.assertIn('id="animdlVersionLine"', APP.CONFIG_HTML)
|
||||
self.assertIn('ani-cli ${data.ani_cli_version || "Unavailable"}', APP.CONFIG_HTML)
|
||||
self.assertIn('anipy-cli ${data.anipy_cli_version || "Unavailable"}', APP.CONFIG_HTML)
|
||||
self.assertIn('id="anipyCliFallbackEnabled"', APP.CONFIG_HTML)
|
||||
self.assertIn('animdl ${data.animdl_version || "Unavailable"}', APP.CONFIG_HTML)
|
||||
self.assertIn('class="download-method" type="checkbox" value="animdl"', APP.CONFIG_HTML)
|
||||
self.assertIn('id="openChangelogBtn"', APP.CONFIG_HTML)
|
||||
self.assertIn('id="changelogOverlay"', APP.CONFIG_HTML)
|
||||
self.assertIn('const data = await api("/api/changelog");', APP.CONFIG_HTML)
|
||||
|
||||
Reference in New Issue
Block a user