Skip to content

Bulk asynchronous downloader for multiple file hosts

Remove need for tldextract, generalize thotsbay scraper

Jules-WinnfieldX0ba22967477a
diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py
index dd2b2a1e0..44e30b126 100644
--- a/cyberdrop_dl/__init__.py
+++ b/cyberdrop_dl/__init__.py
@@ -1 +1 @@
-__version__ = "2.15.2"
+__version__ = "2.15.3"
diff --git a/cyberdrop_dl/utils/base_functions.py b/cyberdrop_dl/utils/base_functions.py
index 54481d7f6..0eb44c619 100644
--- a/cyberdrop_dl/utils/base_functions.py
+++ b/cyberdrop_dl/utils/base_functions.py
@@ -5,7 +5,6 @@ import sqlite3
import ssl
import certifi
-import tldextract
from colorama import Fore, Style
from yarl import URL
diff --git a/cyberdrop_dl/utils/crawlers/Anonfiles_Spider.py b/cyberdrop_dl/utils/crawlers/Anonfiles_Spider.py
index 9dbdcfb31..8a9cc4a63 100644
--- a/cyberdrop_dl/utils/crawlers/Anonfiles_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/Anonfiles_Spider.py
@@ -1,6 +1,5 @@
from bs4 import BeautifulSoup
from colorama import Fore
-from tldextract import tldextract
from yarl import URL
from ..base_functions import log, logger, ssl_context
@@ -12,9 +11,7 @@ class AnonfilesCrawler():
self.include_id = include_id
async def fetch(self, session, url):
- url_extract = tldextract.extract(str(url))
- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)
- domain_obj = DomainItem(base_domain, {})
+ domain_obj = DomainItem(url.host, {})
await log("Starting scrape of " + str(url), Fore.WHITE)
diff --git a/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py b/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py
index 386193f8e..92ca548cc 100644
--- a/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py
@@ -1,6 +1,5 @@
from bs4 import BeautifulSoup
from colorama import Fore
-from tldextract import tldextract
from yarl import URL
from ..base_functions import bunkr_parse, log, logger, make_title_safe, ssl_context, check_direct
@@ -12,9 +11,7 @@ class ChibisafeCrawler():
self.include_id = include_id
async def fetch(self, session, url):
- url_extract = tldextract.extract(str(url))
- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)
- domain_obj = DomainItem(base_domain, {})
+ domain_obj = DomainItem(url.host, {})
if await check_direct(url):
await domain_obj.add_to_album(link=url, referral=url, title="Chibisafe Loose Files")
@@ -41,8 +38,6 @@ class ChibisafeCrawler():
link = URL(link.get('href'))
if 'bunkr' in link.host:
link = await bunkr_parse(link)
- # elif 'cyberdrop' in link.host:
- # link = await cyberdrop_parse(link)
await domain_obj.add_to_album(title, link, url)
except Exception as e:
diff --git a/cyberdrop_dl/utils/crawlers/Erome_Spider.py b/cyberdrop_dl/utils/crawlers/Erome_Spider.py
index cabd3d260..5cea2d82d 100644
--- a/cyberdrop_dl/utils/crawlers/Erome_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/Erome_Spider.py
@@ -1,6 +1,5 @@
from bs4 import BeautifulSoup
from colorama import Fore
-from tldextract import tldextract
from yarl import URL
from ..base_functions import log, logger, make_title_safe, ssl_context
@@ -12,9 +11,7 @@ class EromeCrawler():
self.include_id = include_id
async def fetch(self, session, url):
- url_extract = tldextract.extract(str(url))
- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)
- domain_obj = DomainItem(base_domain, {})
+ domain_obj = DomainItem(url.host, {})
await log("Starting scrape of " + str(url), Fore.WHITE)
diff --git a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py b/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
index 6904bf16f..5755fa887 100644
--- a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
@@ -1,5 +1,4 @@
import http
-import logging
from typing import Union
from colorama import Fore
@@ -27,7 +26,6 @@ class GofileCrawler():
results = await self.get_links(url)
await log("Starting scrape of " + str(url), Fore.WHITE)
- logging.debug("Starting scrape of " + str(url))
if results:
for result in results:
@@ -43,8 +41,7 @@ class GofileCrawler():
try:
content = self.client.get_content(content_id)
except:
- await log("GoFile seems to be down.")
- logging.debug("GoFile seems to be down or the link is dead")
+ await log("GoFile seems to be down or the link is dead")
return
if not content:
return
diff --git a/cyberdrop_dl/utils/crawlers/ShareX_Spider.py b/cyberdrop_dl/utils/crawlers/ShareX_Spider.py
index f6a194cde..22330d649 100644
--- a/cyberdrop_dl/utils/crawlers/ShareX_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/ShareX_Spider.py
@@ -1,6 +1,5 @@
from bs4 import BeautifulSoup
from colorama import Fore
-from tldextract import tldextract
from yarl import URL
from ..base_functions import log, logger, make_title_safe, ssl_context, check_direct
@@ -12,9 +11,7 @@ class ShareXCrawler():
self.include_id = include_id
async def fetch(self, session, url):
- url_extract = tldextract.extract(str(url))
- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)
- domain_obj = DomainItem(base_domain, {})
+ domain_obj = DomainItem(url.host, {})
await log("Starting scrape of " + str(url), Fore.WHITE)
diff --git a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py
index 253af3d4d..7578c11be 100644
--- a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py
@@ -17,8 +17,9 @@ class ThotsbayCrawler():
self.session = session
self.lock = 0
- async def login(self, session):
- async with session.get("https://forum.thotsbay.com/login", ssl=ssl_context) as response:
+ async def login(self, session, url: URL):
+ domain = URL("https://" + url.host) / "login"
+ async with session.get(domain, ssl=ssl_context) as response:
text = await response.text()
if "You are already logged in" in text:
return
@@ -31,21 +32,29 @@ class ThotsbayCrawler():
if elem.get('name') and elem.get('value')
}
data.update({"login": self.username, "password": self.password})
- return await session.post("https://forum.thotsbay.com/login/login", data=data)
+ return await session.post(domain/"login", data=data)
async def fetch(self, session, url: URL):
await log("Starting scrape of " + str(url), Fore.WHITE)
Cascade = CascadeItem({})
- if self.username and self.password:
- if self.lock == 0:
- self.lock = 1
- await self.login(session)
+ try:
+ if self.username and self.password:
+ while True:
+ if self.lock == 0:
+ self.lock = 1
+ await self.login(session, url)
+ self.lock = 0
+ break
+ else:
+ await asyncio.sleep(2)
else:
- await asyncio.sleep(5)
- else:
- await log("login wasn't provided, consider using --thotsbay-username and --thotsbay-password")
- await log("Not being logged in might cause issues.")
+ await log("login wasn't provided, consider using --thotsbay-username and --thotsbay-password")
+ await log("Not being logged in might cause issues.")
+ except Exception as e:
+ await log("there was an error signing into %s" % url.host)
+ await log(e)
+ return
try:
title = await self.parse_thread(session, url, Cascade, None)
@@ -63,6 +72,8 @@ class ThotsbayCrawler():
text = await response.text()
soup = BeautifulSoup(text, 'html.parser')
+ domain = URL("https://" + url.host)
+
if title:
pass
else:
@@ -76,7 +87,8 @@ class ThotsbayCrawler():
content_links = []
post_number = str(url).split("post-")
- post_number = int(post_number[-1]) if len(post_number) == 2 else None
+ post_number = int(post_number[-1].strip("/")) if len(post_number) == 2 else None
+
posts = soup.select("div[class='message-main uix_messageContent js-quickEditTarget']")
for post in posts:
@@ -89,6 +101,7 @@ class ThotsbayCrawler():
elem.decompose()
post_content = post.select_one("div[class=bbWrapper]")
+ # Content links
links = post_content.select('a')
for link in links:
link = link.get('href')
@@ -97,7 +110,7 @@ class ThotsbayCrawler():
if link.startswith('//'):
link = "https:" + link
elif link.startswith('/'):
- link = URL("https://forum.thotsbay.com") / link[1:]
+ link = domain / link[1:]
content_links.append(URL(link))
links = post.select("div[class='bbImageWrapper js-lbImage']")
@@ -107,6 +120,17 @@ class ThotsbayCrawler():
link = link[:-1]
content_links.append(URL(link))
+ links = post.select("div[class='bbImageWrapper lazyload js-lbImage']")
+ for link in links:
+ link = link.get('data-src')
+ if link.endswith("/"):
+ link = link[:-1]
+ if link.startswith('//'):
+ link = "https:" + link
+ elif link.startswith('/'):
+ link = domain / link
+ content_links.append(URL(link))
+
links = post.select("video source")
for link in links:
link = link.get('src')
@@ -115,9 +139,11 @@ class ThotsbayCrawler():
if link.startswith('//'):
link = "https:" + link
elif link.startswith('/'):
- link = "https://forum.thotsbay.com" + link
+ link = domain / link
content_links.append(URL(link))
+
+
attachments_block = post.select_one("section[class=message-attachments]")
links = attachments_block.select("a[class='file-preview js-lbImage']") if attachments_block else []
for link in links:
@@ -125,20 +151,18 @@ class ThotsbayCrawler():
if link.endswith("/"):
link = link[:-1]
if link.startswith('/'):
- link = URL("https://forum.thotsbay.com") / link[1:]
- else:
- link = URL(link)
- await Cascade.add_to_album("Thotsbay.com", "Attachments", link, url)
-
- thotsbay_direct_urls = [x for x in content_links if "thotsbay.com" in x.host]
- content_links = [x for x in content_links if x not in thotsbay_direct_urls]
- for link in thotsbay_direct_urls:
+ link = domain / link[1:]
+ await Cascade.add_to_album(url.host, "Attachments", URL(link), url)
+
+ forum_direct_urls = [x for x in content_links if url.host in x.host]
+ content_links = [x for x in content_links if x not in forum_direct_urls]
+ for link in forum_direct_urls:
if str(link).endswith("/"):
link = URL(str(link)[:-1])
if 'attachments' in link.parts:
- await Cascade.add_to_album("Thotsbay.com", "Attachments", link, url)
+ await Cascade.add_to_album(url.host, "Attachments", link, url)
elif 'data' in link.parts:
- await Cascade.add_to_album("Thotsbay.com", "Attachments", link, url)
+ await Cascade.add_to_album(url.host, "Attachments", link, url)
tasks = []
for link in content_links:
@@ -150,7 +174,7 @@ class ThotsbayCrawler():
next_page = next_page.get('href')
if next_page is not None:
if next_page.startswith('/'):
- next_page = URL("https://forum.thotsbay.com") / next_page[1:]
+ next_page = domain / next_page[1:]
next_page = URL(next_page)
title = await self.parse_thread(session, next_page, Cascade, title)
return title
diff --git a/cyberdrop_dl/utils/scraper_helper.py b/cyberdrop_dl/utils/scraper_helper.py
index 2bfedcaf2..f8ac4551d 100644
--- a/cyberdrop_dl/utils/scraper_helper.py
+++ b/cyberdrop_dl/utils/scraper_helper.py
@@ -1,4 +1,3 @@
-import tldextract
from yarl import URL
from .crawlers.Anonfiles_Spider import AnonfilesCrawler
@@ -29,7 +28,7 @@ class ScrapeMapper():
"cyberdrop.to": self.Chibisafe, "cyberdrop.nl": self.Chibisafe, "bunkr.is": self.Chibisafe,
"bunkr.to": self.Chibisafe, "erome.com": self.Erome, "gofile.io": self.GoFile,
"anonfiles.com": self.Anonfiles, "pixeldrain.com": self.Pixeldrain,
- "thotsbay.com": self.ThotsBay}
+ "thotsbay.com": self.ThotsBay, "socialmediagirls.com": self.ThotsBay}
async def ShareX(self, url: URL, title=None):
if not self.sharex_crawler:
@@ -82,10 +81,8 @@ class ScrapeMapper():
await self.Cascade.extend(await self.thotsbay_crawler.fetch(self.session, url))
async def map_url(self, url_to_map: URL, title=None):
- url_extract = tldextract.extract(str(url_to_map))
- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)
-
- if base_domain in self.mapping.keys():
- await self.mapping[base_domain](url=url_to_map, title=title)
- else:
- await log(str(url_to_map) + " is not supported currently.")
+ for key, value in self.mapping.items():
+ if key in url_to_map.host:
+ await value(url=url_to_map, title=title)
+ return
+ await log(str(url_to_map) + "is not supported currently.")