diff --git a/src/modules/create_pdf.py b/src/modules/create_pdf.py index 1deada6..2414759 100644 --- a/src/modules/create_pdf.py +++ b/src/modules/create_pdf.py @@ -4,12 +4,12 @@ import os +from concurrent.futures import ProcessPoolExecutor + import img2pdf from .link_parse import Link, LinkFile -from concurrent.futures import ProcessPoolExecutor - class CreatePDF: """Merge the images of books into PDF files @@ -18,8 +18,9 @@ class CreatePDF: - links (list[Link]): The list of links object """ - def __init__(self, links: list[Link]) -> None: + def __init__(self, links: list[Link], download_directory: str) -> None: self.links: list[Link] = links + self.download_directory: str = download_directory @staticmethod def merge_jpg_to_pdf_page_link_or_preview_link( @@ -61,8 +62,7 @@ def merge_jpg_to_pdf_book_link(book_directory: str, link: Link) -> None: link_page, ) - @staticmethod - def create_pdf(dowload_directory: str, links: list[Link]) -> None: + def create_pdf(self) -> None: """ For each subdirectory in a directory, if there are JPG images, merge them into a single PDF. If there are no JPG images, use the merge_jpg_to_pdf_book_link function. @@ -71,12 +71,12 @@ def create_pdf(dowload_directory: str, links: list[Link]) -> None: directory (str): The directory containing the subdirectories. links (list[Link]): list of Link """ - for link in links: + for link in self.links: if link.original_type == "book": CreatePDF.merge_jpg_to_pdf_book_link( - os.path.join(dowload_directory, link.name), link + os.path.join(self.download_directory, link.name), link ) else: CreatePDF.merge_jpg_to_pdf_page_link_or_preview_link( - os.path.join(dowload_directory, link.name), link.files[0] + os.path.join(self.download_directory, link.name), link.files[0] )