Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: make Content-Length mandatory
NTFSvolume3013c926534c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ebd847533..5d7feedc2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,22 @@ All notable changes to this project will be documented here. For more details, vThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).+## UNRELEASED++### Added++### Changed++- Reject any download without a valid `Content-Length` header.++### Deprecated++### Removed++### Fixed++### Security+## [9.14.0] - 2026-06-03⚠️**IMPORTANT**diff --git a/cyberdrop_dl/clients/downloads.py b/cyberdrop_dl/clients/downloads.pyindex d799dffab..aa9047296 100644--- a/cyberdrop_dl/clients/downloads.py+++ b/cyberdrop_dl/clients/downloads.py@@ -7,6 +7,8 @@ import timefrom http import HTTPStatusfrom typing import TYPE_CHECKING, Any, final+from aiohttp import hdrs+from cyberdrop_dl import aio, constants, ffmpeg, storagefrom cyberdrop_dl.clients import etagfrom cyberdrop_dl.constants import FileExt@@ -72,7 +74,7 @@ class DownloadClient:resume_point = 0if self._supports_ranges and media_item.partial_file and (size := await aio.get_size(media_item.partial_file)):resume_point = size- media_item.headers["Range"] = f"bytes={size}-"+ media_item.headers[hdrs.RANGE] = f"bytes={size}-"await asyncio.sleep(self.manager.config.global_settings.rate_limiting_options.total_delay)@@ -114,7 +116,7 @@ class DownloadClient:if not media_item.is_segment and (content_type := _get_content_type(resp.headers)):_check_content_type(content_type, media_item.ext)- media_item.filesize = int(resp.headers.get("Content-Length", "0")) or None+ media_item.filesize = int(resp.headers[hdrs.CONTENT_LENGTH])try:_ = media_item.pathexcept AttributeError:@@ -182,7 +184,7 @@ class DownloadClient:async def _post_download_check(self, media_item: MediaItem, *_: Any) -> None:if not await aio.get_size(media_item.partial_file):await aio.unlink(media_item.partial_file, missing_ok=True)- raise DownloadError(HTTPStatus.INTERNAL_SERVER_ERROR, message="File is empty")+ raise DownloadError(HTTPStatus.INTERNAL_SERVER_ERROR, "File is empty")async def download_file(self, domain: str, media_item: MediaItem) -> bool:"""Starts a file."""@@ -246,8 +248,6 @@ class DownloadClient:except Exception:logger.exception(f"Error handling media item completion of: {media_item.path}")- """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""-def get_download_dir(self, media_item: MediaItem) -> Path:"""Returns the download directory for the media item."""download_folder = media_item.download_folder@@ -385,7 +385,7 @@ def _check_content_type(content_type: str, ext: str) -> str | None:def _get_content_type(headers: Mapping[str, str]) -> str | None:- content_type = headers.get("Content-Type")+ content_type = headers.get(hdrs.CONTENT_TYPE)if not content_type:return None@@ -394,7 +394,7 @@ def _get_content_type(headers: Mapping[str, str]) -> str | None:def _get_last_modified(headers: Mapping[str, str]) -> int | None:- if date_str := headers.get("Last-Modified"):+ if date_str := headers.get(hdrs.LAST_MODIFIED):return dates.parse_http(date_str)@@ -402,12 +402,12 @@ def _is_html_or_text(content_type: str) -> bool:return any(s in content_type for s in ("html", "text"))-def _check_content_length(headers: Mapping[str, Any]) -> None:- content_length, content_type = headers.get("Content-Length"), headers.get("Content-Type")- if content_length is None or content_type is None:+def _check_content_length(headers: Mapping[str, str]) -> None:+ content_length, content_type = headers[hdrs.CONTENT_LENGTH], headers.get(hdrs.CONTENT_TYPE)+ if content_type is None:returnif content_length == "322509" and content_type == "video/mp4":- raise DownloadError(status="Bunkr Maintenance", message="Bunkr under maintenance")+ raise DownloadError("Bunkr Maintenance", "Bunkr under maintenance")if content_length == "73003" and content_type == "video/mp4":raise DownloadError(410) # Placeholder video with text "Video removed" (efukt)diff --git a/cyberdrop_dl/downloader/http.py b/cyberdrop_dl/downloader/http.pyindex ee2c5f7f0..dceb1ab33 100644--- a/cyberdrop_dl/downloader/http.py+++ b/cyberdrop_dl/downloader/http.py@@ -130,9 +130,6 @@ class Downloader:if not e.retry:raise- if e.status != 999:- media_item.attempts += 1-logger.error(f"{self.log_prefix} failed: {media_item.url} with error: {e!s}")if media_item.attempts >= self.max_attempts:raise@@ -141,7 +138,7 @@ class Downloader:f"Retrying {self.log_prefix.lower()}: {media_item.url}, retry attempt: {media_item.attempts + 1}")- async def _finalize_download(self, media_item: MediaItem) -> None:+ async def __finalize_download(self, media_item: MediaItem) -> None:await aio.chmod(media_item.path, 0o666)if media_item.is_segment:return@@ -168,7 +165,7 @@ class Downloader:return bool(await self.__download_w_retries(media_item))@contextlib.asynccontextmanager- async def _download_context(self, media_item: MediaItem) -> AsyncGenerator[None]:+ async def __download_context(self, media_item: MediaItem) -> AsyncGenerator[None]:await self.client.mark_incomplete(media_item, media_item.domain)if media_item.is_segment:yield@@ -217,7 +214,7 @@ class Downloader:else:if downloaded:- await self._finalize_download(media_item)+ await self.__finalize_download(media_item)return downloaded@contextlib.asynccontextmanager@@ -234,7 +231,7 @@ class Downloader:if media_item.url.path in self._processed_items and not self._ignore_history:return False- async with self._download_context(media_item):+ async with self.__download_context(media_item):return await self._download(media_item)@error_handling_wrapper@@ -243,7 +240,7 @@ class Downloader:returnassert ffmpeg.is_installed()- async with self._download_context(media_item):+ async with self.__download_context(media_item):await self.__hls_download(media_item, m3u8_group)async def __hls_download(self, media_item: MediaItem, rendition: Rendition) -> None:@@ -276,7 +273,7 @@ class Downloader:await self.client.process_completed(media_item, media_item.domain)await self.client.handle_media_item_completion(media_item, downloaded=True)- await self._finalize_download(media_item)+ await self.__finalize_download(media_item)def _is_allowed_filetype(media_item: MediaItem, config: Config) -> bool: