Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: update old crawlers
NTFSvolumed1c80b765a60
diff --git a/cyberdrop_dl/crawlers/ashemaletube.py b/cyberdrop_dl/crawlers/ashemaletube.pyindex d45b21577..912c45ab9 100644--- a/cyberdrop_dl/crawlers/ashemaletube.py+++ b/cyberdrop_dl/crawlers/ashemaletube.py@@ -2,22 +2,23 @@ from __future__ import annotationsimport jsonfrom enum import StrEnum-from typing import TYPE_CHECKING, ClassVar+from typing import TYPE_CHECKING, ClassVar, finalfrom cyberdrop_dl.clients.http import HTTPConfig-from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths+from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths, URLConfigfrom cyberdrop_dl.exceptions import ScrapeErrorfrom cyberdrop_dl.url_objects import AbsoluteHttpURL-from cyberdrop_dl.utils import css, extr_text, json_ld, m3u8+from cyberdrop_dl.utils import css, extr_text, json_ld+from cyberdrop_dl.utils._url import remove_trailing_slashfrom cyberdrop_dl.utils.errors import error_handling_wrapperif TYPE_CHECKING:from bs4 import BeautifulSoup, Tag- from cyberdrop_dl.mediaprops import Resolutionfrom cyberdrop_dl.url_objects import ScrapeItem+@finalclass Selector:PROFILE_VIDEOS = "div.sub-content div.media-item__inner > a[data-video-preview]"SEARCH_VIDEOS = "div.main-content div.media-item__inner > a[data-video-preview]"@@ -25,9 +26,9 @@ class Selector:PLAYLIST_VIDEOS = "a.playlist-video-item__thumbnail"JS_PLAYER = "script:-soup-contains('var playerConfig =')"LOGIN_REQUIRED = "div.loginLinks:-soup-contains('To watch this video please')"- IMAGE_ITEM = "div.imgItem"+ IMAGE_ITEM = ".main-content .imgItem"ALBUM_IMAGES = "div.gallery-detail div.thumb"- ALBUM_TITLE = "div.prepositions-wrapper h1"+ TITLE = ".content-title-row h1"GALLERY_ALBUM = "div.profile-content div.galItem > a"NEXT_PAGE = "a.rightKey"@@ -49,7 +50,7 @@ MEDIA_SELECTOR_MAP = {}TITLE_SELECTOR_MAP = {- CollectionType.ALBUM: Selector.ALBUM_TITLE,+ CollectionType.ALBUM: Selector.TITLE,CollectionType.MODEL: Selector.USER_NAME,CollectionType.PLAYLIST: "h1",CollectionType.SEARCH: "h1",@@ -60,7 +61,8 @@ TITLE_TRASH = "Shemale Porn Videos - Trending"PRIMARY_URL = AbsoluteHttpURL("https://www.ashemaletube.com")-@HTTPConfig(rate_limit=(3, 10))+@HTTPConfig(rate_limit=(3, 10), impersonate=True)+@URLConfig(trim=False)class AShemaleTubeCrawler(Crawler):SUPPORTED_PATHS: ClassVar[SupportedPaths] = {"Playlist": "/playlists/...",@@ -73,62 +75,63 @@ class AShemaleTubeCrawler(Crawler):PRIMARY_URL: ClassVar[AbsoluteHttpURL] = PRIMARY_URLNEXT_PAGE_SELECTOR: ClassVar[str] = Selector.NEXT_PAGE- async def fetch(self, scrape_item: ScrapeItem) -> None: # noqa: PLR0911- if any(p in scrape_item.url.parts for p in ("creators", "profiles", "pornstars", "model")):- if "galleries" in scrape_item.url.parts:- return await self.gallery(scrape_item)- return await self.collection(scrape_item, CollectionType.MODEL)- if "videos" in scrape_item.url.parts:- return await self.video(scrape_item)- if "playlists" in scrape_item.url.parts:- return await self.collection(scrape_item, CollectionType.PLAYLIST)- if "search" in scrape_item.url.parts:- return await self.collection(scrape_item, CollectionType.SEARCH)- if "images" in scrape_item.url.parts:- return await self.direct_file(scrape_item, scrape_item.url.with_query(None))- if "pics" in scrape_item.url.parts:- if len(scrape_item.url.parts) >= 5:- return await self.image(scrape_item)- return await self.album(scrape_item)- if "cam" in scrape_item.url.parts:- raise ValueError- raise ValueError+ async def fetch(self, scrape_item: ScrapeItem) -> None:+ match remove_trailing_slash(scrape_item.url).parts[1:]:+ case ["videos", video_id, *_]:+ await self.video(scrape_item, video_id)+ case ["playlists", _playlist_id, *_]:+ await self.collection(scrape_item, CollectionType.PLAYLIST)+ case ["search", *_] if "q" in scrape_item.url.query:+ await self.collection(scrape_item, CollectionType.SEARCH)+ case ["images", *_]:+ await self.direct_file(scrape_item, scrape_item.url.with_query(None))+ case ["pics", _id, _slug, *rest]:+ if rest:+ await self.image(scrape_item)+ else:+ await self.album(scrape_item)+ case ["creators" | "profiles" | "pornstars" | "model" as _kind, _, *rest]:+ match rest:+ case ["galleries", *_]:+ await self.gallery(scrape_item)+ case _:+ await self.collection(scrape_item, CollectionType.MODEL)+ case _:+ raise ValueError@error_handling_wrapperasync def gallery(self, scrape_item: ScrapeItem) -> None:- async for soup in self.web_pager(scrape_item.url, impersonate=True):+ async for soup in self.web_pager(scrape_item.url):for new_scrape_item in self.iter_children(scrape_item, soup, Selector.GALLERY_ALBUM):self.create_task(self.run(new_scrape_item))@error_handling_wrapperasync def album(self, scrape_item: ScrapeItem) -> None:- album_title = ""- async for soup in self.web_pager(scrape_item.url, impersonate=True):- if not album_title:- album_title = self.create_collection_title(soup, CollectionType.ALBUM)- scrape_item.setup_as_album(album_title)+ name = ""+ async for soup in self.web_pager(scrape_item.url):+ if not name:+ name = self._create_collection_title(soup, CollectionType.ALBUM)+ scrape_item.setup_as_album(name)for thumb in soup.select(MEDIA_SELECTOR_MAP[CollectionType.ALBUM]):- await self.proccess_image(scrape_item, thumb)+ await self._image(scrape_item, thumb)@error_handling_wrapperasync def collection(self, scrape_item: ScrapeItem, collection_type: CollectionType) -> None:collection_title = ""- async for soup in self.web_pager(scrape_item.url, impersonate=True):+ async for soup in self.web_pager(scrape_item.url):if not collection_title:- collection_title = self.create_collection_title(soup, collection_type)+ collection_title = self._create_collection_title(soup, collection_type)if collection_type == CollectionType.MODEL:scrape_item.setup_as_profile(collection_title)else:scrape_item.setup_as_album(collection_title)- for new_scrape_item in self.iter_children(scrape_item, soup, MEDIA_SELECTOR_MAP[collection_type]):- self.create_task(self.run(new_scrape_item))- def create_collection_title(self, soup: BeautifulSoup, collection_type: CollectionType) -> str:- title_elem = soup.select_one(TITLE_SELECTOR_MAP[collection_type])- if not title_elem:- raise ScrapeError(401)- collection_title: str = title_elem.get_text(strip=True)+ for new_item in self.iter_children(scrape_item, soup, MEDIA_SELECTOR_MAP[collection_type]):+ self.create_task(self.run(new_item))++ def _create_collection_title(self, soup: BeautifulSoup, collection_type: CollectionType) -> str:+ collection_title: str = css.select_text(soup, TITLE_SELECTOR_MAP[collection_type])collection_title = collection_title.replace(TITLE_TRASH, "").strip()return self.create_title(f"{collection_title} [{collection_type}]")@@ -136,59 +139,59 @@ class AShemaleTubeCrawler(Crawler):async def image(self, scrape_item: ScrapeItem) -> None:if await self.check_complete_from_referer(scrape_item.url):return- soup = await self.request_soup(scrape_item.url, impersonate=True)- img_item = soup.select_one(Selector.IMAGE_ITEM)- if not img_item:- raise ScrapeError(404)- await self.proccess_image(scrape_item, img_item)++ soup = await self.request_soup(scrape_item.url)+ img = css.select(soup, Selector.IMAGE_ITEM)+ src = self.parse_url(css.select(img, ".image-box img", "src")).with_query(None)+ _, ext = self.get_filename_and_ext(src.name)+ await self.handle_file(+ src,+ scrape_item,+ src.name,+ ext,+ custom_filename=self.create_custom_filename(_, ext, file_id=css.attr(img, "data-image-id")),+ )@error_handling_wrapper- async def proccess_image(self, scrape_item: ScrapeItem, img_tag: Tag) -> None:- if image := img_tag.select_one("img"):+ async def _image(self, scrape_item: ScrapeItem, img_tag: Tag) -> None:+ if image := img_tag.select_one(".image-box img"):link_str: str = css.attr(image, "src")else:style: str = css.select(img_tag, "a", "style")link_str = extr_text(style, "url('", "');")+url = self.parse_url(link_str).with_query(None)filename, ext = self.get_filename_and_ext(url.name)custom_filename = self.create_custom_filename(filename, ext, file_id=css.attr(img_tag, "data-image-id"))await self.handle_file(url, scrape_item, filename, ext, custom_filename=custom_filename)@error_handling_wrapper- async def video(self, scrape_item: ScrapeItem) -> None:- video_id: str = scrape_item.url.parts[2]+ async def video(self, scrape_item: ScrapeItem, video_id: str) -> None:canonical_url = PRIMARY_URL / "videos" / video_idif await self.check_complete_from_referer(canonical_url):- return None-- soup = await self.request_soup(scrape_item.url, impersonate=True)+ return+ soup = await self.request_soup(scrape_item.url)if soup.select_one(Selector.LOGIN_REQUIRED):raise ScrapeError(401)- js_text = css.select_text(soup, Selector.JS_PLAYER)- resolution, url, m3u8 = await self.parse_player_info(js_text)scrape_item.uploaded_at = json_ld.upload_date(soup, validate={"@type": "VideoObject"})-- title = css.select_text(soup, "title").split("- aShemaletube.com")[0].strip()+ title = css.select_text(soup, Selector.TITLE)scrape_item.url = canonical_url- filename, ext = self.get_filename_and_ext(url.name, assume_ext=".mp4")- custom_filename = self.create_custom_filename(title, ext, file_id=video_id, resolution=resolution)+ m3u8, info = await self.request_m3u8_playlist(_extr_hls_src(soup))- return await self.handle_file(+ await self.handle_file(canonical_url,scrape_item,- filename,- ext,- custom_filename=custom_filename,+ title,+ ext := ".mp4",+ custom_filename=self.create_custom_filename(title, ext, file_id=video_id, resolution=info.resolution),m3u8=m3u8,)- async def parse_player_info(self, script_text: str) -> tuple[Resolution, AbsoluteHttpURL, m3u8.Rendition]:- sources = extr_text(script_text, "sources: ", "aspectRatio").strip().strip(",")- sources_data = json.loads(sources)- url = self.parse_url(sources_data["hlsAuto"])-- rendition, playlist_info = await self.request_m3u8_playlist(url)- return playlist_info.resolution, url, rendition+def _extr_hls_src(soup: BeautifulSoup) -> AbsoluteHttpURL:+ player = css.select_text(soup, Selector.JS_PLAYER)+ sources = extr_text(player, "sources: ", "aspectRatio").strip().strip(",")+ sources_data = json.loads(sources)+ return AShemaleTubeCrawler.parse_url(sources_data["hlsAuto"])diff --git a/cyberdrop_dl/crawlers/nudostartv.py b/cyberdrop_dl/crawlers/nudostartv.pyindex 6f2f97842..c753e5895 100644--- a/cyberdrop_dl/crawlers/nudostartv.py+++ b/cyberdrop_dl/crawlers/nudostartv.py@@ -3,8 +3,7 @@ from __future__ import annotationsfrom typing import TYPE_CHECKING, ClassVarfrom cyberdrop_dl import aio-from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths-from cyberdrop_dl.exceptions import ScrapeError+from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths, URLConfigfrom cyberdrop_dl.url_objects import AbsoluteHttpURLfrom cyberdrop_dl.utils import cssfrom cyberdrop_dl.utils.errors import error_handling_wrapper@@ -18,34 +17,36 @@ class Selector:CONTENT = "div[id=list_videos_common_videos_list_items] div a"+@URLConfig(trim=False)class NudoStarTVCrawler(Crawler):- SUPPORTED_PATHS: ClassVar[SupportedPaths] = {"Model": "/models/..."}+ SUPPORTED_PATHS: ClassVar[SupportedPaths] = {+ "Model": "/models/<name>",+ "Image": "/models/<name>/<img_id>",+ }PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://nudostar.tv")NEXT_PAGE_SELECTOR: ClassVar[str] = "li[class=next] a"DOMAIN: ClassVar[str] = "nudostar.tv"FOLDER_DOMAIN: ClassVar[str] = "NudoStarTV"async def fetch(self, scrape_item: ScrapeItem) -> None:- if "models" not in scrape_item.url.parts:- raise ValueError- if scrape_item.url.name:- scrape_item.url /= ""- if len(scrape_item.url.parts) > 4:- return await self.image(scrape_item)- await self.model(scrape_item)+ match scrape_item.url.parts[1:]:+ case ["models", _, _, *rest]:+ if rest:+ await self.image(scrape_item)+ else:+ await self.model(scrape_item)+ case _:+ raise ValueError@error_handling_wrapperasync def model(self, scrape_item: ScrapeItem) -> None:soup, pages = await aio.peek_first(self.web_pager(scrape_item.url))- title = self.create_title(css.select(soup, "title").get_text().split("/")[0])- scrape_item.setup_as_album(title)+ scrape_item.setup_as_album("")- if "Last OnlyFans Updates" in title or not soup.select_one(Selector.CONTENT):- raise ScrapeError(404)-- async for soup in pages:- for new_scrape_item in self.iter_children(scrape_item, soup, Selector.CONTENT):- self.create_task(self.run(new_scrape_item))+ async with self.new_task_group() as tg:+ async for soup in pages:+ for new_item in self.iter_children(scrape_item, soup, Selector.CONTENT):+ tg.create_task(self.image(new_item))@error_handling_wrapperasync def image(self, scrape_item: ScrapeItem) -> None:@@ -53,7 +54,6 @@ class NudoStarTVCrawler(Crawler):returnsoup = await self.request_soup(scrape_item.url)- link_str = css.select(soup, Selector.IMAGE, "src")- link = self.parse_url(link_str)- filename, ext = self.get_filename_and_ext(link.name)- await self.handle_file(link, scrape_item, filename, ext)+ scrape_item.setup_as_album(self.create_title(css.select_text(soup, ".headline").partition("/")[0]))+ src = self.parse_url(css.select(soup, Selector.IMAGE, "src"))+ await self.direct_file(scrape_item, src)diff --git a/cyberdrop_dl/crawlers/postimg.py b/cyberdrop_dl/crawlers/postimg.pyindex 7aed0d258..635bbaf7b 100644--- a/cyberdrop_dl/crawlers/postimg.py+++ b/cyberdrop_dl/crawlers/postimg.py@@ -25,7 +25,8 @@ class PostImgCrawler(Crawler):async def fetch(self, scrape_item: ScrapeItem) -> None:if "i.postimg.cc" in scrape_item.url.host:- return await self.direct_file(scrape_item)+ await self.direct_file(scrape_item)+ returnmatch scrape_item.url.parts[1:]:case ["gallery", album_id, *_]:diff --git a/cyberdrop_dl/crawlers/twitter/crawler.py b/cyberdrop_dl/crawlers/twitter/crawler.pyindex f460c817a..86133ee09 100644--- a/cyberdrop_dl/crawlers/twitter/crawler.py+++ b/cyberdrop_dl/crawlers/twitter/crawler.py@@ -63,8 +63,9 @@ class TwimgCrawler(Crawler):if "amplify_video_thumb" in scrape_item.url.parts or scrape_item.url.suffix == ".m3u8":raise ValueErrorif "video" in scrape_item.url.host:- return await self.direct_file(scrape_item)- await self.photo(scrape_item)+ await self.direct_file(scrape_item)+ else:+ await self.photo(scrape_item)@error_handling_wrapperasync def photo(self, scrape_item: ScrapeItem, url: AbsoluteHttpURL | None = None) -> None:diff --git a/tests/crawlers/test_cases/ashemaletube.py b/tests/crawlers/test_cases/ashemaletube.pyindex 5b411af16..af8091107 100644--- a/tests/crawlers/test_cases/ashemaletube.py+++ b/tests/crawlers/test_cases/ashemaletube.py@@ -16,7 +16,7 @@ TEST_CASES = [{"url": "https://cc.ashemaletube.com/images/2025-09/b8/68b658b8f35c3/68b658b8f35c3-full-0.jpg","filename": "68b658b8f35c3-full-0 [11374066].jpg",- "referer": "https://www.ashemaletube.com/pics/265074/jjk-black-uniform/1",+ "referer": "https://www.ashemaletube.com/pics/265074/jjk-black-uniform/1/","album_id": None,}],diff --git a/tests/crawlers/test_cases/nudostar_tv.py b/tests/crawlers/test_cases/nudostar_tv.pynew file mode 100644index 000000000..8ae1fcd3a--- /dev/null+++ b/tests/crawlers/test_cases/nudostar_tv.py@@ -0,0 +1,20 @@+DOMAIN = "nudostar.tv"+TEST_CASES = [+ {+ "url": "https://nudostar.tv/models/anne-ale/105/",+ "results": [+ {+ "url": "https://nudostar.tv/contents/a/n/anne-ale/1000/anne-ale_0105.jpg",+ "filename": "anne-ale_0105.jpg",+ "debrid_url": None,+ "original_filename": "anne-ale_0105.jpg",+ "referer": "https://nudostar.tv/models/anne-ale/105/",+ "album_id": None,+ "uploaded_at": None,+ "download_folder": "re:Anne Ale (NudoStarTV)",+ "thumbnail": None,+ }+ ],+ "count": 1,+ }+]