Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: report corrupted files

NTFSvolume3bd02497387e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d7feedc2..3fbdbbe30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Reject any download without a valid `Content-Length` header.
+- Report any download with size < `Content-Length` as corrupted and delete them
### Deprecated
diff --git a/cyberdrop_dl/clients/downloads.py b/cyberdrop_dl/clients/downloads.py
index aa9047296..51dc8a7b7 100644
--- a/cyberdrop_dl/clients/downloads.py
+++ b/cyberdrop_dl/clients/downloads.py
@@ -182,10 +182,18 @@ class DownloadClient:
media_item.partial_file.touch()
async def _post_download_check(self, media_item: MediaItem, *_: Any) -> None:
- if not await aio.get_size(media_item.partial_file):
+ size = await aio.get_size(media_item.partial_file)
+ if not size:
await aio.unlink(media_item.partial_file, missing_ok=True)
raise DownloadError(HTTPStatus.INTERNAL_SERVER_ERROR, "File is empty")
+ assert media_item.filesize
+ if size < media_item.filesize:
+ await aio.unlink(media_item.partial_file, missing_ok=True)
+ raise DownloadError(
+ "Corrupted File", f"Expected at least {media_item.filesize:,} bytes but only got {size:,} bytes"
+ )
+
async def download_file(self, domain: str, media_item: MediaItem) -> bool:
"""Starts a file."""
if self.manager.config.settings.download_options.skip_download_mark_completed and not media_item.is_segment: