Skip to content

Commit edd477a

Browse files
committed
feat: Scraper.get_episode_image_urls가 Callback을 리턴할 수 있도록 함
1 parent cceb19a commit edd477a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

WebtoonScraper/scrapers/_scraper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def extra_info_scraper(self, extra: ExtraInfoScraper | None) -> None:
273273
extra.register(self)
274274

275275
@abstractmethod
276-
async def get_episode_image_urls(self, episode_no: int) -> list[str] | None:
276+
async def get_episode_image_urls(self, episode_no: int) -> list[str] | None | Callback:
277277
"""해당 회차를 구성하는 이미지들의 URL을 불러옵니다."""
278278
raise NotImplementedError
279279

@@ -844,7 +844,7 @@ async def _download_episode(self, episode_no: int, webtoon_directory: Path) -> N
844844
# fetch image urls
845845
time.sleep(self.download_interval) # 실질적인 외부 요청을 보내기 직전에만 interval을 넣음.
846846
try:
847-
image_urls = await self.get_episode_image_urls(episode_no) # TODO: Callback을 리턴할 경우 그 것을 failed의 메시지로 사용하는 것을 구현할 것
847+
image_urls = await self.get_episode_image_urls(episode_no)
848848
# 기본적으로 get_episode_image_urls는 실패해서는 안 된다.
849849
# 그런 상황이 있을 경우 warning을 내부적으로 내보내며 None을 리턴해야 한다.
850850
# 따라서 다른 경우들과 달리 raise를 하는 것이다.
@@ -853,21 +853,21 @@ async def _download_episode(self, episode_no: int, webtoon_directory: Path) -> N
853853
await self.async_callback("get_episode_images_failed", **context)
854854
raise
855855

856-
if not image_urls:
856+
if isinstance(image_urls, Callback) or not image_urls:
857+
callback = image_urls if isinstance(image_urls, Callback) else None
857858
with suppress(Exception):
858859
episode_directory.rmdir()
859860
self.download_status[episode_no] = "failed"
860861
await self.async_callback(
861862
"download_failed",
862-
_crate_callback(
863+
callback or _crate_callback(
863864
"The episode #{episode_no} '{short_ep_title}' is failed {description}",
864865
progress_update="{short_ep_title} skipped",
865866
level="warning",
866867
log_with_progress=True,
867868
),
868869
reason="gathering_images_failed",
869870
description="because no images are found",
870-
warning=True, # todo
871871
**context,
872872
)
873873
return

0 commit comments

Comments
 (0)