manga-scans-fetcher/fetch_scans.py
2023-07-19 19:11:42 +02:00

54 lines
1.2 KiB
Python

# -*- encoding: utf-8 -*-
import logging
from pathlib import Path
from scans.lelscans import LelScansFetcher
# Folder containing the scans
SCAN_FOLDER = Path("scans")
# List of scan numbers to ignore
IGNORE_NUMBERS = [] # [str(i) for i in range(1, 910 + 1)]
def main():
logging.basicConfig(level=logging.INFO)
manga = "One Punch Man" # "One Piece"
SCAN_FOLDER.joinpath(manga).mkdir(exist_ok=True)
fetcher = LelScansFetcher()
one_piece = fetcher.find_manga(manga)
assert one_piece is not None
chapters = fetcher.list_chapters(one_piece)
print(
"Found {} scans from {} to {}... ".format(
len(chapters), chapters[0].number, chapters[-1].number
)
)
# check the scans that need to be downloaded
for chapter in chapters:
number = chapter.number
# ignore the number
if number in IGNORE_NUMBERS:
continue
folder = SCAN_FOLDER.joinpath(manga, number.replace(".", "_"))
pdf = SCAN_FOLDER.joinpath(manga, "ops_{}.pdf".format(number))
if pdf.exists():
continue
# check if the scan exists
if not pdf.exists():
fetcher.fetch_chapter(chapter, folder, pdf)
if __name__ == "__main__":
main()