Skip to content

Commit

Permalink
Merge branch 'main' of github.com:KevinNitroG/VNULIB-Downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Feb 27, 2024
2 parents 5a566e8 + 759f0d3 commit dcd4f13
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/modules/create_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand All @@ -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]
)

0 comments on commit dcd4f13

Please sign in to comment.