Workflow: sparse partial checkout (code and _incoming only), book lookup before processing, safe rebase retry; revert cancel-in-progress
This commit is contained in:
+13
-4
@@ -40,14 +40,23 @@ def author_slug(author):
|
||||
return bookio.slug(" ".join([parts[-1]] + parts[:-1])) if parts else "unknown"
|
||||
|
||||
|
||||
def book_folder(cfg, author, title):
|
||||
return os.path.join(settings.resolve(cfg, "books_dir"), author_slug(author), bookio.slug(title))
|
||||
|
||||
|
||||
def detect(pdf, title=None, author=None):
|
||||
"""Title and author from the PDF itself (title: PDF metadata; author: a 'By <Name>' line on the first pages)."""
|
||||
author = author or find_author([u["text"] for u in pdftext.units(pdf, first_pages=6)])
|
||||
title = title or find_title(pdf)
|
||||
return title, author
|
||||
|
||||
|
||||
def run(cfg, pdf, title=None, author=None):
|
||||
"""Returns the book folder path."""
|
||||
pdf_units = pdftext.units(pdf)
|
||||
author = author or find_author([u["text"] for u in pdf_units[:6]])
|
||||
title = title or find_title(pdf)
|
||||
title, author = detect(pdf, title, author)
|
||||
if not author or not title:
|
||||
raise SystemExit("could not find title/author in the PDF; pass --title and --author")
|
||||
book_dir = os.path.join(settings.resolve(cfg, "books_dir"), author_slug(author), bookio.slug(title))
|
||||
book_dir = book_folder(cfg, author, title)
|
||||
os.makedirs(book_dir, exist_ok=True)
|
||||
copy = os.path.join(book_dir, os.path.basename(pdf))
|
||||
if os.path.exists(copy) and sha256(copy) != sha256(pdf):
|
||||
|
||||
Reference in New Issue
Block a user