Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add support for tags
NTFSvolume81dd064c3223
diff --git a/cyberdrop_dl/crawlers/beeg.py b/cyberdrop_dl/crawlers/beeg.pyindex 871f83d64..60b6ca41f 100644--- a/cyberdrop_dl/crawlers/beeg.py+++ b/cyberdrop_dl/crawlers/beeg.py@@ -1,25 +1,37 @@from __future__ import annotationsimport dataclasses+import itertoolsfrom typing import TYPE_CHECKING, Any, ClassVar, Finalfrom cyberdrop_dl.clients.http import HTTPConfigfrom cyberdrop_dl.crawlers.crawler import API, Crawler, SupportedPaths+from cyberdrop_dl.exceptions import ScrapeErrorfrom cyberdrop_dl.url_objects import AbsoluteHttpURL-from cyberdrop_dl.utils import datesfrom cyberdrop_dl.utils.errors import error_handling_wrapperif TYPE_CHECKING:+ from collections.abc import AsyncGenerator, Mapping+from cyberdrop_dl.url_objects import ScrapeItem+_VIDEO: Final = AbsoluteHttpURL("https://video.beeg.com")+_THUMBS: Final = AbsoluteHttpURL("https://thumbs.externulls.com")+_STORE: Final = AbsoluteHttpURL("https://store.externulls.com")++@HTTPConfig(rate_limit=(4, 1))class BeegComCrawler(Crawler):SUPPORTED_PATHS: ClassVar[SupportedPaths] = {"Video": (- "/<video_id>",- "/video/<video_id>",- )+ "/-<video_id>",+ "/video/-<video_id>",+ ),+ "Tags / Network / Model": (+ "/<tag>",+ "/<tag_1>+<tag_2>",+ ),}DOMAIN: ClassVar[str] = "beeg.com"PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://beeg.com")@@ -29,9 +41,15 @@ class BeegComCrawler(Crawler):async def fetch(self, scrape_item: ScrapeItem) -> None:match scrape_item.url.parts[1:]:- case [video_id]:- video_id = int(video_id.removeprefix("-"))- await self.video(scrape_item, video_id)+ case ["reacted", "saved", "following"]:+ raise ValueError++ case [slug]:+ if slug.startswith("-"):+ video_id = int(slug.lstrip("-"))+ await self.video(scrape_item, video_id)+ else:+ await self.tags(scrape_item, slug)case _:raise ValueError@@ -40,7 +58,7 @@ class BeegComCrawler(Crawler):url = super().transform_url(url)match url.parts[1:]:case ["video", video_id]:- return url.origin() / video_id+ return url.origin() / _video_slug(video_id)case _:return url@@ -50,8 +68,18 @@ class BeegComCrawler(Crawler):returnvideo = await self.api.video(video_id)+ await self._video(scrape_item, video)++ @error_handling_wrapper+ async def _video_task(self, scrape_item: ScrapeItem, video: Video) -> None:+ if await self.check_complete_from_referer(scrape_item.url):+ return++ await self._video(scrape_item, video)++ async def _video(self, scrape_item: ScrapeItem, video: Video) -> None:scrape_item.uploaded_at = video.created_at- m3u8, info = await self.request_m3u8_playlist(video.m3u8)+ m3u8, info = await self.request_m3u8_playlist(video.m3u8, headers={"Referer": str(scrape_item.url)})await self.handle_file(scrape_item.url,scrape_item,@@ -69,6 +97,42 @@ class BeegComCrawler(Crawler):thumbnail=video.thumb,)+ @error_handling_wrapper+ async def tags(self, scrape_item: ScrapeItem, slug: str) -> None:+ tags = slug.split("+")+ scrape_item.setup_as_album(self.create_title(slug))++ found_videos: bool = False+ async for videos in self.api.tag_videos(*tags):+ for video in videos:+ found_videos = True+ new_item = scrape_item.create_child(self.PRIMARY_URL / _video_slug(video.id))+ self.create_task(self._video_task(new_item, video))+ scrape_item.add_children()++ if not found_videos:+ raise ScrapeError(404)+++class BeegAPI(API):+ async def video(self, video_id: int) -> Video:+ resp: dict[str, Any] = await self.request_json(_STORE / f"facts/file/{video_id}")+ return _parse_video(resp)++ async def tag(self, slug: str) -> dict[str, Any]:+ url = (_STORE / "tag").with_query(slug=slug, get_original="true")+ resp = await self.request_json(url)+ return _normalize_tag(resp)++ async def tag_videos(self, *tags: str) -> AsyncGenerator[map[Video]]:+ limit = 48+ url = (_STORE / "tag/videos" / ",".join(tags)).with_query(limit=limit)+ for offset in itertools.count(0, limit):+ resp = await self.request_json(url.update_query(offset=offset))+ yield map(_parse_video, resp)+ if len(resp) < limit:+ break+@dataclasses.dataclass(order=True, frozen=True, slots=True)class Video:@@ -77,23 +141,42 @@ class Video:created_at: intthumb: AbsoluteHttpURLm3u8: AbsoluteHttpURL+ tags: tuple[dict[str, Any], ...]-class BeegAPI(API):- VIDEO: Final = AbsoluteHttpURL("https://video.beeg.com")- STORE: Final = AbsoluteHttpURL("https://store.externulls.com")- THUMBS: Final = AbsoluteHttpURL("https://thumbs.externulls.com")+def _video_slug(video_id: str | int) -> str:+ return f"-{str(video_id).lstrip('-').zfill(16)}"- async def video(self, video_id: int) -> Video:- resp: dict[str, Any] = await self.request_json(self.STORE / f"facts/file/{video_id}")- facts: dict[str, Any] = min(resp["fc_facts"], key=lambda x: int(x["id"]))- file: dict[str, Any] = resp["file"]- thumb = next(iter(facts["fc_thumbs"]), 0)-- return Video(- id=video_id,- title=next(data for data in file["data"] if data.get("cd_file") == video_id)["cd_value"],- created_at=int(dates.parse_iso(facts["fc_created"]).timestamp()),- thumb=self.THUMBS / f"videos/{video_id}/{thumb}.webp",- m3u8=self.VIDEO / file["hls_resources"]["fl_cdn_multi"],- )++def _normalize_tag(resp: Mapping[str, Any]) -> dict[str, Any]:+ tag = _filter_by_prefix(resp, "tg_")+ tag["description"] = next((d["td_value"] for d in resp["data"] if d["td_tag"] == tag["id"]), None)+ tag["links"] = [_normalize_link(link) for link in resp.get("links", ())]+ tag["mother_brand"] = _normalize_tag(mb) if (mb := resp.get("mother_brand")) else None+ return tag+++def _normalize_link(data: Mapping[str, Any]) -> dict[str, Any]:+ link = _filter_by_prefix(data, "tk_")+ link["type"] = _filter_by_prefix(data["type"], "tt_")+ return link+++def _filter_by_prefix(data: Mapping[str, Any], prefix: str) -> dict[str, Any]:+ return {k.removeprefix(prefix): v for k, v in data.items() if k == "id" or k.startswith(prefix)}+++def _parse_video(video: dict[str, Any]) -> Video:+ facts: dict[str, Any] = min(video["fc_facts"], key=lambda x: int(x["id"]))+ file: dict[str, Any] = video["file"]+ thumb: int = next(iter(facts["fc_thumbs"]), 0)+ video_id = int(file["id"])++ return Video(+ id=video_id,+ title=next(d for d in file["data"] if d.get("cd_file") == video_id)["cd_value"],+ created_at=int(Crawler.parse_iso_date(facts["fc_created"])),+ thumb=_THUMBS / f"videos/{video_id}/{thumb}.webp",+ m3u8=_VIDEO / file["hls_resources"]["fl_cdn_multi"],+ tags=tuple(map(_normalize_tag, video.get("tags", ()))),+ )diff --git a/tests/crawlers/test_cases/beeg_com.py b/tests/crawlers/test_cases/beeg_com.pyindex 7dffc92a0..80e67453c 100644--- a/tests/crawlers/test_cases/beeg_com.py+++ b/tests/crawlers/test_cases/beeg_com.py@@ -17,4 +17,66 @@ TEST_CASES = [],"count": 1,},+ {+ "url": "https://beeg.com/BrattySis+ElizaIbarra",+ "description": "multiple tags",+ "results": [+ {+ "url": "https://beeg.com/-0119433079661245",+ "filename": "Easter Creampie Surprise Compilation [119433079661245][avc1][mp4a][1080p].mp4",+ "debrid_url": None,+ "original_filename": "Easter Creampie Surprise Compilation",+ "referer": "https://beeg.com/-0119433079661245",+ "album_id": None,+ "uploaded_at": 1744416000,+ "download_folder": "re:BrattySis+ElizaIbarra (Beeg.com)",+ "thumbnail": "https://thumbs.externulls.com/videos/119433079661245/0.webp",+ },+ {+ "url": "https://beeg.com/-0874719598932310",+ "filename": "Big Booty Step Sis Eliza Ibarra Fucking Step Bro on Ea [874719598932310][avc1][mp4a][1080p].mp4",+ "debrid_url": None,+ "original_filename": "Big Booty Step Sis Eliza Ibarra Fucking Step Bro on Easter",+ "referer": "https://beeg.com/-0874719598932310",+ "album_id": None,+ "uploaded_at": 1585958400,+ "download_folder": "re:BrattySis+ElizaIbarra (Beeg.com)",+ "thumbnail": "https://thumbs.externulls.com/videos/874719598932310/0.webp",+ },+ {+ "url": "https://beeg.com/-0920267319838605",+ "filename": "Easter Bunny Cosplay Compilation [920267319838605][hevc][mp4a][1080p].mp4",+ "debrid_url": None,+ "original_filename": "Easter Bunny Cosplay Compilation",+ "referer": "https://beeg.com/-0920267319838605",+ "album_id": None,+ "uploaded_at": 1774828800,+ "download_folder": "re:BrattySis+ElizaIbarra (Beeg.com)",+ "thumbnail": "https://thumbs.externulls.com/videos/920267319838605/0.webp",+ },+ {+ "url": "https://beeg.com/-0978857425569648",+ "filename": "Step Sis its so Much Bigger than I Imagined Easter Bunn [978857425569648][avc1][mp4a][720p].mp4",+ "debrid_url": None,+ "original_filename": 'Step Sis "it\'s so Much Bigger than I Imagined" Easter Bunny Fuck',+ "referer": "https://beeg.com/-0978857425569648",+ "album_id": None,+ "uploaded_at": 1585958400,+ "download_folder": "re:BrattySis+ElizaIbarra (Beeg.com)",+ "thumbnail": "https://thumbs.externulls.com/videos/978857425569648/0.webp",+ },+ {+ "url": "https://beeg.com/-0406392139599987",+ "filename": "Bunny Cosplay Compilation [406392139599987][hevc][mp4a][1080p].mp4",+ "debrid_url": None,+ "original_filename": "Bunny Cosplay Compilation",+ "referer": "https://beeg.com/-0406392139599987",+ "album_id": None,+ "uploaded_at": 1775433600,+ "download_folder": "re:BrattySis+ElizaIbarra (Beeg.com)",+ "thumbnail": "https://thumbs.externulls.com/videos/406392139599987/0.webp",+ },+ ],+ "count": 5,+ },]