[BACKEND] Add URL thumbnail download timeout (#367)
This commit is contained in:
parent
954dc0f3ee
commit
9f5ee153b7
2 changed files with 4 additions and 3 deletions
|
|
@ -646,7 +646,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (thumbnail_url := parent.get_thumbnail_url(thumbnail_id=thumbnail_id)) is None:
|
if (thumbnail_url := parent.get_thumbnail_url(thumbnail_id=thumbnail_id)) is None:
|
||||||
download_logger.warning("TODO: Failed to download channel's avatar image")
|
download_logger.warning("Failed to find thumbnail id '%s'", thumbnail_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self._download_thumbnail(
|
if self._download_thumbnail(
|
||||||
|
|
@ -656,7 +656,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC):
|
||||||
self.save_file(file_name=thumbnail_name)
|
self.save_file(file_name=thumbnail_name)
|
||||||
thumbnails_downloaded.add(thumbnail_name)
|
thumbnails_downloaded.add(thumbnail_name)
|
||||||
else:
|
else:
|
||||||
download_logger.warning("TODO: Failed to download channel's avatar image")
|
download_logger.warning("Failed to download thumbnail id '%s'", thumbnail_id)
|
||||||
|
|
||||||
return thumbnails_downloaded
|
return thumbnails_downloaded
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,8 @@ def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> Opt
|
||||||
-------
|
-------
|
||||||
True to indicate it converted the thumbnail from url. None if the retry failed.
|
True to indicate it converted the thumbnail from url. None if the retry failed.
|
||||||
"""
|
"""
|
||||||
with urlopen(thumbnail_url) as file:
|
# timeout after 8 seconds
|
||||||
|
with urlopen(thumbnail_url, timeout=8.0) as file:
|
||||||
with tempfile.NamedTemporaryFile() as thumbnail:
|
with tempfile.NamedTemporaryFile() as thumbnail:
|
||||||
thumbnail.write(file.read())
|
thumbnail.write(file.read())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue