Skip to content

Commit

Permalink
Add optional dependency concat
Browse files Browse the repository at this point in the history
  • Loading branch information
ilotoki0804 committed Jun 22, 2024
1 parent c30bd41 commit 0182963
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions WebtoonScraper/image_concatenator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@
import os
import shutil
from pathlib import Path
from typing import TYPE_CHECKING, Generator, Iterator, Literal
from typing import TYPE_CHECKING, Iterator, Literal

from PIL import Image, UnidentifiedImageError
from tqdm import tqdm

from WebtoonScraper.exceptions import MissingOptionalDependencyError

from . import webtoon_viewer
from .directory_merger import ContainerStates, _directories_and_files_of, ensure_normal
from .miscs import logger

BatchMode = tuple[Literal["count", "height"], int] | tuple[Literal["ratio"], float] | Literal["all"]

if TYPE_CHECKING:
from PIL import Image, UnidentifiedImageError
else:
Image = UnidentifiedImageError = None


def _load_pillow():
global Image, UnidentifiedImageError
if Image is None:
with MissingOptionalDependencyError.importing("Pillow", "concat"):
from PIL import Image
if UnidentifiedImageError is None:
with MissingOptionalDependencyError.importing("Pillow", "concat"):
from PIL import UnidentifiedImageError


def concat_webtoon(
source_webtoon_directory: Path,
target_webtoon_directory: Path | None,
Expand Down Expand Up @@ -57,6 +74,8 @@ def concat_webtoon(
Returns:
연결된 이미지들이 들어 있는 웹툰 디렉토리를 반환합니다. 만약 WORKING 파일로 인해 비정상 종료되었다면 None을 반환합니다.
"""
_load_pillow()

ensure_normal(source_webtoon_directory, empty_ok=False, manual_container_state=manual_container_state)

directories, files = _directories_and_files_of(source_webtoon_directory)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ naver_post = ["demjson3"]
lezhin_comics = ["Pillow"]
kakao_webtoon = ["pycryptodomex"]
full = ["demjson3", "Pillow", "pycryptodomex"]
concat = ["Pillow"]

[tool.ruff]
line-length = 120
Expand Down

0 comments on commit 0182963

Please sign in to comment.