Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: use our own content disposition
NTFSvolumede404f05b939
diff --git a/cyberdrop_dl/clients/response.py b/cyberdrop_dl/clients/response.pyindex 4a8b7fc66..5a3251e28 100644--- a/cyberdrop_dl/clients/response.py+++ b/cyberdrop_dl/clients/response.py@@ -9,8 +9,7 @@ from types import MappingProxyTypefrom typing import TYPE_CHECKING, Any, Generic, Literal, Self, finalimport aiohttp.multipart-from aiohttp import hdrs-from aiohttp.client_reqrep import ClientResponse, ContentDisposition+from aiohttp import ClientResponse, hdrsfrom bs4 import BeautifulSoupfrom multidict import CIMultiDict, CIMultiDictProxyfrom propcache import under_cached_property@@ -28,7 +27,8 @@ if TYPE_CHECKING:else:- CurlResponse = object++ class CurlResponse: ...__all__ = ["AbstractResponse"]@@ -40,6 +40,21 @@ _ResponseT = TypeVar()[email protected](slots=True, frozen=True)+class ContentDisposition:+ type: str | None+ parameters: MappingProxyType[str, str]+ raw_filename: str | None++ @property+ def filename(self) -> str:+ if name := self.raw_filename:+ return name++ msg = "Content disposition has no filename information"+ raise ScrapeError(422, msg)++@dataclasses.dataclass(slots=True)class AbstractResponse(ABC, Generic[_ResponseT]):"""@@ -114,20 +129,12 @@ class AbstractResponse(ABC, Generic[_ResponseT]):except KeyError:msg = f"No content disposition header found in response from {self.url}"raise ScrapeError(422, msg) from None+disposition_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:- if name := self.content_disposition.filename:- return name-- msg = "Content disposition has no filename information"- raise ScrapeError(422, msg)-@propertydef consumed(self) -> bool:return bool(self._text)diff --git a/cyberdrop_dl/crawlers/buzzheavier.py b/cyberdrop_dl/crawlers/buzzheavier.pyindex a73104fa8..0654a6851 100644--- a/cyberdrop_dl/crawlers/buzzheavier.py+++ b/cyberdrop_dl/crawlers/buzzheavier.py@@ -35,7 +35,7 @@ class BuzzHeavierCrawler(Crawler):"HX-Request": "true",},) as resp:- filename: str = resp.filename+ filename = resp.content_disposition.filenamelink = self.parse_url(resp.headers["hx-redirect"])filename, ext = self.get_filename_and_ext(filename, assume_ext=".zip")diff --git a/cyberdrop_dl/crawlers/dropbox.py b/cyberdrop_dl/crawlers/dropbox.pyindex c4e95cc99..027c81786 100644--- a/cyberdrop_dl/crawlers/dropbox.py+++ b/cyberdrop_dl/crawlers/dropbox.py@@ -78,7 +78,7 @@ class DropboxCrawler(Crawler):async def file(self, scrape_item: ScrapeItem) -> None:scrape_item.url = await self._ensure_rlkey(scrape_item.url)async with self.request(scrape_item.url.update_query(dl=1)) as resp:- self._file(scrape_item, resp.filename)+ self._file(scrape_item, resp.content_disposition.filename)def _file(self, scrape_item: ScrapeItem, filename: str) -> None:scrape_item.url = view_url = scrape_item.url.with_query(rlkey=scrape_item.url.query["rlkey"], dl=0)diff --git a/cyberdrop_dl/crawlers/google_drive.py b/cyberdrop_dl/crawlers/google_drive.pyindex 7556f2b0a..13f85b878 100644--- a/cyberdrop_dl/crawlers/google_drive.py+++ b/cyberdrop_dl/crawlers/google_drive.py@@ -192,7 +192,7 @@ class GoogleDriveCrawler(Crawler):async with self.request(export_url, method=method) as resp:assert resp.ok and "html" not in resp.content_type- return resp.url, resp.filename+ return resp.url, resp.content_disposition.filenamedef _get_proper_doc_format(doc: str, format: str | None) -> str:diff --git a/cyberdrop_dl/crawlers/patreon.py b/cyberdrop_dl/crawlers/patreon.pyindex 1794b0528..bd10a6e31 100644--- a/cyberdrop_dl/crawlers/patreon.py+++ b/cyberdrop_dl/crawlers/patreon.py@@ -80,7 +80,7 @@ class PatreonCrawler(Crawler):name = asset.nameif not name:async with self.request(asset.url) as resp:- name = resp.filename+ name = resp.content_disposition.filenamefilename, ext = self.get_filename_and_ext(name)await self.handle_file(asset.url, scrape_item, filename, ext)