Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dd56b72f6 |
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 0.46.1 - 2026-07-09
|
||||
|
||||
- Added a Config-page backup download toggle that lets queue jobs retry failed `ani-cli` downloads automatically with `anikoto-cli`.
|
||||
- Installed `anikoto-cli` system-wide in the container image alongside `ani-cli`, and added the extra `jq` and `mpv` packages it currently needs even for download-only runs.
|
||||
- Exposed `anikoto-cli` in Runtime info and dependency checks so it is easier to verify that the backup downloader is available.
|
||||
|
||||
## 0.46.0 - 2026-06-14
|
||||
|
||||
- Changed manual Jellyfin handoff to run as a persisted background job instead of a single blocking request, so the Config page can show live progress while files are being moved.
|
||||
|
||||
+11
@@ -2,14 +2,19 @@ FROM python:3.12-slim
|
||||
|
||||
ARG ANI_CLI=https://github.com/pystardust/ani-cli.git
|
||||
ARG ANI_CLI_BRANCH=master
|
||||
ARG ANIKOTO_CLI=https://github.com/Slimyslushy/anikoto-cli.git
|
||||
ARG ANIKOTO_CLI_BRANCH=main
|
||||
ARG ANI_CLI_WEB=https://gitea.coreplay.eu/Dymas/ani-cli-web.git
|
||||
ARG YT_DLP_RELEASE_URL=https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
ANI_CLI_REPO=${ANI_CLI} \
|
||||
ANI_CLI_BRANCH=${ANI_CLI_BRANCH} \
|
||||
ANIKOTO_CLI_REPO=${ANIKOTO_CLI} \
|
||||
ANIKOTO_CLI_BRANCH=${ANIKOTO_CLI_BRANCH} \
|
||||
ANI_CLI_WEB_REPO=${ANI_CLI_WEB} \
|
||||
ANI_CLI_BIN=ani-cli \
|
||||
ANIKOTO_CLI_BIN=anikoto-cli \
|
||||
ANI_CLI_DOWNLOAD_DIR=/downloads \
|
||||
ANI_CLI_WEB_HOST=0.0.0.0 \
|
||||
ANI_CLI_WEB_PORT=8421 \
|
||||
@@ -26,6 +31,8 @@ RUN apt-get update \
|
||||
fzf \
|
||||
git \
|
||||
grep \
|
||||
jq \
|
||||
mpv \
|
||||
openssl \
|
||||
patch \
|
||||
sed \
|
||||
@@ -42,6 +49,10 @@ RUN git clone --depth 1 --branch "${ANI_CLI_BRANCH}" "${ANI_CLI}" /tmp/ani-cli-s
|
||||
esac \
|
||||
&& rm -rf /tmp/ani-cli-src
|
||||
|
||||
RUN git clone --depth 1 --branch "${ANIKOTO_CLI_BRANCH}" "${ANIKOTO_CLI}" /tmp/anikoto-cli-src \
|
||||
&& install -m 0755 /tmp/anikoto-cli-src/anikoto-cli /usr/local/bin/anikoto-cli \
|
||||
&& rm -rf /tmp/anikoto-cli-src
|
||||
|
||||
RUN curl -fL "${YT_DLP_RELEASE_URL}" -o /usr/local/bin/yt-dlp \
|
||||
&& chmod 0755 /usr/local/bin/yt-dlp \
|
||||
&& yt-dlp --version
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
Local web UI for a system-wide `ani-cli` install.
|
||||
|
||||
Current version: `0.46.0`
|
||||
Current version: `0.46.1`
|
||||
|
||||
## 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 system-wide `anikoto-cli` as a backup downloader
|
||||
- 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
|
||||
@@ -27,7 +28,8 @@ Current version: `0.46.0`
|
||||
Requirements:
|
||||
|
||||
- `ani-cli` installed and available in `PATH`
|
||||
- Common runtime tools used by `ani-cli`, especially `curl`, `ffmpeg`, `fzf`, `grep`, `openssl`, `sed`, `aria2c`, and `yt-dlp`
|
||||
- Optional: `anikoto-cli` installed in `PATH` if you want backup downloads
|
||||
- Common runtime tools used by `ani-cli` and `anikoto-cli`, especially `curl`, `ffmpeg`, `fzf`, `grep`, `jq`, `mpv`, `openssl`, `sed`, `aria2c`, and `yt-dlp`
|
||||
|
||||
Run locally:
|
||||
|
||||
@@ -81,6 +83,7 @@ Docker notes:
|
||||
- App state is stored under `/app/.ani-cli-web`
|
||||
- `USER_UID` and `USER_GID` help keep mounted files owned by your host user
|
||||
- `UPDATE_ON_START=true` runs `ani-cli --update` before startup
|
||||
- The image installs both `ani-cli` and `anikoto-cli` system-wide under `/usr/local/bin`
|
||||
|
||||
## Key behavior
|
||||
|
||||
@@ -99,6 +102,12 @@ Docker notes:
|
||||
- Uses the per-show language, quality, `Source name` search override, season, library name, and optional episode offset settings
|
||||
- Can queue backlog episodes that were already available before the show was first tracked
|
||||
|
||||
### Backup downloads
|
||||
|
||||
- Configure the global backup toggle from `/config`
|
||||
- When enabled, any failed `ani-cli` queue job automatically retries with `anikoto-cli`
|
||||
- `anikoto-cli` ignores the saved quality setting, so backup attempts use the source's default stream quality
|
||||
|
||||
### Jellyfin handoff
|
||||
|
||||
- Optional and configured from `/config`
|
||||
@@ -182,6 +191,7 @@ ANI_CLI_DOWNLOAD_DIR/movie/Movie Name/Movie Name.mp4
|
||||
Most users only need these environment variables:
|
||||
|
||||
- `ANI_CLI_BIN`
|
||||
- `ANIKOTO_CLI_BIN`
|
||||
- `ANI_CLI_WEB_HOST`
|
||||
- `ANI_CLI_WEB_PORT`
|
||||
- `ANI_CLI_WEB_ALLOW_REMOTE`
|
||||
|
||||
+23
-1
@@ -23,6 +23,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"
|
||||
ANIKOTO_CLI = os.environ.get("ANIKOTO_CLI_BIN") or shutil.which("anikoto-cli") or "anikoto-cli"
|
||||
APP_NAME = "ani-cli-web"
|
||||
VERSION_FILE = PROJECT_ROOT / "VERSION"
|
||||
CHANGELOG_FILE = PROJECT_ROOT / "CHANGELOG.md"
|
||||
@@ -290,6 +291,7 @@ DEFAULT_CONFIG = {
|
||||
"download_dir": default_download_dir(),
|
||||
"mode": os.environ.get("ANI_CLI_MODE", "sub"),
|
||||
"quality": os.environ.get("ANI_CLI_QUALITY", "best"),
|
||||
"download_backup_enabled": False,
|
||||
"watchlist_auto_refresh_enabled": False,
|
||||
"watchlist_auto_refresh_minutes": WATCHLIST_AUTO_REFRESH_DEFAULT_MINUTES,
|
||||
"watchlist_refresh_delay_seconds": WATCHLIST_REFRESH_DELAY_DEFAULT_SECONDS,
|
||||
@@ -448,6 +450,7 @@ def normalize_config(data):
|
||||
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")
|
||||
download_backup_enabled = config.get("download_backup_enabled")
|
||||
auto_download_enabled = config.get("auto_download_enabled")
|
||||
auto_download_mode = str(config.get("auto_download_mode", "dub")).lower()
|
||||
auto_download_quality = str(config.get("auto_download_quality", "best")).lower()
|
||||
@@ -469,6 +472,10 @@ def normalize_config(data):
|
||||
auto_download_enabled = auto_download_enabled.strip().lower() in {"1", "true", "yes", "on"}
|
||||
else:
|
||||
auto_download_enabled = bool(auto_download_enabled)
|
||||
if isinstance(download_backup_enabled, str):
|
||||
download_backup_enabled = download_backup_enabled.strip().lower() in {"1", "true", "yes", "on"}
|
||||
else:
|
||||
download_backup_enabled = bool(download_backup_enabled)
|
||||
if isinstance(jellyfin_sync_enabled, str):
|
||||
jellyfin_sync_enabled = jellyfin_sync_enabled.strip().lower() in {"1", "true", "yes", "on"}
|
||||
else:
|
||||
@@ -494,6 +501,7 @@ 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["download_backup_enabled"] = download_backup_enabled
|
||||
config["watchlist_auto_refresh_enabled"] = auto_refresh_enabled
|
||||
config["watchlist_auto_refresh_minutes"] = auto_refresh_minutes
|
||||
config["watchlist_refresh_delay_seconds"] = refresh_delay_seconds
|
||||
@@ -1153,7 +1161,21 @@ def build_job(payload, config):
|
||||
}
|
||||
|
||||
|
||||
def command_for_job(job):
|
||||
def command_for_job(job, downloader="ani-cli"):
|
||||
if str(downloader or "ani-cli").strip().lower() == "anikoto-cli":
|
||||
command = [
|
||||
ANIKOTO_CLI,
|
||||
"-d",
|
||||
"-e",
|
||||
job["episodes"],
|
||||
]
|
||||
if job["mode"] == "dub":
|
||||
command.append("--dub")
|
||||
else:
|
||||
command.append("--sub")
|
||||
command.append(job["query"])
|
||||
return command
|
||||
|
||||
command = [
|
||||
ANI_CLI,
|
||||
"-d",
|
||||
|
||||
+12
-1
@@ -461,6 +461,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
<div class="stack muted">
|
||||
<p id="versionLine">Loading version...</p>
|
||||
<p id="aniCliVersionLine">Detecting ani-cli version...</p>
|
||||
<p id="anikotoCliVersionLine">Detecting anikoto-cli version...</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>
|
||||
@@ -502,8 +503,14 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
<option value="480">480p</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>Backup downloader
|
||||
<select id="downloadBackupEnabled">
|
||||
<option value="false">Disabled</option>
|
||||
<option value="true">Enabled</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="field-hint">Tip: these are the saved defaults only. The active search form can still be adjusted per download.</div>
|
||||
<div class="field-hint">Tip: these are the saved defaults only. The active search form can still be adjusted per download. When backup downloads are enabled, failed `ani-cli` jobs retry automatically with `anikoto-cli`.</div>
|
||||
</section>
|
||||
|
||||
<section class="settings settings-main">
|
||||
@@ -666,6 +673,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
mode: "sub",
|
||||
quality: "best",
|
||||
download_dir: "",
|
||||
download_backup_enabled: false,
|
||||
watchlist_auto_refresh_enabled: false,
|
||||
watchlist_auto_refresh_minutes: 60,
|
||||
watchlist_refresh_delay_seconds: 5,
|
||||
@@ -732,6 +740,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
download_dir: $("downloadDir").value,
|
||||
mode: $("configMode").value,
|
||||
quality: $("configQuality").value,
|
||||
download_backup_enabled: $("downloadBackupEnabled").value === "true",
|
||||
watchlist_auto_refresh_enabled: $("watchlistAutoRefreshEnabled").value === "true",
|
||||
watchlist_auto_refresh_minutes: $("watchlistAutoRefreshMinutes").value,
|
||||
watchlist_refresh_delay_seconds: $("watchlistRefreshDelaySeconds").value,
|
||||
@@ -751,6 +760,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
$("downloadDir").value = data.download_dir;
|
||||
$("configMode").value = data.mode;
|
||||
$("configQuality").value = data.quality;
|
||||
$("downloadBackupEnabled").value = String(Boolean(data.download_backup_enabled));
|
||||
$("watchlistAutoRefreshEnabled").value = String(Boolean(data.watchlist_auto_refresh_enabled));
|
||||
$("watchlistAutoRefreshMinutes").value = data.watchlist_auto_refresh_minutes;
|
||||
$("watchlistRefreshDelaySeconds").value = data.watchlist_refresh_delay_seconds;
|
||||
@@ -960,6 +970,7 @@ CONFIG_HTML = r"""<!doctype html>
|
||||
const data = await api("/api/version");
|
||||
$("versionLine").textContent = `${data.name} ${data.version}`;
|
||||
$("aniCliVersionLine").textContent = `ani-cli ${data.ani_cli_version || "Unavailable"}`;
|
||||
$("anikotoCliVersionLine").textContent = `anikoto-cli ${data.anikoto_cli_version || "Unavailable"}`;
|
||||
}
|
||||
|
||||
async function openChangelog() {
|
||||
|
||||
@@ -6,6 +6,8 @@ services:
|
||||
args:
|
||||
ANI_CLI: ${ANI_CLI:-https://github.com/pystardust/ani-cli.git}
|
||||
ANI_CLI_BRANCH: ${ANI_CLI_BRANCH:-master}
|
||||
ANIKOTO_CLI: ${ANIKOTO_CLI:-https://github.com/Slimyslushy/anikoto-cli.git}
|
||||
ANIKOTO_CLI_BRANCH: ${ANIKOTO_CLI_BRANCH:-main}
|
||||
ANI_CLI_WEB: ${ANI_CLI_WEB:-https://gitea.coreplay.eu/Dymas/ani-cli-web.git}
|
||||
image: ani-cli-web:latest
|
||||
container_name: ani-cli-web
|
||||
|
||||
+27
-2
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
from urllib.parse import parse_qs, unquote, urlencode, urlparse, urlunparse
|
||||
|
||||
from app_support import (
|
||||
ANIKOTO_CLI,
|
||||
ANI_CLI,
|
||||
APP_NAME,
|
||||
CHANGELOG_FILE,
|
||||
@@ -85,9 +86,10 @@ def build_handler_class(context):
|
||||
|
||||
|
||||
def dependency_status():
|
||||
checks = ["curl", "sed", "grep", "openssl", "fzf", "aria2c", "ffmpeg", "yt-dlp"]
|
||||
checks = ["curl", "sed", "grep", "openssl", "fzf", "aria2c", "ffmpeg", "yt-dlp", "jq", "mpv"]
|
||||
result = {name: bool(shutil.which(name)) for name in checks}
|
||||
result["ani-cli"] = bool(shutil.which(ANI_CLI) or (Path(ANI_CLI).exists() and os.access(ANI_CLI, os.X_OK)))
|
||||
result["anikoto-cli"] = bool(shutil.which(ANIKOTO_CLI) or (Path(ANIKOTO_CLI).exists() and os.access(ANIKOTO_CLI, os.X_OK)))
|
||||
return result
|
||||
|
||||
|
||||
@@ -166,6 +168,22 @@ def installed_ani_cli_version():
|
||||
return version or "Unavailable"
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def installed_anikoto_cli_version():
|
||||
try:
|
||||
completed = subprocess.run(
|
||||
[ANIKOTO_CLI, "--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"
|
||||
@@ -535,7 +553,14 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif parsed.path == "/api/config":
|
||||
self.json(sanitize_public_config(Handler._context(self).get_config_snapshot()))
|
||||
elif parsed.path == "/api/version":
|
||||
self.json({"name": APP_NAME, "version": VERSION, "ani_cli_version": installed_ani_cli_version()})
|
||||
self.json(
|
||||
{
|
||||
"name": APP_NAME,
|
||||
"version": VERSION,
|
||||
"ani_cli_version": installed_ani_cli_version(),
|
||||
"anikoto_cli_version": installed_anikoto_cli_version(),
|
||||
}
|
||||
)
|
||||
elif parsed.path == "/api/changelog":
|
||||
self.json({"content": load_project_text_file(CHANGELOG_FILE, default="Changelog unavailable.")})
|
||||
elif parsed.path == "/api/dependencies":
|
||||
|
||||
+111
-54
@@ -13,6 +13,7 @@ import time
|
||||
import re
|
||||
|
||||
from app_support import (
|
||||
ANIKOTO_CLI,
|
||||
MAX_LOG_LINES,
|
||||
PROJECT_ROOT,
|
||||
QUEUE_PATH,
|
||||
@@ -1335,6 +1336,16 @@ class DownloadQueue:
|
||||
debug_log("queue.cleanup.staging_failed", job_id=job.get("id"), staging_dir=staging_dir, error=exc)
|
||||
return False
|
||||
|
||||
def _command_available(self, command_name):
|
||||
return bool(shutil.which(command_name) or (os.path.exists(command_name) and os.access(command_name, os.X_OK)))
|
||||
|
||||
def _download_attempts(self):
|
||||
config = normalize_config(self.config_getter() or {})
|
||||
attempts = [("ani-cli", command_for_job)]
|
||||
if config.get("download_backup_enabled"):
|
||||
attempts.append(("anikoto-cli", lambda job: command_for_job(job, downloader="anikoto-cli")))
|
||||
return attempts
|
||||
|
||||
def _fail_job_startup(self, job, exc):
|
||||
message = f"Could not start download: {exc}"
|
||||
with self.lock:
|
||||
@@ -1383,7 +1394,6 @@ class DownloadQueue:
|
||||
self._run_job(job)
|
||||
|
||||
def _run_job(self, job):
|
||||
command = command_for_job(job)
|
||||
staging_dir = job_staging_dir(job)
|
||||
target_dir = job_output_dir(job)
|
||||
env = os.environ.copy()
|
||||
@@ -1397,12 +1407,14 @@ class DownloadQueue:
|
||||
)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
attempts = self._download_attempts()
|
||||
primary_command = attempts[0][1](job)
|
||||
|
||||
with self.lock:
|
||||
job["status"] = "running"
|
||||
job["started_at"] = now_iso()
|
||||
job["updated_at"] = job["started_at"]
|
||||
job["command"] = printable_command(command)
|
||||
job["command"] = printable_command(primary_command)
|
||||
job["staging_dir"] = str(staging_dir)
|
||||
job["target_dir"] = str(target_dir)
|
||||
job["log"] = [
|
||||
@@ -1410,73 +1422,117 @@ class DownloadQueue:
|
||||
f"Staging in: {job['staging_dir']}",
|
||||
f"Final folder: {job['target_dir']}",
|
||||
]
|
||||
if len(attempts) > 1:
|
||||
job["log"].append("Backup downloads are enabled. Failed ani-cli jobs will retry with anikoto-cli.")
|
||||
job["cancel_requested"] = False
|
||||
job["_dirty_log_lines"] = 0
|
||||
self._save_job_locked(job)
|
||||
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
command,
|
||||
cwd=str(PROJECT_ROOT),
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
start_new_session=True,
|
||||
)
|
||||
except Exception as exc:
|
||||
self._fail_job_startup(job, exc)
|
||||
return
|
||||
with self.lock:
|
||||
self.current_process = process
|
||||
self.current_job_id = job["id"]
|
||||
self.current_job = job
|
||||
job["pid"] = process.pid
|
||||
self._save_job_locked(job)
|
||||
|
||||
try:
|
||||
assert process.stdout is not None
|
||||
for line in process.stdout:
|
||||
self._append_log(job, line)
|
||||
exit_code = process.wait()
|
||||
finalize_error = None
|
||||
last_exit_code = 1
|
||||
last_finalize_error = None
|
||||
moved_files = []
|
||||
watchlist_sync_error = None
|
||||
synced_watchlist_item = None
|
||||
cleanup_staging = False
|
||||
if exit_code == 0 and not job.get("cancel_requested"):
|
||||
canceled = False
|
||||
download_succeeded = False
|
||||
|
||||
for attempt_index, (downloader_name, command_builder) in enumerate(attempts):
|
||||
command = command_builder(job)
|
||||
if attempt_index > 0:
|
||||
self._cleanup_staging_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
self._append_log(job, f"Retrying with backup downloader: {downloader_name}.")
|
||||
self._append_log(job, "anikoto-cli does not support ani-cli quality flags, so the saved quality preference is ignored for the backup attempt.")
|
||||
if downloader_name == "anikoto-cli" and not self._command_available(ANIKOTO_CLI):
|
||||
self._append_log(job, "Backup downloader anikoto-cli is not installed or not executable.")
|
||||
continue
|
||||
|
||||
with self.lock:
|
||||
job["command"] = printable_command(command)
|
||||
job["updated_at"] = now_iso()
|
||||
self._save_job_locked(job)
|
||||
self._append_log(job, f"Launching {downloader_name}: {job['command']}")
|
||||
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
command,
|
||||
cwd=str(PROJECT_ROOT),
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
start_new_session=True,
|
||||
)
|
||||
except Exception as exc:
|
||||
last_exit_code = 1
|
||||
last_finalize_error = None
|
||||
self._append_log(job, f"Could not start {downloader_name}: {exc}")
|
||||
continue
|
||||
with self.lock:
|
||||
self.current_process = process
|
||||
self.current_job_id = job["id"]
|
||||
self.current_job = job
|
||||
job["pid"] = process.pid
|
||||
self._save_job_locked(job)
|
||||
|
||||
assert process.stdout is not None
|
||||
for line in process.stdout:
|
||||
self._append_log(job, line)
|
||||
exit_code = process.wait()
|
||||
with self.lock:
|
||||
job["pid"] = None
|
||||
self.current_process = None
|
||||
self.current_job_id = None
|
||||
self.current_job = None
|
||||
self._save_job_locked(job)
|
||||
canceled = bool(job.get("cancel_requested"))
|
||||
if canceled:
|
||||
last_exit_code = exit_code
|
||||
break
|
||||
if exit_code != 0:
|
||||
last_exit_code = exit_code
|
||||
last_finalize_error = None
|
||||
self._append_log(job, f"{downloader_name} failed with exit code {exit_code}.")
|
||||
continue
|
||||
|
||||
try:
|
||||
moved_files = finalize_library_files(job)
|
||||
except Exception as exc:
|
||||
finalize_error = exc
|
||||
else:
|
||||
if self.watchlist_sync_fn is not None:
|
||||
try:
|
||||
synced_watchlist_item = self.watchlist_sync_fn(job)
|
||||
except Exception as exc:
|
||||
watchlist_sync_error = exc
|
||||
last_exit_code = 1
|
||||
last_finalize_error = exc
|
||||
message = str(exc).strip()
|
||||
if "No downloaded files were found in the staging folder" in message:
|
||||
self._append_log(
|
||||
job,
|
||||
f"{downloader_name} exited without downloading any files. The selected result or episodes may not be downloadable.",
|
||||
)
|
||||
else:
|
||||
self._append_log(job, f"Library rename failed after {downloader_name}: {exc}")
|
||||
continue
|
||||
|
||||
download_succeeded = True
|
||||
last_exit_code = 0
|
||||
last_finalize_error = None
|
||||
if self.watchlist_sync_fn is not None:
|
||||
try:
|
||||
synced_watchlist_item = self.watchlist_sync_fn(job)
|
||||
except Exception as exc:
|
||||
watchlist_sync_error = exc
|
||||
break
|
||||
|
||||
with self.lock:
|
||||
canceled = job.get("cancel_requested")
|
||||
job["exit_code"] = 1 if finalize_error else exit_code
|
||||
job["exit_code"] = last_exit_code
|
||||
job["pid"] = None
|
||||
job["finished_at"] = now_iso()
|
||||
job["updated_at"] = job["finished_at"]
|
||||
cleanup_staging = False
|
||||
if canceled:
|
||||
job["status"] = "canceled"
|
||||
job.setdefault("log", []).append("Canceled.")
|
||||
elif finalize_error:
|
||||
job["status"] = "failed"
|
||||
message = str(finalize_error).strip()
|
||||
if "No downloaded files were found in the staging folder" in message:
|
||||
job.setdefault("log", []).append(
|
||||
"ani-cli exited without downloading any files. The selected result or episodes may not be downloadable."
|
||||
)
|
||||
else:
|
||||
job.setdefault("log", []).append(f"Library rename failed: {finalize_error}")
|
||||
cleanup_staging = True
|
||||
elif exit_code == 0:
|
||||
elif download_succeeded:
|
||||
job["status"] = "done"
|
||||
for path in moved_files:
|
||||
job.setdefault("log", []).append(f"Saved: {path}")
|
||||
@@ -1490,9 +1546,10 @@ class DownloadQueue:
|
||||
job.setdefault("log", []).append("Watchlist download state synced.")
|
||||
else:
|
||||
job["status"] = "failed"
|
||||
job.setdefault("log", []).append(f"Download failed with exit code {exit_code}.")
|
||||
cleanup_staging = True
|
||||
if canceled:
|
||||
if last_finalize_error and "No downloaded files were found in the staging folder" not in str(last_finalize_error):
|
||||
job.setdefault("log", []).append(f"Download failed after all downloaders were tried: {last_finalize_error}")
|
||||
else:
|
||||
job.setdefault("log", []).append("Download failed after all configured downloaders were tried.")
|
||||
cleanup_staging = True
|
||||
self.current_process = None
|
||||
self.current_job_id = None
|
||||
@@ -1500,7 +1557,7 @@ class DownloadQueue:
|
||||
self._save_job_locked(job)
|
||||
if cleanup_staging:
|
||||
self._cleanup_staging_dir(job)
|
||||
elif exit_code == 0 and not finalize_error and not canceled:
|
||||
elif download_succeeded:
|
||||
download_title = (
|
||||
str((synced_watchlist_item or {}).get("title") or "").strip()
|
||||
or str(job.get("title") or "").strip()
|
||||
@@ -1524,4 +1581,4 @@ class DownloadQueue:
|
||||
except Exception as exc:
|
||||
debug_log("discord_webhook.download_completed_failed", title=download_title, error=exc)
|
||||
except Exception as exc:
|
||||
self._fail_job_runtime(job, exc, process=process)
|
||||
self._fail_job_runtime(job, exc)
|
||||
|
||||
+63
-1
@@ -624,7 +624,7 @@ class DownloadQueueWorkerFailureTests(unittest.TestCase):
|
||||
stored = queue._find(job["id"])
|
||||
self.assertEqual(stored["status"], "failed")
|
||||
self.assertEqual(stored["exit_code"], 1)
|
||||
self.assertIn("Could not start download", stored["log"][-1])
|
||||
self.assertIn("Could not start ani-cli", "\n".join(stored["log"]))
|
||||
self.assertFalse(staging_dir.exists())
|
||||
|
||||
def test_failed_download_cleans_staging_dir(self):
|
||||
@@ -669,6 +669,46 @@ class DownloadQueueWorkerFailureTests(unittest.TestCase):
|
||||
self.assertIn("without downloading any files", "\n".join(stored["log"]))
|
||||
self.assertFalse(staging_dir.exists())
|
||||
|
||||
def test_failed_ani_cli_retries_with_anikoto_backup(self):
|
||||
queue = APP.DownloadQueue(
|
||||
lambda: {
|
||||
"mode": "sub",
|
||||
"quality": "best",
|
||||
"download_dir": "/tmp/example",
|
||||
"download_backup_enabled": True,
|
||||
},
|
||||
start_worker=False,
|
||||
)
|
||||
job = queue.add({"query": "Queue Show", "title": "Queue Show", "season": "1", "episodes": "1"})
|
||||
|
||||
class FailedProc:
|
||||
pid = 1111
|
||||
stdout = []
|
||||
|
||||
def wait(self):
|
||||
return 1
|
||||
|
||||
class SuccessProc:
|
||||
pid = 2222
|
||||
stdout = []
|
||||
|
||||
def wait(self):
|
||||
return 0
|
||||
|
||||
with mock.patch.object(queue_jobs.subprocess, "Popen", side_effect=[FailedProc(), SuccessProc()]), mock.patch.object(
|
||||
queue, "_command_available", return_value=True
|
||||
), mock.patch.object(
|
||||
queue_jobs, "finalize_library_files", return_value=["/tmp/example/tv/Queue Show/Season 01/Queue Show - S01E01.mp4"]
|
||||
):
|
||||
queue._run_job(job)
|
||||
|
||||
stored = queue._find(job["id"])
|
||||
self.assertEqual(stored["status"], "done")
|
||||
log_text = "\n".join(stored["log"])
|
||||
self.assertIn("Retrying with backup downloader: anikoto-cli.", log_text)
|
||||
self.assertIn("anikoto-cli does not support ani-cli quality flags", log_text)
|
||||
self.assertIn("Download completed.", log_text)
|
||||
|
||||
def test_run_job_marks_post_start_exception_failed_without_killing_worker_state(self):
|
||||
queue = APP.DownloadQueue(lambda: {"mode": "sub", "quality": "best", "download_dir": "/tmp/example"}, start_worker=False)
|
||||
job = queue.add({"query": "Queue Show", "title": "Queue Show", "season": "1", "episodes": "1"})
|
||||
@@ -1597,6 +1637,22 @@ class WatchlistCompletionTests(unittest.TestCase):
|
||||
|
||||
self.assertNotIn("-S", command)
|
||||
|
||||
def test_command_for_job_builds_anikoto_backup_command_without_quality_flag(self):
|
||||
command = APP.app_support.command_for_job(
|
||||
{
|
||||
"query": "Queue Show",
|
||||
"quality": "best",
|
||||
"episodes": "1-10",
|
||||
"mode": "sub",
|
||||
},
|
||||
downloader="anikoto-cli",
|
||||
)
|
||||
|
||||
self.assertEqual(command[0], APP.app_support.ANIKOTO_CLI)
|
||||
self.assertIn("-d", command)
|
||||
self.assertIn("--sub", command)
|
||||
self.assertNotIn("-q", command)
|
||||
|
||||
def test_download_watchlist_item_queues_full_episode_range_for_selected_mode(self):
|
||||
item = {
|
||||
"show_id": "show-42",
|
||||
@@ -2074,6 +2130,7 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
|
||||
def test_normalize_config_includes_watchlist_schedule_defaults(self):
|
||||
config = APP.normalize_config({})
|
||||
self.assertFalse(config["download_backup_enabled"])
|
||||
self.assertFalse(config["watchlist_auto_refresh_enabled"])
|
||||
self.assertEqual(config["watchlist_auto_refresh_minutes"], 60)
|
||||
self.assertEqual(config["watchlist_refresh_delay_seconds"], 5)
|
||||
@@ -2089,6 +2146,7 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
def test_normalize_config_parses_watchlist_schedule_fields(self):
|
||||
config = APP.normalize_config(
|
||||
{
|
||||
"download_backup_enabled": "true",
|
||||
"watchlist_auto_refresh_enabled": "true",
|
||||
"watchlist_auto_refresh_minutes": "15",
|
||||
"watchlist_refresh_delay_seconds": "7",
|
||||
@@ -2100,6 +2158,7 @@ class ConfigSnapshotTests(unittest.TestCase):
|
||||
"jellyfin_movie_dir": "~/jellyfin/movies",
|
||||
}
|
||||
)
|
||||
self.assertTrue(config["download_backup_enabled"])
|
||||
self.assertTrue(config["watchlist_auto_refresh_enabled"])
|
||||
self.assertEqual(config["watchlist_auto_refresh_minutes"], 15)
|
||||
self.assertEqual(config["watchlist_refresh_delay_seconds"], 7)
|
||||
@@ -3244,7 +3303,10 @@ class TemplateHelperTests(unittest.TestCase):
|
||||
self.assertIn("@media (max-width: 1080px)", APP.CONFIG_HTML)
|
||||
self.assertIn("justify-items: stretch;", APP.CONFIG_HTML)
|
||||
self.assertIn('id="aniCliVersionLine"', APP.CONFIG_HTML)
|
||||
self.assertIn('id="anikotoCliVersionLine"', APP.CONFIG_HTML)
|
||||
self.assertIn('ani-cli ${data.ani_cli_version || "Unavailable"}', APP.CONFIG_HTML)
|
||||
self.assertIn('anikoto-cli ${data.anikoto_cli_version || "Unavailable"}', APP.CONFIG_HTML)
|
||||
self.assertIn('id="downloadBackupEnabled"', 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