Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add support to twpornstars (#1016)

Barbarella66666662591f0fdc653
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4573d9308..04cbf7629 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Influencerbitches.com support
- IncestFlix support
- Porntrex support
+- Twpornstars.com support
- Vipr.im support
- Albums support (ThisVid)
- Parse upload date of files (rule34xxx)
diff --git a/cyberdrop_dl/crawlers/__init__.py b/cyberdrop_dl/crawlers/__init__.py
index 3e1f9c653..73bf25a0a 100644
--- a/cyberdrop_dl/crawlers/__init__.py
+++ b/cyberdrop_dl/crawlers/__init__.py
@@ -85,6 +85,7 @@ from .tiktok import TikTokCrawler
from .tokyomotion import TokioMotionCrawler
from .toonily import ToonilyCrawler
from .twitter_images import TwimgCrawler
+from .twpornstars import TwPornstarsCrawler
from .vipr_dot_im import ViprImCrawler
from .wetransfer import WeTransferCrawler
from .xbunkr import XBunkrCrawler
diff --git a/cyberdrop_dl/crawlers/twitter_images.py b/cyberdrop_dl/crawlers/twitter_images.py
index 5778264d5..d17499739 100644
--- a/cyberdrop_dl/crawlers/twitter_images.py
+++ b/cyberdrop_dl/crawlers/twitter_images.py
@@ -27,15 +27,18 @@ class TwimgCrawler(Crawler):
@create_task_id
async def fetch(self, scrape_item: ScrapeItem) -> None:
"""Determines where to send the scrape item based on the url."""
- await self.photo(scrape_item)
+ if "video" in scrape_item.url.host:
+ await self.direct_file(scrape_item)
+ else:
+ await self.photo(scrape_item)
- async def photo(self, scrape_item: ScrapeItem) -> None:
+ async def photo(self, scrape_item: ScrapeItem, url: URL | None = None) -> None:
"""Scrapes a photo.
See: https://developer.x.com/en/docs/x-api/v1/data-dictionary/object-model/entities#photo_format
"""
- scrape_item.url = scrape_item.url.with_host(CDN_HOST)
- link = scrape_item.url.with_query(format="jpg", name="large")
+ link = url or scrape_item.url
+ link = link.with_host(CDN_HOST).with_query(format="jpg", name="large")
filename = str(Path(link.name).with_suffix(".jpg"))
filename, ext = self.get_filename_and_ext(filename)
await self.handle_file(link, scrape_item, filename, ext)
diff --git a/cyberdrop_dl/crawlers/twpornstars.py b/cyberdrop_dl/crawlers/twpornstars.py
new file mode 100644
index 000000000..e66048228
--- /dev/null
+++ b/cyberdrop_dl/crawlers/twpornstars.py
@@ -0,0 +1,91 @@
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, ClassVar
+
+from yarl import URL
+
+from cyberdrop_dl.crawlers.crawler import create_task_id
+from cyberdrop_dl.crawlers.twitter_images import TwimgCrawler
+from cyberdrop_dl.exceptions import ScrapeError
+from cyberdrop_dl.utils.utilities import error_handling_wrapper
+
+if TYPE_CHECKING:
+ from bs4 import BeautifulSoup
+
+ from cyberdrop_dl.data_structures.url_objects import ScrapeItem
+ from cyberdrop_dl.managers.manager import Manager
+
+
+class Selectors:
+ NEXT = "li > a:contains('»')"
+ VIDEO = "video.video-js > source"
+ PHOTO = "img.thumb__img"
+ TITLE = "h1.user-page"
+ HASHTAGS = "h1.tag-page"
+ THUMBS = "div.block-thumbs a.thumb__link"
+
+
+_SELECTORS = Selectors()
+
+SUPPORTED_DOMAINS = [
+ "www.twgays.com",
+ "www.twmilf.com",
+ "www.twlesbian.com",
+ "www.twteens.com",
+ "www.twonfans.com",
+ "www.twtiktoks.com",
+ "www.twgaymuscle.com",
+ "www.twanal.com",
+ "www.indiantw.com",
+ "www.twpornstars.com",
+]
+
+TITLE_TRASH = "'s pics and videos"
+
+
+class TwPornstarsCrawler(TwimgCrawler):
+ SUPPORTED_SITES: ClassVar[dict[str, list]] = {"twpornstars": SUPPORTED_DOMAINS}
+ primary_base_domain = URL("https://www.twpornstars.com")
+ next_page_selector = _SELECTORS.NEXT
+
+ def __init__(self, manager: Manager, _=None) -> None:
+ super().__init__(manager)
+ self.manager = manager
+ self.domain = "twpornstars"
+ self.folder_domain = "TWPornStars"
+
+ """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""
+
+ @create_task_id
+ async def fetch(self, scrape_item: ScrapeItem) -> None:
+ """Determines where to send the scrape item based on the url."""
+ if "p" in scrape_item.url.parts:
+ return await self.media(scrape_item)
+ if len(scrape_item.url.parts) >= 2:
+ return await self.collection(scrape_item)
+ raise ValueError
+
+ @error_handling_wrapper
+ async def media(self, scrape_item: ScrapeItem) -> None:
+ if await self.check_complete_from_referer(scrape_item):
+ return
+ async with self.request_limiter:
+ soup: BeautifulSoup = await self.client.get_soup(self.domain, scrape_item.url)
+ if url := soup.select_one(_SELECTORS.PHOTO):
+ await self.photo(scrape_item, self.parse_url(url["src"].replace(":large", "")))
+ elif url := soup.select_one(_SELECTORS.VIDEO):
+ await self.direct_file(scrape_item, self.parse_url(url["src"]).with_query(None))
+ else:
+ raise ScrapeError(404)
+
+ @error_handling_wrapper
+ async def collection(self, scrape_item: ScrapeItem) -> None:
+ title_created: bool = False
+ async for soup in self.web_pager(scrape_item.url):
+ if not title_created:
+ title_tag = soup.select_one(_SELECTORS.TITLE) or soup.select_one(_SELECTORS.HASHTAGS)
+ title = self.create_title(title_tag.get_text(strip=True).replace(TITLE_TRASH, ""))
+ scrape_item.setup_as_album(title)
+ title_created = True
+ for _, new_scrape_item in self.iter_children(scrape_item, soup, _SELECTORS.THUMBS):
+ self.manager.task_group.create_task(self.run(new_scrape_item))
diff --git a/cyberdrop_dl/utils/utilities.py b/cyberdrop_dl/utils/utilities.py
index ef8dc7927..5e36fc229 100644
--- a/cyberdrop_dl/utils/utilities.py
+++ b/cyberdrop_dl/utils/utilities.py
@@ -442,10 +442,14 @@ def parse_url(link_str: str, relative_to: URL | None = None, *, trim: bool = Tru
query_and_frag = query_and_frag.replace("+", "%20")
return f"{parts}?{query_and_frag}"
+ def fix_multiple_slashes(link_str: str) -> str:
+ return re.sub(r"(?:https?)?:?(\/{3,})", "//", link_str)
+
try:
assert link_str, "link_str is empty"
assert isinstance(link_str, str), f"link_str must be a string object, got: {link_str!r}"
clean_link_str = fix_query_params_encoding()
+ clean_link_str = fix_multiple_slashes(clean_link_str)
is_encoded = "%" in clean_link_str
new_url = URL(clean_link_str, encoded=is_encoded)
except (AssertionError, AttributeError, ValueError, TypeError) as e:
diff --git a/docs/reference/supported-websites.md b/docs/reference/supported-websites.md
index 5e6b1b3d4..d62dc0d86 100644
--- a/docs/reference/supported-websites.md
+++ b/docs/reference/supported-websites.md
@@ -879,6 +879,17 @@ See: [`--download-dropbox-folders-as-zip` (CLI args)](https://script-ware.gitboo
<details>
+<summary>twpornstars.com</summary>
+
+### `Supported URL Paths:`
+
+* Photo or Video: `/p/...`
+* Collection: `/...`
+
+</details>
+
+<details>
+
<summary>WeTransfer</summary>
### `Supported URL Paths:`