Skip to content

Commit 8bc9f9f

Browse files
committed
feat: image를 불러올 때 잘못된 상태 코드를 받을 경우 오류를 내는 대신 경고만 함
1 parent bb32ee0 commit 8bc9f9f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

WebtoonScraper/scrapers/_scraper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,12 @@ async def _episode_skipped(self, reason: DownloadStatus, description: str, *, no
804804
**context,
805805
)
806806

807-
async def _download_image(self, url: str, directory: Path, name: str, episode_no: int | None = None) -> Path:
807+
async def _download_image(self, url: str, directory: Path, name: str, episode_no: int | None = None) -> Path | None:
808808
try:
809-
response = await self.client.get(url)
809+
response = await self.client.get(url, raise_for_status=False)
810+
if not response.is_success:
811+
logger.warning(f"Failed to fetch an image {name!r}. The image won't be downloaded. (HTTP {response.status_code}): {url}")
812+
return
810813
image_raw: bytes = response.content
811814
file_extension = infer_filetype(response.headers.get("content-type"), image_raw)
812815
image_path = directory / self._safe_name(f"{name}.{file_extension}")
@@ -854,7 +857,7 @@ def _cookie_get(cookie: str | None, key: str) -> str | None:
854857
return result if result is None else result.value
855858
# return {key: morsel.value for key, morsel in parsed.items()}
856859

857-
async def _download_thumbnail(self) -> None | asyncio.Task[Path]:
860+
async def _download_thumbnail(self) -> None | asyncio.Task[Path | None]:
858861
if self.skip_thumbnail_download:
859862
return None
860863

0 commit comments

Comments
 (0)