Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: add `filename` property to response
NTFSvolumef5ad2e690eb2
diff --git a/cyberdrop_dl/clients/response.py b/cyberdrop_dl/clients/response.pyindex 7db1b6f1d..cd9223e88 100644--- a/cyberdrop_dl/clients/response.py+++ b/cyberdrop_dl/clients/response.py@@ -166,17 +166,32 @@ class AbstractResponse(ABC, Generic[_ResponseT]):@final@propertydef content_disposition(self) -> ContentDisposition:+ if cd := self.parse_content_disposition():+ return cd++ msg = f"No content disposition header found in response from {self.url}"+ raise ScrapeError(422, msg) from None++ @final+ def parse_content_disposition(self) -> ContentDisposition | None:try:header = self.headers[hdrs.CONTENT_DISPOSITION]except KeyError:- msg = f"No content disposition header found in response from {self.url}"- raise ScrapeError(422, msg) from None+ return Nonedisposition_type, params = aiohttp.multipart.parse_content_disposition(header)params = MappingProxyType(params)filename = aiohttp.multipart.content_disposition_filename(params)return ContentDisposition(disposition_type, params, filename)+ @final+ @property+ def filename(self) -> str:+ cd = self.parse_content_disposition()+ if cd and cd.raw_filename:+ return cd.raw_filename+ return self.url.name or self.url.parent.name+@final@propertydef aiohttp_resp(self) -> ClientResponse:diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.pyindex be161ff5d..9637685d2 100644--- a/cyberdrop_dl/crawlers/crawler.py+++ b/cyberdrop_dl/crawlers/crawler.py@@ -646,7 +646,7 @@ class Crawler(HTTPMixin, HLSMixin, ABC):return self.get_filename_and_ext(url.name).suffixexcept NoExtensionError:async with self.request(url, method or self.__http_ctx__.probe_method, **kwargs) as resp:- name = url.name or url.parent.name or "file"+ name = resp.filename or "file"return self.get_filename_and_ext(name, mime_type=resp.content_type).suffixdef _prepare_headers(self, scrape_item: ScrapeItem) -> dict[str, str]: