fix: Resume unfinished imageset downloads

This commit is contained in:
abdus committed 2026-10-20 12:59:23 +00:00
1 parent be47aede02
commit 50ea658fc7
2 files changed
+113 -12

No files matched your search

+33 -12
View File
@@ -284,6 +284,9 @@ def process_imageset(path: Path, processor: ImageProcessor) -> None:
return
for archive in archives:
if archive.with_name(f"{archive.name}.aria2").exists():
logging.warning(f"skipping {archive}: download is unfinished")
return
logging.info(f"extracting {archive} → {output_dir}")
if archive.suffix.lower() == ".zip":
try:
@@ -342,7 +345,7 @@ def remove_empty_dirs(root_dir: Path) -> None:
for d in removed:
d.rmdir()
if removed:
print(f"removed {len(removed)} empty dir(s) in {root_dir}")
logging.info(f"removed {len(removed)} empty dir(s) in {root_dir}")
def move_to_trash(file_paths: list[Path]) -> None:
@@ -423,9 +426,9 @@ def gallery_cmd(urls: tuple[str, ...], name: str | None, cwd: Path | None) -> No
output_dir = (cwd or Path(".")) / resolved_name
if output_dir.exists() and _has_images(output_dir):
print(f"skipping gallery-dl: {output_dir} already has images")
logging.info(f"skipping gallery-dl: {output_dir} already has images")
else:
print(f"gallery-dl → {output_dir}")
logging.info(f"gallery-dl → {output_dir}")
args = ["uvx", "gallery-dl"]
if name or cwd:
args += ["-D", str(output_dir)]
@@ -445,24 +448,42 @@ def filehost_cmd(urls: tuple[str, ...], name: str | None, cwd: Path, token: str)
output_dir.mkdir(parents=True, exist_ok=True)
for url in urls:
print(f"unrestricting {url}")
logging.info(f"unrestricting {url}")
dl_url = resolve_download_url_with_alldebrid(token, url)
meta = _resolve_url(dl_url)
if meta.suggested_extension in _VIDEO_EXTS:
video_path = (cwd or Path(".")) / (resolved_name + meta.suggested_extension)
print(f"video detected → {video_path}")
if video_path.exists() and video_path.stat().st_size > 5 * 1024 * 1024:
print(f"skipping: {video_path.name} already downloaded")
logging.info(f"video detected → {video_path}")
if video_path.with_name(f"{video_path.name}.aria2").exists():
logging.warning(f"unfinished download; resuming {video_path}")
if (
video_path.exists()
and not video_path.with_name(f"{video_path.name}.aria2").exists()
and video_path.stat().st_size > 5 * 1024 * 1024
):
logging.info(f"skipping: {video_path.name} already downloaded")
continue
run_command(["aria2c", "-o", str(video_path), dl_url])
run_command(args=[
"aria2c", "--continue=true", f"--dir={video_path.parent}",
f"--out={video_path.name}", dl_url,
])
continue
dest = output_dir / meta.suggested_filename
if dest.exists() and dest.stat().st_size > 5 * 1024 * 1024:
print(f"skipping: {dest.name} already downloaded")
if dest.with_name(f"{dest.name}.aria2").exists():
logging.warning(f"unfinished download; resuming {dest}")
if (
dest.exists()
and not dest.with_name(f"{dest.name}.aria2").exists()
and dest.stat().st_size > 5 * 1024 * 1024
):
logging.info(f"skipping: {dest.name} already downloaded")
continue
print(f"downloading {meta.suggested_filename} → {output_dir}")
run_command(["aria2c", f"--dir={output_dir}", dl_url])
logging.info(f"downloading {meta.suggested_filename} → {output_dir}")
run_command(args=[
"aria2c", "--continue=true", f"--dir={output_dir}",
f"--out={dest.name}", dl_url,
])
process_imageset(path=output_dir, processor=detect_resizer())