Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Scraper mapping and cleanup.
Jules-WinnfieldXe7c93d086cdf
diff --git a/CHANGELOG.txt b/CHANGELOG.txtindex 5643bba52..3dd577eb2 100644--- a/CHANGELOG.txt+++ b/CHANGELOG.txt@@ -9,4 +9,8 @@ Fixed my instant returns for 400-500 status.2.14.9We're trying just cyberdrop.to for faster cyberdrop downloads-Change all funcs to be async\ No newline at end of file+Change all funcs to be async++2.15.0+Created scraper_helper.py+-> we now only create the scrapers as needed, and it allows me to pass backwards the thotsbay links, cleaning up the code.\ No newline at end of filediff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.pyindex a75afc5f9..90c1ae3a0 100644--- a/cyberdrop_dl/__init__.py+++ b/cyberdrop_dl/__init__.py@@ -1 +1 @@-__version__ = "2.14.14"+__version__ = "2.15.0"diff --git a/cyberdrop_dl/utils/base_functions.py b/cyberdrop_dl/utils/base_functions.pyindex c96a910a2..54481d7f6 100644--- a/cyberdrop_dl/utils/base_functions.py+++ b/cyberdrop_dl/utils/base_functions.py@@ -32,14 +32,6 @@ FILE_FORMATS = {}}-mapping_ShareX = ["pixl.is", "putme.ga", "putmega.com", "jpg.church"]-mapping_Chibisafe = ["cyberdrop.me", "cyberdrop.cc", "cyberdrop.to", "cyberdrop.nl", "bunkr.is", "bunkr.to"]-mapping_Erome = ["erome.com"]-mapping_GoFile = ["gofile.io"]-mapping_Pixeldrain = ["pixeldrain.com"]-mapping_Thotsbay = ["thotsbay.com"]-mapping_Anonfiles = ["anonfiles.com"]-user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'ssl_context = ssl.create_default_context(cafile=certifi.where())@@ -167,54 +159,3 @@ async def check_direct(url: URL):elif extension in FILE_FORMATS['Videos'] or extension in FILE_FORMATS['Images'] or extension in FILE_FORMATS['Audio'] or extension in FILE_FORMATS['Other']:return Truereturn False---async def url_sort(urls, Cascade):- ShareX_urls = []- Chibisafe_urls = []- Erome_urls = []- GoFile_urls = []- Thotsbay_urls = []- Anonfiles_urls = []-- for url in urls:- url_extract = tldextract.extract(str(url))- base_domain = "{}.{}".format(url_extract.domain, url_extract.suffix)-- if base_domain in mapping_ShareX:- if await check_direct(url):- await Cascade.add_to_album(base_domain, "ShareX Loose Files", url, url)- else:- ShareX_urls.append(url)-- elif base_domain in mapping_Chibisafe:- if await check_direct(url):- if 'bunkr' in url.host:- await Cascade.add_to_album(base_domain, "Chibisafe Loose Files", await bunkr_parse(url), url)- # elif 'cyberdrop' in url.host:- # await Cascade.add_to_album(base_domain, "Chibisafe Loose Files", await cyberdrop_parse(url), url)- else:- await Cascade.add_to_album(base_domain, "Chibisafe Loose Files", url, url)- else:- Chibisafe_urls.append(url)-- elif base_domain in mapping_Erome:- Erome_urls.append(url)-- elif base_domain in mapping_GoFile:- GoFile_urls.append(url)-- elif base_domain in mapping_Pixeldrain:- title = str(url).split('/')[-1]- await Cascade.add_to_album(base_domain, title, await pixeldrain_parse(url, title), url)-- elif base_domain in mapping_Anonfiles:- Anonfiles_urls.append(url)-- elif base_domain in mapping_Thotsbay:- Thotsbay_urls.append(url)-- else:- await log(str(url) + " is not supported currently.")-- return ShareX_urls, Chibisafe_urls, Erome_urls, GoFile_urls, Thotsbay_urls, Anonfiles_urlsdiff --git a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.pyindex 206786273..253af3d4d 100644--- a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py+++ b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py@@ -4,31 +4,24 @@ from bs4 import BeautifulSoupfrom colorama import Forefrom yarl import URL-from .Anonfiles_Spider import AnonfilesCrawler-from .Chibisafe_Spider import ChibisafeCrawler-from .Erome_Spider import EromeCrawler-from .GoFile_Spider import GofileCrawler-from .ShareX_Spider import ShareXCrawler-from ..base_functions import check_direct, log, logger, make_title_safe, ssl_context, url_sort+from ..base_functions import log, logger, make_title_safe, ssl_contextfrom ..data_classes import CascadeItemclass ThotsbayCrawler():- def __init__(self, *, include_id=False, username=None, password=None, erome_crawler: EromeCrawler,- sharex_crawler: ShareXCrawler, chibisafe_crawler: ChibisafeCrawler, gofile_crawler: GofileCrawler,- anonfiles_crawler: AnonfilesCrawler):+ def __init__(self, *, include_id=False, username=None, password=None, scraping_mapper, session):self.include_id = include_idself.username = usernameself.password = password- self.erome_crawler = erome_crawler- self.sharex_crawler = sharex_crawler- self.chibisafe_crawler = chibisafe_crawler- self.gofile_crawler = gofile_crawler- self.anonfiles_crawler = anonfiles_crawler+ self.scraping_mapper = scraping_mapper+ self.session = session+ self.lock = 0async def login(self, session):async with session.get("https://forum.thotsbay.com/login", ssl=ssl_context) as response:text = await response.text()+ if "You are already logged in" in text:+ returnsoup = BeautifulSoup(text, 'html.parser')inputs = soup.select('form input')@@ -40,48 +33,31 @@ class ThotsbayCrawler():data.update({"login": self.username, "password": self.password})return await session.post("https://forum.thotsbay.com/login/login", data=data)- async def fetch(self, session, url):- Cascade = CascadeItem({})-+ async def fetch(self, session, url: URL):await log("Starting scrape of " + str(url), Fore.WHITE)+ Cascade = CascadeItem({})if self.username and self.password:- await self.login(session)+ if self.lock == 0:+ self.lock = 1+ await self.login(session)+ 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.")try:- ShareX_urls, Chibisafe_urls, Erome_urls, GoFile_urls, Thotsbay_urls, Anonfile_urls, title = await self.parse(session, url, Cascade, None)- except:+ title = await self.parse_thread(session, url, Cascade, None)+ except Exception:await log("Error handling " + str(url))return-- tasks = []- for url in Erome_urls:- tasks.append(self.erome_crawler.fetch(session, url))- for url in ShareX_urls:- if await check_direct(url):- await Cascade.add_to_album(url.host, "ShareX Loose Files", url, url)- tasks.append(self.sharex_crawler.fetch(session, url))- for url in Chibisafe_urls:- if await check_direct(url):- await Cascade.add_to_album(url.host, "Chibisafe Loose Files", url, url)- tasks.append(self.chibisafe_crawler.fetch(session, url))- for url in GoFile_urls:- tasks.append(self.gofile_crawler.fetch(session, url))- for url in Anonfile_urls:- tasks.append(self.anonfiles_crawler.fetch(session, url))- results = await asyncio.gather(*tasks)-- for result in results:- await Cascade.add_albums(result)-await Cascade.append_title(title)+await log("Finished scrape of " + str(url), Fore.WHITE)return Cascade- async def parse(self, session, url, Cascade, title):+ async def parse_thread(self, session, url, Cascade, title):try:async with session.get(url, ssl=ssl_context) as response:text = await response.text()@@ -112,6 +88,7 @@ class ThotsbayCrawler():for elem in post.find_all('blockquote'):elem.decompose()post_content = post.select_one("div[class=bbWrapper]")+links = post_content.select('a')for link in links:link = link.get('href')@@ -122,12 +99,14 @@ class ThotsbayCrawler():elif link.startswith('/'):link = URL("https://forum.thotsbay.com") / link[1:]content_links.append(URL(link))+links = post.select("div[class='bbImageWrapper js-lbImage']")for link in links:link = link.get('data-src')if link.endswith("/"):link = link[:-1]content_links.append(URL(link))+links = post.select("video source")for link in links:link = link.get('src')@@ -147,11 +126,13 @@ class ThotsbayCrawler():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)- ShareX_urls, Chibisafe_urls, Erome_urls, GoFile_urls, Thotsbay_urls, Anonfile_urls = await url_sort(content_links, Cascade)-- for link in Thotsbay_urls:+ 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:if str(link).endswith("/"):link = URL(str(link)[:-1])if 'attachments' in link.parts:@@ -159,6 +140,11 @@ class ThotsbayCrawler():elif 'data' in link.parts:await Cascade.add_to_album("Thotsbay.com", "Attachments", link, url)+ tasks = []+ for link in content_links:+ tasks.append(self.scraping_mapper.map_url(link, title))+ await asyncio.gather(*tasks)+next_page = soup.select_one('a[class="pageNav-jump pageNav-jump--next"]')if next_page is not None:next_page = next_page.get('href')@@ -166,14 +152,8 @@ class ThotsbayCrawler():if next_page.startswith('/'):next_page = URL("https://forum.thotsbay.com") / next_page[1:]next_page = URL(next_page)- ShareX_urls_ret, Chibisafe_urls_ret, Erome_urls_ret, GoFile_urls_ret, Thotsbay_urls_ret, Anonfile_urls_ret, title = await self.parse(session, next_page, Cascade, title)- ShareX_urls.extend(ShareX_urls_ret)- Chibisafe_urls.extend(Chibisafe_urls_ret)- Erome_urls.extend(Erome_urls_ret)- GoFile_urls.extend(GoFile_urls_ret)- Thotsbay_urls.extend(Thotsbay_urls_ret)- Anonfile_urls.extend(Anonfile_urls_ret)- return ShareX_urls, Chibisafe_urls, Erome_urls, GoFile_urls, Thotsbay_urls, Anonfile_urls, title+ title = await self.parse_thread(session, next_page, Cascade, title)+ return titleexcept Exception as e:logger.debug("Error encountered while handling %s", str(url), exc_info=True)diff --git a/cyberdrop_dl/utils/data_classes.py b/cyberdrop_dl/utils/data_classes.pyindex 6a40c76b9..aed63217a 100644--- a/cyberdrop_dl/utils/data_classes.py+++ b/cyberdrop_dl/utils/data_classes.py@@ -39,6 +39,14 @@ class DomainItem:else:self.albums[title] = album+ async def append_title(self, title):+ new_albums = {}+ for album_str, album in self.albums.items():+ new_title = title+'/'+album_str+ new_albums[new_title] = album+ album.title = new_title+ self.albums = new_albums+@dataclassclass CascadeItem:diff --git a/cyberdrop_dl/utils/scraper.py b/cyberdrop_dl/utils/scraper.pyindex fcf9f1643..3fb3d1c06 100644--- a/cyberdrop_dl/utils/scraper.py+++ b/cyberdrop_dl/utils/scraper.py@@ -3,64 +3,23 @@ import asyncioimport aiohttpfrom colorama import Fore-from .base_functions import log, url_sort, user_agent-from .crawlers.Anonfiles_Spider import AnonfilesCrawler-from .crawlers.Chibisafe_Spider import ChibisafeCrawler-from .crawlers.Erome_Spider import EromeCrawler-from .crawlers.GoFile_Spider import GofileCrawler-from .crawlers.ShareX_Spider import ShareXCrawler-from .crawlers.Thotsbay_Spider import ThotsbayCrawler-from .data_classes import CascadeItem+from .base_functions import log, user_agent+from .scraper_helper import ScrapeMapperasync def scrape(urls, include_id: bool, thotsbay_username: str, thotsbay_password: str):- Cascade = CascadeItem({})-await log("Starting Scrape", Fore.WHITE)-- ShareX_urls, Chibisafe_urls, Erome_urls, GoFile_urls, Thotsbay_urls, Anonfile_urls = await url_sort(urls, Cascade)-- erome_crawler = EromeCrawler(include_id=include_id)- sharex_crawler = ShareXCrawler(include_id=include_id)- chibisafe_crawler = ChibisafeCrawler(include_id=include_id)- gofile_crawler = GofileCrawler()- anonfiles_crawler = AnonfilesCrawler(include_id=include_id)- thotsbay_crawler = ThotsbayCrawler(include_id=include_id, username=thotsbay_username, password=thotsbay_password,- erome_crawler=erome_crawler, sharex_crawler=sharex_crawler,- chibisafe_crawler=chibisafe_crawler, gofile_crawler=gofile_crawler,- anonfiles_crawler=anonfiles_crawler)-- tasks = []headers = {"user-agent": user_agent}jar = aiohttp.CookieJar(quote_cookie=False)async with aiohttp.ClientSession(headers=headers, raise_for_status=True, cookie_jar=jar) as session:- # Returns Domain items- for url in Erome_urls:- tasks.append(erome_crawler.fetch(session, url))- for url in ShareX_urls:- tasks.append(sharex_crawler.fetch(session, url))- for url in Chibisafe_urls:- tasks.append(chibisafe_crawler.fetch(session, url))- for url in GoFile_urls:- tasks.append(gofile_crawler.fetch(session, url))- for url in Anonfile_urls:- tasks.append(anonfiles_crawler.fetch(session, url))- results = await asyncio.gather(*tasks)-- for domain_item in results:- await Cascade.add_albums(domain_item)-- # Returns a Cascade item- results = []- for url in Thotsbay_urls:- results.append(await thotsbay_crawler.fetch(session, url))-- for result in results:- if result:- if result.domains:- await Cascade.extend(result)+ scraper = ScrapeMapper(session=session, include_id=include_id, username=thotsbay_username, password=thotsbay_password)+ tasks = []+ for link in urls:+ tasks.append(scraper.map_url(link))+ await asyncio.gather(*tasks)+ Cascade = scraper.CascadeCascade.cookies = jarawait Cascade.dedupe()return Cascadediff --git a/cyberdrop_dl/utils/scraper_helper.py b/cyberdrop_dl/utils/scraper_helper.pynew file mode 100644index 000000000..2bfedcaf2--- /dev/null+++ b/cyberdrop_dl/utils/scraper_helper.py@@ -0,0 +1,91 @@+import tldextract+from yarl import URL++from .crawlers.Anonfiles_Spider import AnonfilesCrawler+from .crawlers.Chibisafe_Spider import ChibisafeCrawler+from .crawlers.Erome_Spider import EromeCrawler+from .crawlers.GoFile_Spider import GofileCrawler+from .crawlers.ShareX_Spider import ShareXCrawler+from .crawlers.Thotsbay_Spider import ThotsbayCrawler+from .base_functions import log, pixeldrain_parse+from .data_classes import CascadeItem+++class ScrapeMapper():+ def __init__(self, *, session, include_id=False, username=None, password=None):+ self.include_id = include_id+ self.username = username+ self.password = password+ self.session = session+ self.Cascade = CascadeItem({})+ self.erome_crawler = None+ self.sharex_crawler = None+ self.chibisafe_crawler = None+ self.gofile_crawler = None+ self.anonfiles_crawler = None+ self.thotsbay_crawler = None+ self.mapping = {"pixl.is": self.ShareX, "putme.ga": self.ShareX, "putmega.com": self.ShareX,+ "jpg.church": self.ShareX, "cyberdrop.me": self.Chibisafe, "cyberdrop.cc": self.Chibisafe,+ "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}++ async def ShareX(self, url: URL, title=None):+ if not self.sharex_crawler:+ self.sharex_crawler = ShareXCrawler(include_id=self.include_id)+ domain_obj = await self.sharex_crawler.fetch(self.session, url)+ if title:+ await domain_obj.append_title(title)+ await self.Cascade.add_albums(domain_obj)++ async def Chibisafe(self, url: URL, title=None):+ if not self.chibisafe_crawler:+ self.chibisafe_crawler = ChibisafeCrawler(include_id=self.include_id)+ domain_obj = await self.chibisafe_crawler.fetch(self.session, url)+ if title:+ await domain_obj.append_title(title)+ await self.Cascade.add_albums(domain_obj)++ async def GoFile(self, url: URL, title=None):+ if not self.gofile_crawler:+ self.gofile_crawler = GofileCrawler()+ domain_obj = await self.gofile_crawler.fetch(self.session, url)+ if title:+ await domain_obj.append_title(title)+ await self.Cascade.add_albums(domain_obj)++ async def Anonfiles(self, url: URL, title=None):+ if not self.anonfiles_crawler:+ self.anonfiles_crawler = AnonfilesCrawler(include_id=self.include_id)+ domain_obj = await self.anonfiles_crawler.fetch(self.session, url)+ if title:+ await domain_obj.append_title(title)+ await self.Cascade.add_albums(domain_obj)++ async def Erome(self, url: URL, title=None):+ if not self.erome_crawler:+ self.erome_crawler = EromeCrawler(include_id=self.include_id)+ domain_obj = await self.erome_crawler.fetch(self.session, url)+ if title:+ await domain_obj.append_title(title)+ await self.Cascade.add_albums(domain_obj)++ async def Pixeldrain(self, url: URL, title=None):+ title_alb = str(url).split('/')[-1]+ title = title + "/" + title_alb if title else title_alb+ await self.Cascade.add_to_album("pixeldrain.com", title, await pixeldrain_parse(url, title), url)++ async def ThotsBay(self, url: URL, title=None):+ if not self.thotsbay_crawler:+ self.thotsbay_crawler = ThotsbayCrawler(include_id=self.include_id, username=self.username, password=self.password, scraping_mapper=self, session=self.session)+ 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.")