Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add playmate support
NTFSvolumef1f29809b281
diff --git a/cyberdrop_dl/crawlers/playmate.py b/cyberdrop_dl/crawlers/playmate.pynew file mode 100644index 000000000..c52e289a7--- /dev/null+++ b/cyberdrop_dl/crawlers/playmate.py@@ -0,0 +1,74 @@+from __future__ import annotations++import dataclasses+from typing import TYPE_CHECKING, ClassVar++from cyberdrop_dl import aio+from cyberdrop_dl.crawlers.crawler import API, Crawler, SupportedPaths+from cyberdrop_dl.url_objects import AbsoluteHttpURL+from cyberdrop_dl.utils.errors import error_handling_wrapper++if TYPE_CHECKING:+ from cyberdrop_dl.url_objects import ScrapeItem+++class PlaymateCrawler(Crawler):+ SUPPORTED_PATHS: ClassVar[SupportedPaths] = {+ "Video": (+ "/embed/<video_id>",+ "/watch/<video_id>",+ ),+ }+ DOMAIN: ClassVar[str] = "playmate"+ PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://playmate.to")++ def __post_init__(self) -> None:+ self.api: PlaymateAPI = PlaymateAPI.from_crawler(self)++ async def fetch(self, scrape_item: ScrapeItem) -> None:+ match scrape_item.url.parts[1:]:+ case ["watch" | "embed", video_id]:+ await self.video(scrape_item, video_id)+ case _:+ raise ValueError++ @error_handling_wrapper+ async def video(self, scrape_item: ScrapeItem, video_id: str) -> None:+ embed_url = self.PRIMARY_URL / "embed" / video_id+ if await self.check_complete(embed_url):+ return++ video = await self.api.video(video_id)+ m3u8, info = await self.request_m3u8_playlist(video.m3u8)+ await self.handle_file(+ embed_url,+ scrape_item,+ video.title,+ ext := ".mp4",+ m3u8=m3u8,+ custom_filename=self.create_custom_filename(video.title, ext, resolution=info.resolution),+ thumbnail=video.thumb,+ )++[email protected](slots=True, frozen=True)+class Video:+ id: str+ title: str+ m3u8: AbsoluteHttpURL+ thumb: AbsoluteHttpURL+++class PlaymateAPI(API):+ async def video(self, video_id: str) -> Video:+ stream, meta = await aio.gather(+ self.request_json(self.PRIMARY_URL / "api/s", method="POST", json={"d": "web", "c": video_id}),+ self.request_json((self.PRIMARY_URL / "api/video-meta").with_query(filecode=video_id)),+ fail_fast=False,+ )+ return Video(+ id=video_id,+ title=meta.get("title") or video_id,+ m3u8=self.parse_url(stream["sx"]),+ thumb=self.parse_url(stream["ix"]),+ )diff --git a/tests/crawlers/test_cases/playmate.py b/tests/crawlers/test_cases/playmate.pynew file mode 100644index 000000000..33014dc23--- /dev/null+++ b/tests/crawlers/test_cases/playmate.py@@ -0,0 +1,20 @@+DOMAIN = "playmate"+TEST_CASES = [+ {+ "url": "https://playmate.to/watch/AZDgkEHOPhEvZ",+ "results": [+ {+ "url": "https://playmate.to/embed/AZDgkEHOPhEvZ",+ "filename": "Rashmiix @rmiiix69 - Let me show you my outfit [1920p].mp4",+ "debrid_url": None,+ "original_filename": "Rashmiix @rmiiix69 - Let me show you my outfit",+ "referer": "https://playmate.to/watch/AZDgkEHOPhEvZ",+ "album_id": None,+ "uploaded_at": None,+ "download_folder": "re:Loose Files (Playmate)",+ "thumbnail": "re:/thumbnail/AZDgkEHOPhEvZ.jpg",+ }+ ],+ "count": 1,+ }+]