warnings.log: one line per entry; longer OCR error text

This commit is contained in:
Audiobook Producer
2026-10-18 01:57:44 -05:00
parent 9e8d902547
commit 568bf7749e
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -30,7 +30,8 @@ def write_warnings(book_dir, stage, entries):
if os.path.exists(path): if os.path.exists(path):
with open(path, encoding="utf-8") as f: with open(path, encoding="utf-8") as f:
keep = [ln for ln in f.read().splitlines() if ln and not ln.startswith(stage + " |")] keep = [ln for ln in f.read().splitlines() if ln and not ln.startswith(stage + " |")]
lines = keep + ["%s | %s | %s | %s" % (stage, k, w, m) for k, w, m in entries] one = lambda t: " / ".join(str(t).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: with open(path, "w", encoding="utf-8") as f:
f.write("\n".join(lines) + ("\n" if lines else "")) f.write("\n".join(lines) + ("\n" if lines else ""))
+1 -1
View File
@@ -108,5 +108,5 @@ def ocr_if_needed(cfg, book_dir, book):
src = os.path.join(book_dir, book["source_pdf"]) 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) r = subprocess.run(["ocrmypdf", "--skip-text", "-l", cfg["ocr"]["language"], src, out], capture_output=True, text=True)
if r.returncode != 0: if r.returncode != 0:
return [("ocr-failed", where, "ocrmypdf exit %d: %s" % (r.returncode, (r.stderr.strip()[:300] + " ... " + r.stderr.strip()[-300:]) if len(r.stderr) > 650 else r.stderr.strip()))] 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")] return [("ocr", where, "OCR applied to a scratch copy; original untouched")]