Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: handle non video files (Mixdrop)
NTFSvolume0287123b5ca4
diff --git a/cyberdrop_dl/crawlers/mixdrop.py b/cyberdrop_dl/crawlers/mixdrop.pyindex 3fae8dafc..7d37e3aa5 100644--- a/cyberdrop_dl/crawlers/mixdrop.py+++ b/cyberdrop_dl/crawlers/mixdrop.py@@ -1,9 +1,11 @@from __future__ import annotations-from typing import TYPE_CHECKING, ClassVar+import asyncio+import dataclasses+from typing import TYPE_CHECKING, ClassVar, override-from cyberdrop_dl import aiofrom cyberdrop_dl.crawlers.crawler import Crawler, SupportedDomains, SupportedPaths+from cyberdrop_dl.exceptions import ScrapeErrorfrom cyberdrop_dl.url_objects import AbsoluteHttpURLfrom cyberdrop_dl.utils import css, js_unpackerfrom cyberdrop_dl.utils.errors import error_handling_wrapper@@ -19,13 +21,15 @@ class MixDropCrawler(Crawler):"File": ("/e/<file_id>","/f/<file_id>",- )+ ),+ "**NOTE**": "Only video files are supported",}- SUPPORTED_DOMAINS: ClassVar[SupportedDomains] = "mxdrop", "mixdrop", "m1xdrop"+ SUPPORTED_DOMAINS: ClassVar[SupportedDomains] = "mxdrop", "mixdrop", "m1xdrop", "miixdrop"PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://mixdrop.sb")DOMAIN: ClassVar[str] = "mixdrop"FOLDER_DOMAIN: ClassVar[str] = "MixDrop"+ @overridedef _prepare_headers(self, scrape_item: ScrapeItem) -> dict[str, str]:return super()._prepare_headers(scrape_item) | {"Referer": "https://m1xdrop.click/"}@@ -42,30 +46,55 @@ class MixDropCrawler(Crawler):if await self.check_complete(embed_url):return- scrape_item.url = embed_url- title, link = await self._request_file_info(file_id)- filename, ext = self.get_filename_and_ext(title)+ file = await self._request_video(file_id)+ _, ext = self.get_filename_and_ext(file.src.name)await self.handle_file(- scrape_item.url,+ embed_url,scrape_item,- title,+ file.title,ext,- custom_filename=filename,- debrid_link=link,- referer=scrape_item.parents[-1] if scrape_item.parents else scrape_item.url,+ custom_filename=self.create_custom_filename(file.title, ext, file_id=file_id),+ debrid_link=file.src,+ referer=scrape_item.get_referer() or scrape_item.url,+ thumbnail=file.thumb,)- async def _request_file_info(self, file_id: str) -> tuple[str, AbsoluteHttpURL]:- video_url = self.PRIMARY_URL / "f" / file_id- embed_url = self.PRIMARY_URL / "e" / file_id+ async def _request_video(self, file_id: str) -> File:+ html = await self.request_text(self.origin / "e" / file_id)+ if _is_not_found(html):+ if _is_not_found(await self.request_text(self.origin / "f" / file_id)):+ raise ScrapeError(404)++ raise ScrapeError(422, "Non video files are not supported")++ return await asyncio.to_thread(_parse_video, file_id, html)++[email protected](slots=True, frozen=True)+class File:+ id: str+ title: str+ src: AbsoluteHttpURL+ thumb: str | None+++def _parse_video(video_id: str, html: str) -> File:+ props = dict(_extract_md_core_props(html))+ return File(+ video_id,+ title=css.select_text(css.soup(html), ".title"),+ src=MixDropCrawler.parse_url(props["wurl"]),+ thumb=props.get("poster"),+ )+- soup, embed_html = await aio.gather(self.request_soup(video_url), self.request_text(embed_url), fail_fast=False)- title = css.select_text(soup, "div.tbl-c.title b")- md_props = dict(_extract_properties(embed_html))- return title, self.parse_url(md_props["wurl"])+def _is_not_found(html: str) -> bool:+ return "WE ARE SORRY" in html and any(+ f"find the {media} you are looking for" in html for media in ("video", "file")+ )-def _extract_properties(html: str) -> Generator[tuple[str, str]]:+def _extract_md_core_props(html: str) -> Generator[tuple[str, str]]:content = js_unpacker.unpack(html)for line in content.split(";MDCore."):name, _, value = line.partition("=")