Fix repository review findings and update provider dependencies
This commit is contained in:
1 parent
d97801bf9d
commit
fec17577e3
16 files changed
+354
-146
No files matched your search
@@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## 0.53.14 - 2026-10-12
|
||||
|
||||
- Fixed custom Docker host ports by keeping the application on container port 8421.
|
||||
- Excluded subtitles, metadata, and partial files from watchlist filesystem download detection, including movies.
|
||||
- Preserved fractional episode numbers in download filenames, corrected the default AES-128 HLS sequence/IV to zero, and rejected successful ffmpeg exits that produce no nonempty video.
|
||||
- Handled download folder/preparation errors without stopping the queue worker, and retained completed staging files when library finalization fails.
|
||||
- Kept Jellyfin video/subtitle names paired when either filename collides with existing files; rejected nested source/target folders before moving anything.
|
||||
- Bounded provider subprocess calls to 120 seconds by default and applied watchlist refresh timeouts to each metadata/episode call. Shared the subprocess bridge implementation with the downloader.
|
||||
- Indexed subtitle companions during finalization, removed a duplicate watchlist count query, unused helpers, and unused segment-directory creation/deletion.
|
||||
- Updated the transitive undici dependency from 6.28.0 to 6.29.0; npm audit reports zero known vulnerabilities.
|
||||
- Checked all three providers against upstream tree ae21244a5f3cabc58bd281fff0b3560cbfb7a0f8 and merged AnimePahe's same-version 5.0.6 UUID recovery change while retaining Kaizoku patches. Anikoto and AniNeko were current.
|
||||
|
||||
## 0.53.13 - 2026-10-07
|
||||
|
||||
- Fixed external subtitle requests to use the media downloader's cookies, HTTP fallback, retries, and provider/track headers. Failed English tracks now fall through to another English track, and unavailable tracks are logged instead of labeling an unrelated language as English.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# Repository review — 2026-10-12
|
||||
|
||||
Reviewed the Python application, HTTP routes, persistence and worker flows, inline browser scripts, provider bridge/adapters, dependency lockfile, Docker configuration, and regression suite. Fixes are included in release 0.53.14.
|
||||
|
||||
## Findings addressed
|
||||
|
||||
| Priority | Finding and consequence | Fix location |
|
||||
| --- | --- | --- |
|
||||
| High | Library finalization failures deleted remaining staged downloads, preventing manual recovery. | `queue_jobs.py`: retain staging after a failed library move. |
|
||||
| High | Fractional episodes such as 12.5 were named as episode 12, risking replacement or incorrect library numbering. | `provider_downloader.py`: preserve fractional numbers. |
|
||||
| High | Jellyfin could move a tree into a nested source/target, including files already in the destination. | `app.py`: reject overlapping resolved folders before moving files. |
|
||||
| High | The locked undici 6.28.0 had published advisories, including a high-severity denial of service. Exploitability through Kaizoku was not established. | `package-lock.json`: update to compatible 6.29.0; audit is clear. |
|
||||
| Medium | Folder creation and command preparation ran outside the download worker's exception handling, so a permission/path error could terminate the worker. | `queue_jobs.py`: persist a failed job and return to the worker loop. |
|
||||
| Medium | An exception before process creation could reference an uninitialized process variable and mask the original failure. | `queue_jobs.py`: initialize the process reference before handling runtime failures. |
|
||||
| Medium | Provider subprocesses had no overall timeout, and watchlist snapshot calls ignored their timeout argument. | `provider_bridge.py`, `provider_downloader.py`, `app.py`: share a bounded bridge and forward snapshot timeouts. |
|
||||
| Medium | ffmpeg returning zero without a nonempty output file was treated as a successful download. | `provider_downloader.py`: return failure for missing/empty outputs on direct and native paths. |
|
||||
| Medium | Encrypted HLS playlists without a media sequence started IV numbering at one rather than zero. | `provider_downloader.py`: start at zero, as required by [RFC 8216 §4.3.3.2](https://www.rfc-editor.org/rfc/rfc8216.html#section-4.3.3.2). |
|
||||
| Medium | Subtitle, metadata, and partial files could falsely mark episodes or movies downloaded. | `app.py`: restrict filesystem reconciliation to video suffixes. |
|
||||
| Medium | Jellyfin independently renamed colliding videos and subtitles, breaking their filename association. | `app.py`: reserve destination names for each video and its sidecars together. |
|
||||
| Medium | Setting KAIZOKU_PORT changed both the host mapping and application port, while the container mapping still targeted 8421. | `docker-compose.yaml`: keep the internal application port fixed at 8421. |
|
||||
|
||||
## Redundancy and optimization
|
||||
|
||||
- Indexed subtitle companions by directory and video stem instead of scanning all staged files for every video.
|
||||
- Reused the already-read watchlist total instead of issuing an identical count query.
|
||||
- Removed unused HLS segment-directory creation and deletion; native downloads write directly to a single temporary transport stream.
|
||||
- Consolidated duplicated Python provider subprocess implementations.
|
||||
- Removed unreferenced episode selection, title variant, bearer-token, cookie-clearing, command lookup, and obsolete destination-name helpers. Retained framework callbacks and SQLite attributes flagged as possible dead code because their consumers are external to the repository.
|
||||
|
||||
## Providers and dependencies
|
||||
|
||||
All three providers were compared with [upstream tree ae21244a5f3cabc58bd281fff0b3560cbfb7a0f8](https://github.com/TheYogMehta/extensions/tree/ae21244a5f3cabc58bd281fff0b3560cbfb7a0f8). AnimePahe had a same-version 5.0.6 change to recover a stale One Piece UUID from its saved mapping. That change was merged while retaining Kaizoku's stderr diagnostics, mirror handling, search retry limit, and bridge background-sync guard. Anikoto and AniNeko were current. The final provider check reports no pending upstream updates, with recognized local patches for Anikoto and AnimePahe.
|
||||
|
||||
The dependency audit identified undici advisories [GHSA-3wwx-pv8p-q78v](https://github.com/advisories/GHSA-3wwx-pv8p-q78v), [GHSA-r53p-7pc4-xj5r](https://github.com/advisories/GHSA-r53p-7pc4-xj5r), and [GHSA-rfgv-xxqx-mfg5](https://github.com/advisories/GHSA-rfgv-xxqx-mfg5). After updating undici, `npm audit --omit=dev` reports zero known vulnerabilities.
|
||||
|
||||
## Verification and limits
|
||||
|
||||
- Baseline: 294 unittest tests passed. Final suite: 305 tests passed, including new regressions for timeouts, missing outputs, fractional episodes, filesystem detection, and preservation of existing files.
|
||||
- Ruff undefined-name/unused-import checks pass; dead-code scan results were manually checked against callers.
|
||||
- Node syntax checks pass for all four inline page scripts and all four provider/bridge JavaScript files.
|
||||
- Shell syntax checks and `git diff --check` pass.
|
||||
- `KAIZOKU_PORT=8080 docker compose config --format json` confirms host 8080 maps to container 8421 and the application listens on 8421.
|
||||
- Tests use temporary state and fixture files. No production data migration, service restart, or deployment was performed.
|
||||
|
||||
Live provider playback, a Docker image build, and an actual Jellyfin server transfer were not exercised. Network checks verified upstream source versions and dependency advisories; provider behavior and file-move failures were tested with fixtures. This review does not establish the absence of all defects or cover unsupported HLS formats.
|
||||
@@ -16,7 +16,7 @@ Kaizoku is a local web app for searching, tracking, and downloading anime from A
|
||||
- Save English external subtitles when the provider exposes usable subtitle tracks.
|
||||
- Manage focused watchlists for `Watching`, `Planned`, `Finished`, and `Dropped`, with provider source tags and title links back to the original provider page.
|
||||
- Periodically refresh selected watchlists with a single visible advancing progress bar and auto-download newly available episodes.
|
||||
- Sync watchlist download flags from the filesystem.
|
||||
- Sync watchlist download flags from completed video files on the filesystem; subtitles, metadata, and partial downloads do not count as downloaded episodes or movies.
|
||||
- Hand completed libraries to Jellyfin TV or movie folders, then optionally request a scan of only the configured Jellyfin library.
|
||||
- Export/import watchlist backups.
|
||||
- Send unified Discord notifications for downloads, refreshes, Jellyfin handoff, and runtime errors.
|
||||
@@ -84,7 +84,7 @@ Useful environment variables:
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
The compose file builds the local checkout and runs Kaizoku on port `8421` by default. It mounts:
|
||||
The compose file builds the local checkout and runs Kaizoku on port `8421` by default. `KAIZOKU_PORT` changes the published host port; the app continues listening on port `8421` inside the container. It mounts:
|
||||
|
||||
- `./downloads` to `/downloads`
|
||||
- `${JELLYFIN_TV_DIR:-./jellyfin/tv}` to `/jellyfin/tv`
|
||||
@@ -117,15 +117,17 @@ Anikoto searches use the site's filter endpoint, which supports paginated querie
|
||||
|
||||
Kaizoku stores provider-backed show IDs as `provider:id`, for example `anikoto:some-show-slug`. Queue jobs resolve the episode source through `providers/bridge.js`, then `provider_downloader.py` downloads the media with `ffmpeg` into a staging directory. If a provider returns multiple servers for the requested sub or dub mode, Kaizoku tries every same-mode server source in quality order before falling back to another provider, including when resolving one server's playlist raises an HTTP error. It does not use sub sources for dub downloads, or dub sources for sub downloads. If a provider returns a master HLS playlist, Kaizoku selects the highest-bandwidth variant before starting `ffmpeg`. When a media playlist uses extensionless, SnapCDN, or disguised CDN segments, Kaizoku skips direct ffmpeg and uses a StrawVerse-style segment downloader; if HLS preflight fails, it stays on that native path instead of falling through to ffmpeg. The native downloader fetches the media playlist, preserves provider CDN session cookies across playlist, segment, and encryption-key requests, downloads and concatenates segments itself with browser-like media headers and the provider referer, can fall back to curl-impersonate browser wrappers after protected CDN `HTTP 403` responses, strips short PNG wrappers when present, retries temporary HTTP failures such as `429 Too Many Requests`, optionally paces requests with `KAIZOKU_SEGMENT_DOWNLOAD_DELAY`, then remuxes the local transport stream to MP4. Direct ffmpeg attempts also have a timeout guard so stalled HLS inputs can fall back cleanly. Each episode is written as a temporary `.mp4.part` file and moved into the downloads library after that episode succeeds, so already-finished episodes from a larger batch survive if a later episode fails. Retrying that failed queue job requests only the remaining episodes while keeping the original episode range for display and watchlist sync. Finalization preserves episode numbers from staged `SxxEyy` or `Episode yy` filenames before applying configured season/episode offsets.
|
||||
|
||||
Provider bridge subprocesses time out after 120 seconds by default. Watchlist refreshes apply their shorter request timeout to each metadata and episode-list call, so an unresponsive bridge can fail and allow subsequent work to continue. Fractional episode numbers such as `12.5` keep distinct filenames instead of colliding with episode `12`.
|
||||
|
||||
Provider server aliases that resolve to the same URL and request headers are downloaded only once, avoiding duplicate CDN requests and unnecessary rate limiting.
|
||||
|
||||
When the selected source exposes English external subtitle tracks, Kaizoku saves the first successfully fetched track alongside the video as `.eng.vtt`, `.eng.srt`, `.eng.ass`, or `.eng.ssa`. Subtitle requests use provider/track headers, session cookies, retries, and the media HTTP fallback. Subtitles move into the library with each completed video and keep matching filenames after custom naming, season/episode offsets, or filename collisions. Subtitle failures do not fail an otherwise completed video; the queue log reports failed tracks or that no English external track was exposed. Burned-in subtitles cannot be saved as a separate file, and Kaizoku does not extract embedded or HLS-playlist-only subtitle tracks. The bundled AnimePahe adapter currently exposes no external subtitle tracks. These changes apply to new downloads and do not backfill subtitles for existing videos.
|
||||
|
||||
If the primary provider cannot list, resolve, or download a requested episode, Kaizoku searches the selected provider's title on the remaining providers and tries the matching episode there. A custom library name is used only for output naming. Fallback requires a unique normalized title match, retaining season, part, and cour labels; equivalent notation such as `Season 2` and `2nd Season` is accepted. Shared words or a matching title prefix are insufficient. Ambiguous results, different seasons, and titles that cannot be verified (including alternate translations) are skipped. If no matching source succeeds, the job fails while preserving completed episodes. This prevents unavailable later-season episodes from being silently replaced with season 1 episodes; it does not identify or repair previously downloaded incorrect files. Existing finalization code moves staged files into the configured library layout, preserving data already present in production download folders.
|
||||
If the primary provider cannot list, resolve, or download a requested episode, Kaizoku searches the selected provider's title on the remaining providers and tries the matching episode there. A custom library name is used only for output naming. Fallback requires a unique normalized title match, retaining season, part, and cour labels; equivalent notation such as `Season 2` and `2nd Season` is accepted. Shared words or a matching title prefix are insufficient. Ambiguous results, different seasons, and titles that cannot be verified (including alternate translations) are skipped. If no matching source succeeds, the job fails while preserving completed episodes. This prevents unavailable later-season episodes from being silently replaced with season 1 episodes; it does not identify or repair previously downloaded incorrect files. Existing finalization code moves staged files into the configured library layout, preserving data already present in production download folders. If a library move fails, the queue reports failure and leaves remaining completed files in the staging folder shown in the job log for manual recovery. Resolve the storage/permission problem and recover those files before retrying the download.
|
||||
|
||||
## Data Safety
|
||||
|
||||
Kaizoku uses additive SQLite migrations for queue and watchlist schema changes. Upgrades do not delete configuration, watchlists, queue history, or downloaded files. Jellyfin handoff moves only completed library folders that pass the existing readiness checks, and both manual and automatic handoffs are persisted with per-episode progress in the Jellyfin Queue tab.
|
||||
Kaizoku uses additive SQLite migrations for queue and watchlist schema changes. Upgrades do not delete configuration, watchlists, queue history, or downloaded files. Jellyfin handoff moves only completed library folders that pass the existing readiness checks, and both manual and automatic handoffs are persisted with per-episode progress in the Jellyfin Queue tab. Handoffs keep videos and subtitle sidecars paired when destination names collide, preserving existing files with numbered names for the incoming pair. Source and target folders must not contain each other; overlapping folders are rejected before moving files.
|
||||
|
||||
## Provider Source
|
||||
|
||||
@@ -135,4 +137,6 @@ The Anikoto, AniNeko, and AnimePahe parser modules in `providers/extensions/Anim
|
||||
- AniNeko `3.0.4`
|
||||
- AnimePahe `5.0.6` with Kaizoku bridge patches
|
||||
|
||||
All three modules were checked against upstream tree `ae21244a5f3cabc58bd281fff0b3560cbfb7a0f8` on 2026-10-12. AnimePahe includes the upstream same-version UUID recovery update.
|
||||
|
||||
The Config page checks the bundled JavaScript against the upstream `main` branch and reports whether upstream updates are available. The patched Anikoto and AnimePahe modules keep their official version numbers and are reported separately as local changes while their upstream bases are current. Kaizoku acts as a local client-side parser/downloader wrapper and does not host media.
|
||||
@@ -970,8 +970,8 @@ def numeric_episode_key(value):
|
||||
def fetch_show_episode_snapshot(show_id, timeout=25):
|
||||
runtime = ensure_runtime()
|
||||
provider = str((runtime.get("config") or {}).get("provider") or "anikoto").strip().lower()
|
||||
info = provider_bridge.info(show_id, provider=provider)
|
||||
rows = provider_bridge.episodes(show_id, provider=provider)
|
||||
info = provider_bridge.info(show_id, provider=provider, timeout=timeout)
|
||||
rows = provider_bridge.episodes(show_id, provider=provider, timeout=timeout)
|
||||
episodes = {choice: [] for choice in MODE_CHOICES}
|
||||
for row in rows:
|
||||
value = str(row.get("number") or "").strip()
|
||||
@@ -1149,7 +1149,7 @@ def watchlist_downloaded_episode_values_from_filesystem(item, config, mode):
|
||||
seen = set()
|
||||
offset = (item or {}).get("auto_download_offset")
|
||||
for path in sorted(season_dir.rglob("*")):
|
||||
if not path.is_file():
|
||||
if path.suffix.lower() not in VIDEO_FILE_SUFFIXES or not path.is_file():
|
||||
continue
|
||||
match = pattern.search(path.stem)
|
||||
if not match:
|
||||
@@ -1169,6 +1169,38 @@ def _move_tree_contents(source_dir, target_dir, progress_fn=None):
|
||||
for source_path in sorted(source_dir.rglob("*"), key=lambda path: (len(path.parts), str(path)))
|
||||
if source_path.is_file()
|
||||
]
|
||||
# Reserve video/sidecar names together before any moves, including names
|
||||
# already occupied in the destination library or by another source file.
|
||||
destinations = {}
|
||||
reserved = {target_dir / path.relative_to(source_dir) for path in file_paths}
|
||||
subtitles_by_video = {}
|
||||
for path in file_paths:
|
||||
if path.suffix.lower() in app_support.SUBTITLE_FILE_SUFFIXES:
|
||||
stem, _tags = app_support.subtitle_filename_parts(path)
|
||||
subtitles_by_video.setdefault((path.parent, stem), []).append(path)
|
||||
for path in sorted(file_paths, key=lambda path: path.suffix.lower() not in VIDEO_FILE_SUFFIXES):
|
||||
if path in destinations:
|
||||
continue
|
||||
companions = subtitles_by_video.get((path.parent, path.stem), []) if path.suffix.lower() in VIDEO_FILE_SUFFIXES else []
|
||||
companions = [companion for companion in companions if companion not in destinations]
|
||||
base = target_dir / path.relative_to(source_dir)
|
||||
destination = base
|
||||
counter = 2
|
||||
while True:
|
||||
group = {path: destination}
|
||||
group.update({
|
||||
companion: destination.with_name(
|
||||
destination.stem + app_support.subtitle_filename_parts(companion)[1] + companion.suffix
|
||||
)
|
||||
for companion in companions
|
||||
})
|
||||
if all(not dest.exists() and (dest not in reserved or dest == target_dir / src.relative_to(source_dir))
|
||||
for src, dest in group.items()):
|
||||
break
|
||||
destination = base.with_name(f"{base.stem} ({counter}){base.suffix}")
|
||||
counter += 1
|
||||
destinations.update(group)
|
||||
reserved.update(group.values())
|
||||
total_files = len(file_paths)
|
||||
if progress_fn is not None:
|
||||
progress_fn(
|
||||
@@ -1178,17 +1210,15 @@ def _move_tree_contents(source_dir, target_dir, progress_fn=None):
|
||||
"files": [
|
||||
{
|
||||
"source": str(source_path),
|
||||
"current_file": str(target_dir / source_path.relative_to(source_dir)),
|
||||
"current_file": str(destinations[source_path]),
|
||||
}
|
||||
for source_path in file_paths
|
||||
],
|
||||
}
|
||||
)
|
||||
for index, source_path in enumerate(file_paths, start=1):
|
||||
relative = source_path.relative_to(source_dir)
|
||||
destination = target_dir / relative
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
final_destination = app_support.unique_destination(destination)
|
||||
final_destination = destinations[source_path]
|
||||
final_destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
if progress_fn is not None:
|
||||
progress_fn(
|
||||
{
|
||||
@@ -1262,8 +1292,12 @@ def move_watchlist_item_to_jellyfin(item, config, progress_fn=None):
|
||||
if target_dir is None:
|
||||
return {"moved": False, "reason": "target_missing", "item": item}
|
||||
try:
|
||||
if source_dir.resolve() == target_dir.resolve():
|
||||
source_path = source_dir.resolve()
|
||||
target_path = target_dir.resolve()
|
||||
if source_path == target_path:
|
||||
return {"moved": False, "reason": "same_path", "item": item, "source": str(source_dir), "target": str(target_dir)}
|
||||
if source_path in target_path.parents or target_path in source_path.parents:
|
||||
raise ValueError("Jellyfin source and target folders must not contain each other.")
|
||||
except OSError:
|
||||
pass
|
||||
if not source_dir.exists():
|
||||
@@ -1929,7 +1963,7 @@ class WatchlistStore:
|
||||
(active_category,),
|
||||
).fetchone()["count"]
|
||||
else:
|
||||
total = conn.execute("SELECT COUNT(*) AS count FROM watchlist").fetchone()["count"]
|
||||
total = overall_total
|
||||
totals = conn.execute(
|
||||
"""
|
||||
SELECT
|
||||
@@ -2290,7 +2324,10 @@ class WatchlistStore:
|
||||
media_type = normalize_media_type(existing_item.get("media_type"))
|
||||
if media_type == "movie":
|
||||
source_dir = watchlist_source_library_dir(existing_item, active_config)
|
||||
has_files = source_dir.exists() and any(path.is_file() for path in source_dir.rglob("*"))
|
||||
has_files = source_dir.exists() and any(
|
||||
path.suffix.lower() in VIDEO_FILE_SUFFIXES and path.is_file()
|
||||
for path in source_dir.rglob("*")
|
||||
)
|
||||
new_sub_values = []
|
||||
new_dub_values = []
|
||||
downloaded = has_files
|
||||
|
||||
+8
-31
@@ -24,20 +24,6 @@ from uuid import uuid4
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def configured_cli_command(env_name, executable_name):
|
||||
configured = str(os.environ.get(env_name) or "").strip()
|
||||
if configured:
|
||||
return configured
|
||||
resolved = shutil.which(executable_name)
|
||||
if resolved:
|
||||
return resolved
|
||||
for candidate in (Path("/usr/local/bin") / executable_name, Path("/usr/bin") / executable_name):
|
||||
if candidate.exists() and os.access(candidate, os.X_OK):
|
||||
return str(candidate)
|
||||
return executable_name
|
||||
|
||||
|
||||
KAIZOKU_DOWNLOADER = configured_cli_command("KAIZOKU_DOWNLOADER_BIN", "provider_downloader.py")
|
||||
APP_NAME = "Kaizoku"
|
||||
VERSION_FILE = PROJECT_ROOT / "VERSION"
|
||||
CHANGELOG_FILE = PROJECT_ROOT / "CHANGELOG.md"
|
||||
@@ -1161,17 +1147,6 @@ def episode_match_key(value):
|
||||
return f"{number}{suffix}" if number > 0 else text
|
||||
|
||||
|
||||
def unique_destination(path):
|
||||
if not path.exists():
|
||||
return path
|
||||
counter = 2
|
||||
while True:
|
||||
candidate = path.with_name(f"{path.stem} ({counter}){path.suffix}")
|
||||
if not candidate.exists():
|
||||
return candidate
|
||||
counter += 1
|
||||
|
||||
|
||||
def cleanup_empty_staging_dirs(staging_dir, remove_root=False):
|
||||
for path in sorted(staging_dir.rglob("*"), key=lambda item: len(item.parts), reverse=True):
|
||||
if path.is_dir():
|
||||
@@ -1217,6 +1192,11 @@ def finalize_library_files(job, episode=None, cleanup_staging=True, allow_empty=
|
||||
# Move each video and its subtitles together so collision suffixes and
|
||||
# custom library names remain identical for players such as Jellyfin.
|
||||
processed = set()
|
||||
subtitles_by_video = {}
|
||||
for path in files:
|
||||
if path.suffix.lower() in SUBTITLE_FILE_SUFFIXES:
|
||||
stem, _tags = subtitle_filename_parts(path)
|
||||
subtitles_by_video.setdefault((path.parent, stem), []).append(path)
|
||||
for source in sorted(files, key=lambda path: path.suffix.lower() not in VIDEO_FILE_SUFFIXES):
|
||||
if source in processed:
|
||||
continue
|
||||
@@ -1224,9 +1204,7 @@ def finalize_library_files(job, episode=None, cleanup_staging=True, allow_empty=
|
||||
if media_type == "movie":
|
||||
final_name = f"{library_name}{tags}{source.suffix}"
|
||||
else:
|
||||
ep = None
|
||||
if ep is None:
|
||||
ep = extract_episode_from_filename(source)
|
||||
ep = extract_episode_from_filename(source)
|
||||
if ep is None:
|
||||
ep = str(fallback_episode)
|
||||
fallback_episode += 1
|
||||
@@ -1234,9 +1212,8 @@ def finalize_library_files(job, episode=None, cleanup_staging=True, allow_empty=
|
||||
final_name = f"{library_name} - S{season}E{episode_label(ep)}{tags}{source.suffix}"
|
||||
companions = []
|
||||
if source.suffix.lower() in VIDEO_FILE_SUFFIXES:
|
||||
companions = [path for path in files if path not in processed and path != source
|
||||
and path.parent == source.parent and path.suffix.lower() in SUBTITLE_FILE_SUFFIXES
|
||||
and subtitle_filename_parts(path)[0] == source.stem]
|
||||
companions = [path for path in subtitles_by_video.get((source.parent, source.stem), [])
|
||||
if path not in processed]
|
||||
base = target_dir / final_name
|
||||
destination = base
|
||||
counter = 2
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ services:
|
||||
USER_UID: ${USER_UID:-}
|
||||
USER_GID: ${USER_GID:-}
|
||||
KAIZOKU_HOST: 0.0.0.0
|
||||
KAIZOKU_PORT: ${KAIZOKU_PORT:-8421}
|
||||
KAIZOKU_PORT: 8421
|
||||
KAIZOKU_ALLOW_REMOTE: ${KAIZOKU_ALLOW_REMOTE:-false}
|
||||
KAIZOKU_AUTH_USERNAME: ${KAIZOKU_AUTH_USERNAME:-}
|
||||
KAIZOKU_AUTH_PASSWORD: ${KAIZOKU_AUTH_PASSWORD:-}
|
||||
|
||||
@@ -346,12 +346,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return ("", "")
|
||||
return (username.strip(), password.strip())
|
||||
|
||||
def _bearer_token(self):
|
||||
header = str(self.headers.get("Authorization") or "").strip()
|
||||
if not header.startswith("Bearer "):
|
||||
return ""
|
||||
return header[len("Bearer ") :].strip()
|
||||
|
||||
def _cookie_value(self, name):
|
||||
raw = str(self.headers.get("Cookie") or self.headers.get("cookie") or "").strip()
|
||||
if not raw:
|
||||
@@ -407,15 +401,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
attributes += "; Secure"
|
||||
return attributes
|
||||
|
||||
def _clear_remote_auth_cookie(self):
|
||||
attributes = (
|
||||
f"{Handler.remote_session_cookie_name}=; "
|
||||
"Path=/; HttpOnly; SameSite=Lax; Max-Age=0"
|
||||
)
|
||||
if Handler._request_is_secure(self):
|
||||
attributes += "; Secure"
|
||||
return attributes
|
||||
|
||||
def _set_remote_auth_cookie_and_redirect(self, session_value, location):
|
||||
Handler.write_response_bytes(
|
||||
self,
|
||||
|
||||
Generated
+3
-3
@@ -598,9 +598,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "6.28.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.28.0.tgz",
|
||||
"integrity": "sha512-LIY910g9TI13YS95lrMFrs8Rm/u/irgHeTWoKCoteeJ04CUJ92eEfj0rVn+7VKMPBpUPiUoBKfhNyLI23EE/KA==",
|
||||
"version": "6.29.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.29.0.tgz",
|
||||
"integrity": "sha512-R+RODBqp6i2pPflGdq+xIOUkl+RNfGgHwoinecKu/JCuf2uO06cOKoDbI2P7Dn6KcswdKwrczbU6IYJ6K8X+wg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.17"
|
||||
|
||||
+16
-12
@@ -27,17 +27,21 @@ def parse_provider_id(value, default_provider="anikoto"):
|
||||
return provider if provider in PROVIDERS else "anikoto", text
|
||||
|
||||
|
||||
def bridge(command, provider, *args):
|
||||
def bridge(command, provider, *args, timeout=120):
|
||||
normalized = str(provider or "anikoto").strip().lower()
|
||||
if normalized not in PROVIDERS:
|
||||
normalized = "anikoto"
|
||||
proc = subprocess.run(
|
||||
["node", str(BRIDGE), command, normalized, *[str(arg) for arg in args]],
|
||||
cwd=PROJECT_ROOT,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
["node", str(BRIDGE), command, normalized, *[str(arg) for arg in args]],
|
||||
cwd=PROJECT_ROOT,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
timeout=timeout,
|
||||
)
|
||||
except subprocess.TimeoutExpired as exc:
|
||||
raise ProviderError(f"Provider {normalized} {command} timed out after {timeout} seconds.") from exc
|
||||
if proc.returncode != 0:
|
||||
raise ProviderError((proc.stderr or proc.stdout or f"Provider command {command} failed").strip())
|
||||
try:
|
||||
@@ -50,11 +54,11 @@ def search(query, provider="anikoto", page=1):
|
||||
return bridge("search", provider, query, page)
|
||||
|
||||
|
||||
def info(show_id, provider="anikoto"):
|
||||
def info(show_id, provider="anikoto", timeout=120):
|
||||
actual_provider, provider_id = parse_provider_id(show_id, provider)
|
||||
return bridge("info", actual_provider, provider_id)
|
||||
return bridge("info", actual_provider, provider_id, timeout=timeout)
|
||||
|
||||
|
||||
def episodes(show_id, provider="anikoto"):
|
||||
def episodes(show_id, provider="anikoto", timeout=120):
|
||||
actual_provider, provider_id = parse_provider_id(show_id, provider)
|
||||
return bridge("episodes", actual_provider, provider_id).get("episodes") or []
|
||||
return bridge("episodes", actual_provider, provider_id, timeout=timeout).get("episodes") or []
|
||||
+7
-50
@@ -19,11 +19,9 @@ import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from title_matching import normalize_identity_title_key
|
||||
from provider_bridge import PROVIDERS, bridge
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
BRIDGE = PROJECT_ROOT / "providers" / "bridge.js"
|
||||
PROVIDERS = ("anikoto", "anineko", "pahe")
|
||||
RETRYABLE_HTTP_STATUS = {408, 425, 429, 500, 502, 503, 504}
|
||||
CURL_STATUS_MARKER = b"\nKAIZOKU_HTTP_STATUS:"
|
||||
MEDIA_COOKIE_JAR = http.cookiejar.CookieJar()
|
||||
@@ -59,17 +57,6 @@ def episode_key(value):
|
||||
return str(number).rstrip("0").rstrip(".")
|
||||
|
||||
|
||||
def bridge(command, provider, *args):
|
||||
cmd = ["node", str(BRIDGE), command, provider, *[str(arg) for arg in args]]
|
||||
proc = subprocess.run(cmd, cwd=PROJECT_ROOT, text=True, capture_output=True, check=False)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError((proc.stderr or proc.stdout or f"{command} failed").strip())
|
||||
try:
|
||||
return json.loads(proc.stdout or "{}")
|
||||
except json.JSONDecodeError as exc:
|
||||
raise RuntimeError(f"Provider bridge returned invalid JSON: {exc}") from exc
|
||||
|
||||
|
||||
def emit_progress(**payload):
|
||||
clean = {key: value for key, value in payload.items() if value is not None}
|
||||
print(f"KAIZOKU_PROGRESS {json.dumps(clean, sort_keys=True)}", flush=True)
|
||||
@@ -112,33 +99,6 @@ def find_provider_show(provider, title, original_provider, original_show_id):
|
||||
return next(iter(matches)) if len(matches) == 1 else ""
|
||||
|
||||
|
||||
def episode_values(spec, episodes):
|
||||
values = []
|
||||
by_number = {episode_key(ep.get("number")): ep for ep in episodes}
|
||||
if not str(spec or "").strip():
|
||||
return episodes
|
||||
for part in re.split(r"[\s,]+", str(spec).strip()):
|
||||
if not part:
|
||||
continue
|
||||
if "-" in part:
|
||||
start, end = part.split("-", 1)
|
||||
try:
|
||||
left = int(float(start))
|
||||
right = int(float(end))
|
||||
except ValueError:
|
||||
continue
|
||||
step = 1 if right >= left else -1
|
||||
for number in range(left, right + step, step):
|
||||
item = by_number.get(str(number))
|
||||
if item and item not in values:
|
||||
values.append(item)
|
||||
continue
|
||||
item = by_number.get(episode_key(part)) if re.match(r"^\d+(?:\.\d+)?$", part) else None
|
||||
if item and item not in values:
|
||||
values.append(item)
|
||||
return values
|
||||
|
||||
|
||||
def requested_episode_numbers(spec, episodes):
|
||||
text = str(spec or "").strip()
|
||||
if not text:
|
||||
@@ -509,7 +469,7 @@ def parse_hls_segments(playlist_url, playlist_text):
|
||||
segments = []
|
||||
key_url = None
|
||||
iv = None
|
||||
media_sequence = 1
|
||||
media_sequence = 0
|
||||
segment_index = 0
|
||||
for raw_line in str(playlist_text or "").splitlines():
|
||||
line = raw_line.strip()
|
||||
@@ -519,7 +479,7 @@ def parse_hls_segments(playlist_url, playlist_text):
|
||||
try:
|
||||
media_sequence = int(line.split(":", 1)[1])
|
||||
except ValueError:
|
||||
media_sequence = 1
|
||||
media_sequence = 0
|
||||
continue
|
||||
if line.startswith("#EXT-X-KEY:"):
|
||||
attrs = {
|
||||
@@ -602,10 +562,6 @@ def download_hls_segments(
|
||||
if not segments:
|
||||
return 1
|
||||
ts_file = target.with_suffix(target.suffix + ".ts.part")
|
||||
segment_dir = target.parent / f".segments_{target.stem}"
|
||||
if segment_dir.exists():
|
||||
shutil.rmtree(segment_dir)
|
||||
segment_dir.mkdir(parents=True, exist_ok=True)
|
||||
key_cache = {}
|
||||
try:
|
||||
message = f"Downloading {len(segments)} HLS playlist segments directly..."
|
||||
@@ -695,13 +651,12 @@ def download_hls_segments(
|
||||
if code == 0 and partial.exists() and partial.stat().st_size > 0:
|
||||
partial.replace(target)
|
||||
return 0
|
||||
return code
|
||||
return code or 1
|
||||
finally:
|
||||
try:
|
||||
ts_file.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
shutil.rmtree(segment_dir, ignore_errors=True)
|
||||
|
||||
|
||||
def run_ffmpeg(cmd, timeout=180):
|
||||
@@ -848,6 +803,7 @@ def download_episode(stream, target, episode_number=None, episode_index=None, ep
|
||||
if code == 0 and partial.exists() and partial.stat().st_size > 0:
|
||||
partial.replace(target)
|
||||
return 0
|
||||
code = code or 1
|
||||
if stream.get("isM3U8") or ".m3u8" in str(input_url):
|
||||
try:
|
||||
code = download_hls_segments(
|
||||
@@ -933,7 +889,8 @@ def main():
|
||||
exit_code = 0
|
||||
for episode_index, ep in enumerate(wanted, start=1):
|
||||
number = ep.get("number")
|
||||
padded = f"{int(float(number)):02d}" if str(number).replace(".", "", 1).isdigit() else str(number)
|
||||
normalized_number = episode_key(number)
|
||||
padded = normalized_number.zfill(2) if normalized_number.isdigit() else normalized_number
|
||||
basename = f"{series_title} - S01E{padded}"
|
||||
target = output_dir / f"{basename}.mp4"
|
||||
last_error = None
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ UPSTREAM_PROVIDER_PREFIX = "extensions/"
|
||||
# A changed upstream hash must still report an update.
|
||||
LOCAL_PATCH_UPSTREAM_SHA256 = {
|
||||
"Anime/anikoto.js": "7cfbba6f145243166ca27ee8d8b662d74a242aa7208e3e9f92b2760c257ffc28",
|
||||
"Anime/pahe.js": "6b028108690d95fd232e61bc1e26ad59be2bb4e5d160a94f1d12927aa61589b6",
|
||||
"Anime/pahe.js": "155e683d20d7aab9ac3f2e8bd25c6bc0fb5a3b3dbc106942d12c93de55984ec1",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -715,8 +715,48 @@ async function AnimeInfo(id) {
|
||||
|
||||
if (is404 && id) {
|
||||
console.warn(
|
||||
`[AnimePahe] UUID ${id} returned 404. Fetching /anime directory to auto-heal UUID...`,
|
||||
`[AnimePahe] UUID ${id} returned 404. Checking canary and directory to auto-heal UUID...`,
|
||||
);
|
||||
|
||||
// Fast check: if this broken UUID belongs to One Piece and we already have a newer canary UUID
|
||||
const savedOpUuid = await getSavedOnePieceUuid();
|
||||
if (
|
||||
savedOpUuid &&
|
||||
String(id).toLowerCase() !== savedOpUuid.toLowerCase()
|
||||
) {
|
||||
let isOnePiece = false;
|
||||
if (global.mappingDb) {
|
||||
try {
|
||||
const check = await global.mappingDb
|
||||
.prepare("SELECT malid, id FROM pahe WHERE uuid = ? OR id = ? LIMIT 1")
|
||||
.get(id, id);
|
||||
if (check?.malid === 21 || check?.id === "4") isOnePiece = true;
|
||||
} catch (_) {}
|
||||
}
|
||||
if (global.db && !isOnePiece) {
|
||||
try {
|
||||
const animeCheck = await global.db
|
||||
.prepare("SELECT MalID, title FROM Anime WHERE id = ? OR id LIKE ? LIMIT 1")
|
||||
.get(id, `${id}-%`);
|
||||
if (animeCheck?.MalID === "21" || /^one piece$/i.test(animeCheck?.title || "")) {
|
||||
isOnePiece = true;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
if (isOnePiece) {
|
||||
console.error(
|
||||
`[AnimePahe] Auto-healing broken One Piece UUID ${id} -> ${savedOpUuid} via saved canary UUID`,
|
||||
);
|
||||
return {
|
||||
needsMappingSync: true,
|
||||
brokenUuid: id,
|
||||
newUuid: savedOpUuid,
|
||||
dataId: savedOpUuid,
|
||||
version: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
notifyRenderer("info-loading-status", {
|
||||
text: "Auto-healing AnimePahe UUID from directory, please wait...",
|
||||
});
|
||||
|
||||
+10
-4
@@ -1975,9 +1975,13 @@ class DownloadQueue:
|
||||
def _run_job(self, job):
|
||||
staging_dir = job_staging_dir(job)
|
||||
target_dir = job_output_dir(job)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
attempts, selected_methods, unavailable_methods = self._command_attempts(job, staging_dir)
|
||||
try:
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
attempts, selected_methods, unavailable_methods = self._command_attempts(job, staging_dir)
|
||||
except Exception as exc:
|
||||
self._fail_job_startup(job, exc)
|
||||
return
|
||||
if not attempts:
|
||||
with self.lock:
|
||||
job["status"] = "failed"
|
||||
@@ -2038,6 +2042,7 @@ class DownloadQueue:
|
||||
job["_dirty_log_lines"] = 0
|
||||
self._save_job_locked(job)
|
||||
|
||||
process = None
|
||||
try:
|
||||
exit_code = 1
|
||||
successful_backend = None
|
||||
@@ -2154,7 +2159,8 @@ class DownloadQueue:
|
||||
)
|
||||
else:
|
||||
job.setdefault("log", []).append(f"Library rename failed: {finalize_error}")
|
||||
cleanup_staging = True
|
||||
# Keep completed files available for recovery after a failed move.
|
||||
cleanup_staging = no_files_downloaded
|
||||
elif exit_code == 0:
|
||||
job["status"] = "done"
|
||||
job["progress"] = {
|
||||
|
||||
+153
@@ -3074,6 +3074,16 @@ class WatchlistFilesystemReconcileTests(unittest.TestCase):
|
||||
item = APP.WATCHLIST.get("show-movie-1")
|
||||
self.assertTrue(item["downloaded"])
|
||||
|
||||
def test_movie_sidecars_do_not_mark_movie_downloaded(self):
|
||||
self.seed_watchlist_item(media_type="movie", downloaded=False)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
for name in ("poster.jpg", "movie.nfo", "Movie.eng.srt", "Movie.mp4.part"):
|
||||
(root / name).write_bytes(b"sidecar")
|
||||
with mock.patch.object(APP, "watchlist_source_library_dir", return_value=root):
|
||||
APP.reconcile_watchlist_downloaded_files({"download_dir": directory})
|
||||
self.assertFalse(APP.WATCHLIST.get("show-reconcile-1")["downloaded"])
|
||||
|
||||
|
||||
class WatchlistBackupTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -5947,6 +5957,149 @@ require("./providers/bridge.js");
|
||||
)
|
||||
|
||||
|
||||
class RepositoryReviewRegressionTests(unittest.TestCase):
|
||||
def test_bridge_timeout_becomes_a_provider_error(self):
|
||||
with mock.patch.object(provider_bridge.subprocess, "run", side_effect=subprocess.TimeoutExpired("node", 7)) as run:
|
||||
with self.assertRaisesRegex(provider_bridge.ProviderError, "timed out after 7"):
|
||||
provider_bridge.episodes("anikoto:show", timeout=7)
|
||||
self.assertEqual(run.call_args.kwargs["timeout"], 7)
|
||||
|
||||
def test_watchlist_snapshot_passes_timeout_to_both_provider_calls(self):
|
||||
with mock.patch.object(provider_bridge, "info", return_value={"id": "anikoto:show", "title": "Show"}) as info, mock.patch.object(
|
||||
provider_bridge, "episodes", return_value=[]
|
||||
) as episodes:
|
||||
APP.fetch_show_episode_snapshot("anikoto:show", timeout=8)
|
||||
self.assertEqual(info.call_args.kwargs["timeout"], 8)
|
||||
self.assertEqual(episodes.call_args.kwargs["timeout"], 8)
|
||||
|
||||
def test_filesystem_episode_scan_ignores_sidecars_and_partial_downloads(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
for name in ("Show - S01E01.MP4", "Show - S01E02.eng.srt", "Show - S01E03.mp4.part", "Show - S01E04.nfo"):
|
||||
(root / name).write_bytes(b"data")
|
||||
with mock.patch.object(APP, "watchlist_source_season_dir", return_value=root):
|
||||
self.assertEqual(APP.watchlist_downloaded_episode_values_from_filesystem({}, {}, "sub"), ["1"])
|
||||
|
||||
def test_jellyfin_collision_keeps_subtitle_paired_and_existing_files_intact(self):
|
||||
for collision in ("video", "subtitle"):
|
||||
with self.subTest(collision=collision), tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "source"
|
||||
target = Path(directory) / "target"
|
||||
source.mkdir()
|
||||
target.mkdir()
|
||||
(source / "Show - S01E01.mp4").write_bytes(b"new video")
|
||||
(source / "Show - S01E01.eng.srt").write_bytes(b"new subtitle")
|
||||
# A source file already using (2) must also remain intact.
|
||||
(source / "Show - S01E01 (2).mp4").write_bytes(b"other video")
|
||||
occupied = target / ("Show - S01E01.mp4" if collision == "video" else "Show - S01E01.eng.srt")
|
||||
occupied.write_bytes(b"existing")
|
||||
moved = APP._move_tree_contents(source, target)
|
||||
self.assertEqual(len(moved), 3)
|
||||
self.assertEqual(occupied.read_bytes(), b"existing")
|
||||
self.assertEqual((target / "Show - S01E01 (3).mp4").read_bytes(), b"new video")
|
||||
self.assertEqual((target / "Show - S01E01 (3).eng.srt").read_bytes(), b"new subtitle")
|
||||
self.assertEqual((target / "Show - S01E01 (2).mp4").read_bytes(), b"other video")
|
||||
|
||||
def test_jellyfin_rejects_nested_folders_before_moving_files(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
parent = Path(directory)
|
||||
child = parent / "nested"
|
||||
child.mkdir()
|
||||
original = child / "episode.mp4"
|
||||
original.write_bytes(b"video")
|
||||
for source, target in ((parent, child), (child, parent)):
|
||||
with mock.patch.object(APP, "watchlist_source_library_dir", return_value=source), mock.patch.object(
|
||||
APP, "jellyfin_target_library_dir", return_value=target
|
||||
):
|
||||
with self.assertRaisesRegex(ValueError, "must not contain"):
|
||||
APP.move_watchlist_item_to_jellyfin({}, {})
|
||||
self.assertEqual(original.read_bytes(), b"video")
|
||||
|
||||
def test_hls_default_sequence_and_explicit_iv(self):
|
||||
playlist = '#EXTM3U\n#EXT-X-KEY:METHOD=AES-128,URI="key"\na.ts\nb.ts\n#EXT-X-KEY:METHOD=AES-128,URI="key",IV=0x10\nc.ts\n'
|
||||
segments = provider_downloader.parse_hls_segments("https://cdn.example/index.m3u8", playlist)
|
||||
self.assertEqual([segment["iv"] for segment in segments], ["0", "1", "0x10"])
|
||||
|
||||
def test_zero_exit_without_media_is_not_a_success(self):
|
||||
for native in (False, True):
|
||||
for empty_file in (False, True):
|
||||
with self.subTest(native=native, empty_file=empty_file), tempfile.TemporaryDirectory() as directory:
|
||||
target = Path(directory) / "episode.mp4"
|
||||
partial = target.with_suffix(".mp4.part")
|
||||
unused = Path(directory) / ".segments_episode"
|
||||
unused.mkdir()
|
||||
marker = unused / "keep"
|
||||
marker.write_bytes(b"existing")
|
||||
|
||||
def ffmpeg(*args, **kwargs):
|
||||
if empty_file:
|
||||
partial.touch()
|
||||
return 0
|
||||
|
||||
with mock.patch.object(provider_downloader, "run_ffmpeg", side_effect=ffmpeg), mock.patch.object(
|
||||
provider_downloader, "fetch_bytes_with_retries", return_value=b"segment"
|
||||
), mock.patch("sys.stdout", new_callable=io.StringIO):
|
||||
if native:
|
||||
code = provider_downloader.download_hls_segments({}, "https://cdn.example/index.m3u8", target, partial, playlist_text="#EXTM3U\nsegment.ts\n")
|
||||
else:
|
||||
code = provider_downloader.download_episode({"url": "https://cdn.example/video.mp4"}, target)
|
||||
self.assertNotEqual(code, 0)
|
||||
self.assertFalse(target.exists())
|
||||
self.assertEqual(marker.read_bytes(), b"existing")
|
||||
|
||||
def test_fractional_episodes_keep_distinct_download_filenames(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
episodes = [{"number": "12", "id": "ep12"}, {"number": "12.5", "id": "ep12.5"}]
|
||||
targets = []
|
||||
|
||||
def bridge(command, *args):
|
||||
return {"title": "Show"} if command == "info" else {"episodes": episodes}
|
||||
|
||||
def download(stream, target, **kwargs):
|
||||
targets.append(target.name)
|
||||
target.write_bytes(b"video")
|
||||
return 0
|
||||
|
||||
argv = ["provider_downloader.py", "--show-id", "anikoto:show", "--title", "Show", "--episodes", "12,12.5", "--output-dir", directory]
|
||||
with mock.patch.object(sys, "argv", argv), mock.patch.object(provider_downloader, "bridge", side_effect=bridge), mock.patch.object(
|
||||
provider_downloader, "provider_episode_candidates", side_effect=lambda p, s, _title, ep: [(p, s, ep)]
|
||||
), mock.patch.object(provider_downloader, "provider_stream_candidates", return_value=[{"url": "https://cdn.example/video.mp4"}]), mock.patch.object(
|
||||
provider_downloader, "download_episode", side_effect=download
|
||||
), mock.patch.object(provider_downloader, "download_subtitles", return_value=[]), mock.patch("sys.stdout", new_callable=io.StringIO):
|
||||
with self.assertRaises(SystemExit) as raised:
|
||||
provider_downloader.main()
|
||||
self.assertEqual(raised.exception.code, 0)
|
||||
self.assertEqual(targets, ["Show - S01E12.mp4", "Show - S01E12.5.mp4"])
|
||||
|
||||
def test_download_worker_recovers_after_output_folder_failure(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
queue = APP.DownloadQueue(lambda: {"download_dir": directory, "mode": "sub", "quality": "best"}, start_worker=False)
|
||||
job = queue.add({"query": "Folder failure", "episodes": "1"})
|
||||
blocked = Path(directory) / "blocked"
|
||||
blocked.write_bytes(b"keep")
|
||||
with mock.patch.object(queue_jobs, "job_output_dir", return_value=blocked):
|
||||
queue._run_job(job)
|
||||
self.assertEqual(queue.get(job["id"])["status"], "failed")
|
||||
self.assertEqual(blocked.read_bytes(), b"keep")
|
||||
|
||||
def test_library_move_failure_retains_completed_staging_files(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
queue = APP.DownloadQueue(lambda: {"download_dir": directory, "mode": "sub", "quality": "best"}, start_worker=False)
|
||||
job = queue.add({"query": "Move failure", "episodes": "1"})
|
||||
staging = queue_jobs.job_staging_dir(job)
|
||||
staging.mkdir(parents=True, exist_ok=True)
|
||||
video = staging / "Show - S01E01.mp4"
|
||||
video.write_bytes(b"completed video")
|
||||
process = mock.Mock(pid=4321, stdout=[])
|
||||
process.wait.return_value = 0
|
||||
with mock.patch.object(queue_jobs.subprocess, "Popen", return_value=process), mock.patch.object(
|
||||
queue_jobs, "finalize_library_files", side_effect=PermissionError("library read only")
|
||||
):
|
||||
queue._run_job(job)
|
||||
self.assertEqual(queue.get(job["id"])["status"], "failed")
|
||||
self.assertEqual(video.read_bytes(), b"completed video")
|
||||
|
||||
|
||||
class DockerfilePackagingTests(unittest.TestCase):
|
||||
def test_provider_updates_module_is_copied_into_image(self):
|
||||
dockerfile = (ROOT / "Dockerfile").read_text(encoding="utf-8")
|
||||
|
||||
@@ -62,18 +62,6 @@ def title_match_variants(value):
|
||||
return variants
|
||||
|
||||
|
||||
def identity_title_variants(value):
|
||||
variants = set()
|
||||
normalized = normalize_identity_title_key(value)
|
||||
if normalized:
|
||||
variants.add(normalized)
|
||||
stripped = re.sub(r"\b(19|20)\d{2}\b", " ", normalized)
|
||||
stripped = re.sub(r"\s+", " ", stripped).strip()
|
||||
if stripped:
|
||||
variants.add(stripped)
|
||||
return variants
|
||||
|
||||
|
||||
def title_lookup_queries(value):
|
||||
queries = []
|
||||
for raw_value in base_title_variants(value):
|
||||
|
||||
Reference in new issue
Block a user