diff --git a/src/api/pyproject.toml b/src/api/pyproject.toml index ad6344c..25b2e47 100644 --- a/src/api/pyproject.toml +++ b/src/api/pyproject.toml @@ -17,7 +17,6 @@ dependencies = [ "aiohttp-client-cache[all]", "bs4>=0.0.2", "uvicorn>=0.32.1", - "pyexiftool>=0.5.6", "weasyprint>=63.0", "jinja2>=3.1.6", ] @@ -31,5 +30,6 @@ aiohttp-client-cache = { git = "https://github.com/TheOnlyWayUp/aiohttp-client-c [dependency-groups] dev = [ "ipykernel>=6.29.5", + "ipynb>=0.5.1", "ruff>=0.11.12", ] diff --git a/src/api/src/create_book/generators/pdf.py b/src/api/src/create_book/generators/pdf.py index b6c2c08..9c12183 100644 --- a/src/api/src/create_book/generators/pdf.py +++ b/src/api/src/create_book/generators/pdf.py @@ -4,7 +4,6 @@ from pathlib import Path from tempfile import NamedTemporaryFile, _TemporaryFileWrapper from bs4 import BeautifulSoup -from exiftool import ExifTool from jinja2 import Template from weasyprint import CSS, HTML from weasyprint.text.fonts import FontConfiguration @@ -134,6 +133,12 @@ class PDFGenerator(AbstractGenerator): "book_title": self.story["title"], "cover": f"data:image/jpg;base64,{b64encode(self.cover).decode()}", "username": self.story["user"]["username"], + "author_bio": self.story["user"]["description"], + "tags": self.story["tags"], + "created": self.story["createDate"], + "modified": self.story["modifyDate"], + "is_completed": self.story["completed"], + "is_mature": self.story["mature"], "description": self.story["description"], "avatar": b64encode(self.author).decode(), "copyright": { @@ -160,44 +165,10 @@ class PDFGenerator(AbstractGenerator): self.book.name, stylesheets=[stylesheet_obj], font_config=font_config ) - def add_metadata(self): - """Write metadata to generated PDF file at self.book, using ExifTool.""" - - clean_description = ( - self.story["description"].strip().replace("\n", "$/") - ) # exiftool doesn't parse \ns correctly, they support $/ for the same instead. ` ` is another option. - - metadata = { - "Author": self.story["user"]["username"], - "Title": self.story["title"], - "Subject": clean_description, - "CreationDate": self.story["createDate"], - "ModDate": self.story["modifyDate"], - "Keywords": ",".join(self.story["tags"]), - "Language": self.story["language"]["name"], - "Completed": self.story["completed"], - "MatureContent": self.story["mature"], - "Producer": "Dhanush Rambhatla (TheOnlyWayUp - https://rambhat.la) and WattpadDownloader", - } # As per https://exiftool.org/TagNames/PDF.html - - with ExifTool(config_file=DATA_PATH / "exiftool.config") as et: - # Custom configuration adds Completed and MatureContent tags. - # exiftool logger logs executed command - et.execute( - *( - [f"-{key}={value}" for key, value in metadata.items()] - + [ - "-overwrite_original", - self.book.file.name, - ] - ) - ) - def compile(self): parts = self.generate_chapters() self.populate_template(parts) self.generate_pdf() - self.add_metadata() return True def dump(self) -> BytesIO: diff --git a/src/api/src/create_book/generators/pdf/book.html b/src/api/src/create_book/generators/pdf/book.html index 413b10b..f858a59 100644 --- a/src/api/src/create_book/generators/pdf/book.html +++ b/src/api/src/create_book/generators/pdf/book.html @@ -1,73 +1,87 @@ + +
+ +Ex Libris Sapientiae
+ + + + {% if copyright.data %} +{{ statement }}
+ +{{ freedoms }}
+ +Printing: {{ printing }}
+ ++ ID: {{ book_id }}. + View this Book Online +
+Ex Libris Sapientiae
- - - - {% if copyright.data %} -{{ statement }}
- -{{ freedoms }}
- -Printing: {{ printing }}
- -- ID: {{ book_id }}. - View this Book Online +