From 3184be0c42005a45704a1b1f69a49820d624b23e Mon Sep 17 00:00:00 2001 From: mmynk Date: Sun, 14 Dec 2025 18:25:50 -0800 Subject: [PATCH 1/2] fix data directory creation when epub is in different directory When running reader3.py with an epub file from a different directory, the data directory was created relative to the epub file's location instead of the current working directory where the server expects it. This caused the server to show no content. Now creates the data directory in pwd to fix the issue regardless of wherever the epub file is located. --- reader3.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/reader3.py b/reader3.py index d0b9d3f..a9db5fd 100644 --- a/reader3.py +++ b/reader3.py @@ -8,6 +8,7 @@ from dataclasses import dataclass, field from typing import List, Dict, Optional, Any from datetime import datetime +from pathlib import Path from urllib.parse import unquote import ebooklib @@ -300,8 +301,10 @@ def save_to_pickle(book: Book, output_dir: str): sys.exit(1) epub_file = sys.argv[1] - assert os.path.exists(epub_file), "File not found." - out_dir = os.path.splitext(epub_file)[0] + "_data" + epub_path = Path(epub_file) + assert epub_path.exists(), "File not found." + out_dir = Path() / epub_path.stem + out_dir = str(out_dir) + "_data" book_obj = process_epub(epub_file, out_dir) save_to_pickle(book_obj, out_dir) From 9b40d4bd8c14448dd2dc857a6601d1ee27d5900d Mon Sep 17 00:00:00 2001 From: mmynk Date: Tue, 13 Jan 2026 22:33:16 -0800 Subject: [PATCH 2/2] handle multiple paths and dir --- reader3.py | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/reader3.py b/reader3.py index a9db5fd..a9444f0 100644 --- a/reader3.py +++ b/reader3.py @@ -293,6 +293,10 @@ def save_to_pickle(book: Book, output_dir: str): # --- CLI --- +def is_epub_file(path: Path): + return path.suffix == '.epub' + + if __name__ == "__main__": import sys @@ -300,17 +304,32 @@ def save_to_pickle(book: Book, output_dir: str): print("Usage: python reader3.py ") sys.exit(1) - epub_file = sys.argv[1] - epub_path = Path(epub_file) - assert epub_path.exists(), "File not found." - out_dir = Path() / epub_path.stem - out_dir = str(out_dir) + "_data" - - book_obj = process_epub(epub_file, out_dir) - save_to_pickle(book_obj, out_dir) - print("\n--- Summary ---") - print(f"Title: {book_obj.metadata.title}") - print(f"Authors: {', '.join(book_obj.metadata.authors)}") - print(f"Physical Files (Spine): {len(book_obj.spine)}") - print(f"TOC Root Items: {len(book_obj.toc)}") - print(f"Images extracted: {len(book_obj.images)}") + files = [] + for arg in sys.argv[1:]: + path = Path(arg) + + if not path.exists(): + print(f"No book found at path: {path}") + continue + + if path.is_dir(): + for f in path.iterdir(): + if is_epub_file(f): + files.append(f) + elif is_epub_file(path): + files.append(path) + + + for epub_file in files: + out_dir = Path() / epub_file.stem + out_dir = str(out_dir) + "_data" + + book_obj = process_epub(epub_file, out_dir) + save_to_pickle(book_obj, out_dir) + print("\n--- Summary ---") + print(f"Title: {book_obj.metadata.title}") + print(f"Authors: {', '.join(book_obj.metadata.authors)}") + print(f"Physical Files (Spine): {len(book_obj.spine)}") + print(f"TOC Root Items: {len(book_obj.toc)}") + print(f"Images extracted: {len(book_obj.images)}") + print("==============================\n")