Drop a link: .url/.txt in _incoming/ is downloaded, verified as a PDF, stored as the book's source PDF; workflow also triggers on link files

This commit is contained in:
Audiobook Producer
2026-10-18 13:25:01 -05:00
parent b72c0464ef
commit 9287ea8e16
6 changed files with 406 additions and 22 deletions
+20 -3
View File
@@ -9,6 +9,7 @@
python3 _pipeline/cli.py check <mp3 or folder> ... ACX checker, pass/fail table
"""
import argparse
import json
import os
import sys
@@ -71,8 +72,14 @@ def main(argv=None):
p.add_argument("--compare", help="a books folder (like the repo books/); the text-stage output is compared with the same <author>/<book> folder in it")
p.add_argument("--compare-strict", action="store_true", help="with --compare: fail when the output differs (default: report only)")
p.add_argument("--result-file", help="write {ok, book_dir, pdf} JSON here")
p.add_argument("--source-url", help="where the PDF was downloaded from (recorded in book.json)")
p.add_argument("--name-hint", action="append", default=[], help="another file name to read a title from (repeatable)")
p = sub.add_parser("bookpath", help="print the book folder (relative to the repo root) this PDF will go to")
p.add_argument("pdf")
p.add_argument("--name-hint", action="append", default=[])
p = sub.add_parser("fetch", help="download the PDF named by a .url/.txt file into a scratch folder; writes <out>/fetch.json")
p.add_argument("urlfile")
p.add_argument("--out", required=True)
p = sub.add_parser("ingest")
p.add_argument("pdf")
p.add_argument("--title")
@@ -97,14 +104,24 @@ def main(argv=None):
if a.cmd == "bookpath":
import process
try:
title, author, _ = process.resolve_meta(os.path.abspath(a.pdf))
m = process.resolve_meta(cfg, os.path.abspath(a.pdf), name_hints=a.name_hint)
except process.Failed as e:
sys.exit(str(e))
print(os.path.relpath(ingest.book_folder(cfg, author, title), settings.REPO_ROOT))
print("\n".join(m["log"]), file=sys.stderr)
print(os.path.relpath(ingest.book_folder(cfg, m["author"], m["title"]), settings.REPO_ROOT))
return
if a.cmd == "fetch":
import fetch
try:
res = fetch.fetch_from_file(cfg, a.urlfile, a.out)
with open(os.path.join(a.out, "fetch.json"), "w", encoding="utf-8") as f:
json.dump(res, f)
except fetch.FetchError as e:
sys.exit("FETCH FAILED: %s" % e)
return
if a.cmd == "process":
import process
sys.exit(process.process(cfg, a.pdf, a.dry_run, a.force, a.title, a.author, a.compare, a.result_file, a.compare_strict))
sys.exit(process.process(cfg, a.pdf, a.dry_run, a.force, a.title, a.author, a.compare, a.result_file, a.compare_strict, a.source_url, a.name_hint))
if a.cmd in ("run", "ingest"):
book_dir = ingest.run(cfg, os.path.abspath(a.pdf), a.title, a.author)
print("ingest done ->", book_dir)