OCR a scratch copy of the PDF (Ghostscript SAFER cannot read it from the CI workspace)

This commit is contained in:
Audiobook Producer
2026-10-18 02:08:16 -05:00
parent 50bfa3e239
commit 53d6fb405e
+4 -1
View File
@@ -105,7 +105,10 @@ def ocr_if_needed(cfg, book_dir, book):
out_dir = os.path.join(settings.resolve(cfg, "work_dir"), os.path.basename(book_dir)) out_dir = os.path.join(settings.resolve(cfg, "work_dir"), os.path.basename(book_dir))
os.makedirs(out_dir, exist_ok=True) os.makedirs(out_dir, exist_ok=True)
out = os.path.join(out_dir, "ocr.pdf") out = os.path.join(out_dir, "ocr.pdf")
src = os.path.join(book_dir, book["source_pdf"]) # OCR a copy kept in the scratch folder: Ghostscript 10 (-dSAFER, used inside ocrmypdf) cannot open a PDF that sits
# behind a symlink outside its permitted paths, e.g. in a CI workspace. Measured in a job container (2026-10-18).
src = os.path.join(out_dir, "in.pdf")
shutil.copyfile(os.path.join(book_dir, book["source_pdf"]), src)
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:
print("ocrmypdf failed, exit %d. stdout: %r stderr: %r" % (r.returncode, r.stdout[-1500:], r.stderr[-3000:])) print("ocrmypdf failed, exit %d. stdout: %r stderr: %r" % (r.returncode, r.stdout[-1500:], r.stderr[-3000:]))