From 50bfa3e23939d9c2a8c8a558e53fe7291cd6db80 Mon Sep 17 00:00:00 2001 From: Audiobook Producer Date: Sun, 18 Oct 2026 02:00:38 -0500 Subject: [PATCH] Print full ocrmypdf output on failure; sanitize control characters in warnings.log --- _pipeline/bookio.py | 2 +- _pipeline/ingest.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/_pipeline/bookio.py b/_pipeline/bookio.py index ed8de78..53ba67e 100644 --- a/_pipeline/bookio.py +++ b/_pipeline/bookio.py @@ -30,7 +30,7 @@ def write_warnings(book_dir, stage, entries): if os.path.exists(path): with open(path, encoding="utf-8") as f: keep = [ln for ln in f.read().splitlines() if ln and not ln.startswith(stage + " |")] - one = lambda t: " / ".join(str(t).split("\n")).strip() # one entry = one line + one = lambda t: " / ".join(re.sub(r"[\x00-\x08\x0b-\x1f]", " ", str(t).replace("\r", "\n")).split("\n")).strip() # one entry = one line lines = keep + ["%s | %s | %s | %s" % (stage, k, one(w), one(m)) for k, w, m in entries] with open(path, "w", encoding="utf-8") as f: f.write("\n".join(lines) + ("\n" if lines else "")) diff --git a/_pipeline/ingest.py b/_pipeline/ingest.py index b3abe43..56cb0b4 100644 --- a/_pipeline/ingest.py +++ b/_pipeline/ingest.py @@ -108,5 +108,6 @@ def ocr_if_needed(cfg, book_dir, book): src = os.path.join(book_dir, book["source_pdf"]) r = subprocess.run(["ocrmypdf", "--skip-text", "-l", cfg["ocr"]["language"], src, out], capture_output=True, text=True) if r.returncode != 0: + print("ocrmypdf failed, exit %d. stdout: %r stderr: %r" % (r.returncode, r.stdout[-1500:], r.stderr[-3000:])) return [("ocr-failed", where, "ocrmypdf exit %d: %s" % (r.returncode, (r.stderr.strip()[:700] + " ... " + r.stderr.strip()[-500:]) if len(r.stderr) > 1250 else r.stderr.strip()))] return [("ocr", where, "OCR applied to a scratch copy; original untouched")]