Skip to content

Bulk asynchronous downloader for multiple file hosts

Add Celebforum support

Jules-WinnfieldXe1802831cb67
diff --git a/cyberdrop_dl/scraper/crawlers/celebforum_crawler.py b/cyberdrop_dl/scraper/crawlers/celebforum_crawler.py
new file mode 100644
index 000000000..f998adc0d
--- /dev/null
+++ b/cyberdrop_dl/scraper/crawlers/celebforum_crawler.py
@@ -0,0 +1,284 @@
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from aiolimiter import AsyncLimiter
+from bs4 import Tag
+from yarl import URL
+
+from cyberdrop_dl.scraper.crawler import Crawler
+from cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItem
+from cyberdrop_dl.utils.utilities import get_filename_and_ext, error_handling_wrapper, log
+
+if TYPE_CHECKING:
+ from cyberdrop_dl.managers.manager import Manager
+
+
+class CelebForumCrawler(Crawler):
+ def __init__(self, manager: Manager):
+ super().__init__(manager, "celebforum", "CelebForum")
+ self.primary_base_domain = URL("https://celebforum.to")
+ self.logged_in = False
+ self.request_limiter = AsyncLimiter(10, 1)
+
+ self.title_selector = "h1[class=p-title-value]"
+ self.title_trash_selector = "a"
+ self.posts_selector = "div[class*=message-main]"
+ self.post_date_selector = "time"
+ self.post_date_attribute = "data-time"
+ self.posts_number_selector = "li[class=u-concealed] a"
+ self.posts_number_attribute = "href"
+ self.quotes_selector = "blockquote"
+ self.posts_content_selector = "div[class=bbWrapper]"
+ self.next_page_selector = "a[class*=pageNav-jump--next]"
+ self.next_page_attribute = "href"
+ self.links_selector = "a"
+ self.links_attribute = "href"
+ self.attachment_url_part = "attachments"
+ self.images_selector = "img[class*=bbImage]"
+ self.images_attribute = "src"
+ self.videos_selector = "video source"
+ self.iframe_selector = "iframe[class=saint-iframe]"
+ self.videos_attribute = "src"
+ self.embeds_selector = "iframe"
+ self.embeds_attribute = "src"
+ self.attachments_block_selector = "section[class=message-attachments]"
+ self.attachments_selector = "a"
+ self.attachments_attribute = "href"
+
+ """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""
+
+ async def fetch(self, scrape_item: ScrapeItem) -> None:
+ """Determines where to send the scrape item based on the url"""
+ task_id = await self.scraping_progress.add_task(scrape_item.url)
+
+ if not self.logged_in:
+ login_url = self.primary_base_domain / "login"
+ session_cookie = self.manager.config_manager.authentication_data['Forums']['celebforum_xf_user_cookie']
+ username = self.manager.config_manager.authentication_data['Forums']['celebforum_username']
+ password = self.manager.config_manager.authentication_data['Forums']['celebforum_password']
+ wait_time = 5
+
+ await self.forum_login(login_url, session_cookie, username, password, wait_time)
+
+ if self.logged_in:
+ await self.forum(scrape_item)
+
+ await self.scraping_progress.remove_task(task_id)
+
+ @error_handling_wrapper
+ async def forum(self, scrape_item: ScrapeItem) -> None:
+ """Scrapes an album"""
+ continue_scraping = True
+ if "post-" in str(scrape_item.url):
+ url_parts = str(scrape_item.url).rsplit("post-", 1)
+ thread_url = URL(url_parts[0].rstrip("#"))
+ post_number = int(url_parts[-1].strip("/")) if len(url_parts) == 2 else 0
+ else:
+ thread_url = scrape_item.url
+ post_number = 0
+ current_post_number = 0
+
+ while True:
+ async with self.request_limiter:
+ soup = await self.client.get_BS4(self.domain, thread_url)
+
+ title_block = soup.select_one(self.title_selector)
+ for elem in title_block.find_all(self.title_trash_selector):
+ elem.decompose()
+
+ thread_id = thread_url.parts[2].split('.')[-1]
+ title = await self.create_title(title_block.text.replace("\n", ""), None, thread_id)
+
+ posts = soup.select(self.posts_selector)
+ for post in posts:
+ current_post_number = int(post.select_one(self.posts_number_selector).get(self.posts_number_attribute).split('/')[-1].split('post-')[-1])
+ if post_number > current_post_number:
+ continue
+
+ new_scrape_item = ScrapeItem(thread_url, scrape_item.parent_title)
+ await new_scrape_item.add_to_parent_title(title)
+
+ date = int(post.select_one(self.post_date_selector).get(self.post_date_attribute))
+ new_scrape_item.possible_datetime = date
+
+ for elem in post.find_all(self.quotes_selector):
+ elem.decompose()
+ post_content = post.select_one(self.posts_content_selector)
+ await self.post(new_scrape_item, post_content, current_post_number)
+
+ if self.manager.config_manager.settings_data['Download_Options']['scrape_single_forum_post']:
+ continue_scraping = False
+ break
+
+ next_page = soup.select_one(self.next_page_selector)
+ if next_page and continue_scraping:
+ thread_url = next_page.get(self.next_page_attribute)
+ if thread_url:
+ if thread_url.startswith("/"):
+ thread_url = self.primary_base_domain / thread_url[1:]
+ thread_url = URL(thread_url)
+ continue
+ else:
+ break
+ post_string = f"post-{current_post_number}"
+ if "page-" in scrape_item.url.raw_name or "post-" in scrape_item.url.raw_name:
+ last_post_url = scrape_item.url.parent / post_string
+ else:
+ last_post_url = scrape_item.url / post_string
+ await self.manager.file_manager.write_last_post_log(last_post_url)
+
+ @error_handling_wrapper
+ async def post(self, scrape_item: ScrapeItem, post_content: Tag, post_number: int) -> None:
+ """Scrapes a post"""
+ if self.manager.config_manager.settings_data['Download_Options']['separate_posts']:
+ scrape_item = ScrapeItem(scrape_item.url, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await scrape_item.add_to_parent_title("post-" + str(post_number))
+
+ await self.links(scrape_item, post_content)
+ await self.images(scrape_item, post_content)
+ await self.videos(scrape_item, post_content)
+ await self.embeds(scrape_item, post_content)
+ await self.attachments(scrape_item, post_content)
+
+ @error_handling_wrapper
+ async def links(self, scrape_item: ScrapeItem, post_content: Tag) -> None:
+ """Scrapes links from a post"""
+ links = post_content.select(self.links_selector)
+ for link_obj in links:
+ link = link_obj.get(self.links_attribute)
+ if not link:
+ continue
+
+ link = link.replace(".th.", ".").replace(".md.", ".")
+
+ if link.endswith("/"):
+ link = link[:-1]
+
+ if link.startswith("//"):
+ link = "https:" + link
+ elif link.startswith("/"):
+ link = self.primary_base_domain / link[1:]
+ link = URL(link)
+
+ try:
+ if self.domain not in link.host:
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await self.handle_external_links(new_scrape_item)
+ elif self.attachment_url_part in link.parts:
+ await self.handle_internal_links(link, scrape_item)
+ else:
+ await log(f"Unknown link type: {link}")
+ continue
+ except TypeError:
+ await log(f"Scrape Error: encountered while handling {link}")
+
+ @error_handling_wrapper
+ async def images(self, scrape_item: ScrapeItem, post_content: Tag) -> None:
+ """Scrapes images from a post"""
+ images = post_content.select(self.images_selector)
+ for image in images:
+ link = image.get(self.images_attribute)
+ if not link:
+ continue
+
+ parent_check = image.parent.get("href")
+ if parent_check:
+ continue
+
+ link = link.replace(".th.", ".").replace(".md.", ".")
+ if link.endswith("/"):
+ link = link[:-1]
+
+ if link.startswith("//"):
+ link = "https:" + link
+ elif link.startswith("/"):
+ link = self.primary_base_domain / link[1:]
+ link = URL(link)
+
+ if self.domain not in link.host:
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await self.handle_external_links(new_scrape_item)
+ elif self.attachment_url_part in link.parts:
+ await self.handle_internal_links(link, scrape_item)
+ else:
+ await log(f"Unknown image type: {link}")
+ continue
+
+ @error_handling_wrapper
+ async def videos(self, scrape_item: ScrapeItem, post_content: Tag) -> None:
+ """Scrapes videos from a post"""
+ videos = post_content.select(self.videos_selector)
+ videos.extend(post_content.select(self.iframe_selector))
+
+ for video in videos:
+ link = video.get(self.videos_attribute)
+ if not link:
+ continue
+
+ if link.endswith("/"):
+ link = link[:-1]
+
+ if link.startswith("//"):
+ link = "https:" + link
+
+ link = URL(link)
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await self.handle_external_links(new_scrape_item)
+
+ @error_handling_wrapper
+ async def embeds(self, scrape_item: ScrapeItem, post_content: Tag) -> None:
+ """Scrapes embeds from a post"""
+ embeds = post_content.select(self.embeds_selector)
+ for embed in embeds:
+ link = embed.get(self.embeds_attribute)
+ if not link:
+ continue
+
+ link = link.replace("ifr", "watch")
+
+ link = URL(link)
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await self.handle_external_links(new_scrape_item)
+
+ @error_handling_wrapper
+ async def attachments(self, scrape_item: ScrapeItem, post_content: Tag) -> None:
+ """Scrapes attachments from a post"""
+ attachment_block = post_content.select_one(self.attachments_block_selector)
+ if not attachment_block:
+ return
+
+ attachments = attachment_block.select(self.attachments_selector)
+ for attachment in attachments:
+ link = attachment.get(self.attachments_attribute)
+ if not link:
+ continue
+
+ if link.endswith("/"):
+ link = link[:-1]
+
+ if link.startswith("//"):
+ link = "https:" + link
+ elif link.startswith("/"):
+ link = self.primary_base_domain / link[1:]
+ link = URL(link)
+
+ if self.domain not in link.host:
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, possible_datetime=scrape_item.possible_datetime)
+ await self.handle_external_links(new_scrape_item)
+ elif self.attachment_url_part in link.parts:
+ await self.handle_internal_links(link, scrape_item)
+ else:
+ await log(f"Unknown image type: {link}")
+ continue
+
+ """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""
+
+ @error_handling_wrapper
+ async def handle_internal_links(self, link: URL, scrape_item: ScrapeItem) -> None:
+ """Handles internal links"""
+ filename, ext = await get_filename_and_ext(link.name, True)
+ new_scrape_item = ScrapeItem(link, scrape_item.parent_title, True, scrape_item.possible_datetime)
+ await new_scrape_item.add_to_parent_title("Attachments")
+ await self.handle_file(link, new_scrape_item, filename, ext)
diff --git a/cyberdrop_dl/scraper/scraper.py b/cyberdrop_dl/scraper/scraper.py
index 9bb940f62..2dba314f6 100644
--- a/cyberdrop_dl/scraper/scraper.py
+++ b/cyberdrop_dl/scraper/scraper.py
@@ -22,7 +22,8 @@ if TYPE_CHECKING:
class ScrapeMapper:
"""This class maps links to their respective handlers, or JDownloader if they are unsupported"""
def __init__(self, manager: Manager):
- self.mapping = {"xbunkr": self.xbunkr, "bunkr": self.bunkr, "coomer": self.coomer, "cyberdrop": self.cyberdrop,
+ self.mapping = {"xbunkr": self.xbunkr, "bunkr": self.bunkr, "celebforum": self.celebforum,
+ "coomer": self.coomer, "cyberdrop": self.cyberdrop,
"cyberfile": self.cyberfile, "e-hentai": self.ehentai, "erome": self.erome,
"fapello": self.fapello, "gofile": self.gofile, "imageban": self.imageban, "imgbox": self.imgbox,
"imgur": self.imgur, "img.kiwi": self.imgwiki, "jpg.church": self.jpgchurch,
@@ -34,17 +35,17 @@ class ScrapeMapper:
"reddit": self.reddit, "redd.it": self.reddit, "redgifs": self.redgifs, "saint": self.saint,
"socialmediagirls": self.socialmediagirls, "simpcity": self.simpcity,
"xbunker": self.xbunker}
- self.download_mapping = {"xbunkr": "xbunkr", "bunkr": "bunkr", "coomer": "coomer", "cyberdrop": "cyberdrop",
- "cyberfile": "cyberfile", "e-hentai": "e-hentai", "erome": "erome",
- "fapello": "fapello", "gofile": "gofile", "imageban": "imageban", "imgbox": "imgbox", "imgur": "imgur",
- "img.kiwi": "sharex", "jpg.church": "sharex", "jpg.homes": "sharex",
- "jpg.fish": "sharex", "jpg.fishing": "sharex", "jpg.pet": "sharex",
- "jpeg.pet": "sharex", "jpg1.su": "sharex", "jpg2.su": "sharex", "jpg3.su": "sharex",
- "kemono": "kemono", "mediafire": "mediafire", "nudostar.com": "nudostar",
- "nudostar.tv": "nudostartv", "pimpandhost": "pimpandhost", "pixeldrain": "pixeldrain",
- "postimg": "postimg", "reddit": "reddit", "redd.it": "reddit", "redgifs": "redgifs",
- "saint": "saint", "socialmediagirls": "socialmediagirls", "simpcity": "simpcity",
- "xbunker": "xbunker"}
+ self.download_mapping = {"xbunkr": "xbunkr", "bunkr": "bunkr", "celebforum": "celebforum", "coomer": "coomer",
+ "cyberdrop": "cyberdrop", "cyberfile": "cyberfile", "e-hentai": "e-hentai",
+ "erome": "erome", "fapello": "fapello", "gofile": "gofile", "imageban": "imageban",
+ "imgbox": "imgbox", "imgur": "imgur", "img.kiwi": "sharex", "jpg.church": "sharex",
+ "jpg.homes": "sharex", "jpg.fish": "sharex", "jpg.fishing": "sharex",
+ "jpg.pet": "sharex", "jpeg.pet": "sharex", "jpg1.su": "sharex", "jpg2.su": "sharex",
+ "jpg3.su": "sharex", "kemono": "kemono", "mediafire": "mediafire",
+ "nudostar.com": "nudostar", "nudostar.tv": "nudostartv", "pimpandhost": "pimpandhost",
+ "pixeldrain": "pixeldrain", "postimg": "postimg", "reddit": "reddit",
+ "redd.it": "reddit", "redgifs": "redgifs", "saint": "saint",
+ "socialmediagirls": "socialmediagirls", "simpcity": "simpcity", "xbunker": "xbunker"}
self.existing_crawlers = {}
self.manager = manager
self.jdownloader = JDownloader(self.manager)
@@ -56,6 +57,11 @@ class ScrapeMapper:
from cyberdrop_dl.scraper.crawlers.bunkr_crawler import BunkrCrawler
self.existing_crawlers['bunkr'] = BunkrCrawler(self.manager)
+ async def celebforum(self) -> None:
+ """Creates a CelebForum Crawler instance"""
+ from cyberdrop_dl.scraper.crawlers.celebforum_crawler import CelebForumCrawler
+ self.existing_crawlers['celebforum'] = CelebForumCrawler(self.manager)
+
async def coomer(self) -> None:
"""Creates a Coomer Crawler instance"""
from cyberdrop_dl.scraper.crawlers.coomer_crawler import CoomerCrawler
diff --git a/cyberdrop_dl/ui/prompts/settings_authentication_prompts.py b/cyberdrop_dl/ui/prompts/settings_authentication_prompts.py
index b754502bf..43b6b2c4e 100644
--- a/cyberdrop_dl/ui/prompts/settings_authentication_prompts.py
+++ b/cyberdrop_dl/ui/prompts/settings_authentication_prompts.py
@@ -136,6 +136,15 @@ def edit_forum_authentication_values_prompt(manager: Manager) -> None:
# Enter Cookie Values Manually
elif action == 2:
+ celebforum_username = inquirer.text(
+ message="Enter your CelebForum Username:",
+ default=manager.config_manager.authentication_data["Forums"]["celebforum_username"],
+ ).execute()
+ celebforum_password = inquirer.text(
+ message="Enter your CelebForum Password:",
+ default=manager.config_manager.authentication_data["Forums"]["celebforum_password"],
+ ).execute()
+
nudostar_username = inquirer.text(
message="Enter your NudoStar Username:",
default=manager.config_manager.authentication_data["Forums"]["nudostar_username"],
@@ -172,11 +181,13 @@ def edit_forum_authentication_values_prompt(manager: Manager) -> None:
default=manager.config_manager.authentication_data["Forums"]["xbunker_password"],
).execute()
+ manager.config_manager.authentication_data["Forums"]["celebforum_username"] = celebforum_username
manager.config_manager.authentication_data["Forums"]["nudostar_username"] = nudostar_username
manager.config_manager.authentication_data["Forums"]["simpcity_username"] = simpcity_username
manager.config_manager.authentication_data["Forums"]["socialmediagirls_username"] = socialmediagirls_username
manager.config_manager.authentication_data["Forums"]["xbunker_username"] = xbunker_username
+ manager.config_manager.authentication_data["Forums"]["celebforum_password"] = celebforum_password
manager.config_manager.authentication_data["Forums"]["nudostar_password"] = nudostar_password
manager.config_manager.authentication_data["Forums"]["simpcity_password"] = simpcity_password
manager.config_manager.authentication_data["Forums"]["socialmediagirls_password"] = socialmediagirls_password
diff --git a/cyberdrop_dl/utils/args/config_definitions.py b/cyberdrop_dl/utils/args/config_definitions.py
index d2b7a5243..d7ec217a7 100644
--- a/cyberdrop_dl/utils/args/config_definitions.py
+++ b/cyberdrop_dl/utils/args/config_definitions.py
@@ -7,6 +7,9 @@ from cyberdrop_dl.managers.directory_manager import APP_STORAGE, DOWNLOAD_STORAG
authentication_settings: Dict = {
"Forums": {
+ "celebforum_xf_user_cookie": "",
+ "celebforum_username": "",
+ "celebforum_password": "",
"nudostar_xf_user_cookie": "",
"nudostar_username": "",
"nudostar_password": "",
diff --git a/cyberdrop_dl/utils/dataclasses/supported_domains.py b/cyberdrop_dl/utils/dataclasses/supported_domains.py
index 7d2741a3d..5eef27bae 100644
--- a/cyberdrop_dl/utils/dataclasses/supported_domains.py
+++ b/cyberdrop_dl/utils/dataclasses/supported_domains.py
@@ -5,16 +5,16 @@ from typing import ClassVar, Tuple, List
@dataclass
class SupportedDomains:
"""The allows options for domains to skip when scraping"""
- supported_hosts: ClassVar[Tuple[str, ...]] = ("xbunkr", "bunkr", "coomer", "cyberdrop", "cyberfile", "e-hentai",
+ supported_hosts: ClassVar[Tuple[str, ...]] = ("xbunkr", "bunkr", "celebforum", "coomer", "cyberdrop", "cyberfile", "e-hentai",
"erome", "fapello", "gofile", "imageban", "imgbox", "imgur", "img.kiwi",
"jpg.church", "jpg.homes", "jpg.fish", "jpg.fishing", "jpg.pet",
"jpeg.pet", "jpg1.su", "jpg2.su", "jpg3.su", "kemono", "mediafire",
"nudostar.com", "nudostar.tv", "pimpandhost", "pixeldrain",
"postimg", "reddit", "redd.it", "redgifs", "saint",
"socialmediagirls", "simpcity", "xbunker")
- supported_forums: ClassVar[Tuple[str, ...]] = ("nudostar.com", "simpcity.su", "forums.socialmediagirls.com",
+ supported_forums: ClassVar[Tuple[str, ...]] = ("celebforum.to", "nudostar.com", "simpcity.su", "forums.socialmediagirls.com",
"xbunker.nu")
- supported_forums_map = {"nudostar.com": "nudostar", "simpcity.su": "simpcity",
+ supported_forums_map = {"celebforum.to": "celebforum", "nudostar.com": "nudostar", "simpcity.su": "simpcity",
"forums.socialmediagirls.com": "socialmediagirls", "xbunker.nu": "xbunker"}
sites: List[str]