Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Minor fixes, logging, cleanup
Jules-WinnfieldX66ffc9dd05e4
diff --git a/cyberdrop_dl/utils/base_functions.py b/cyberdrop_dl/utils/base_functions.pyindex c23a81f39..6272a8d69 100644--- a/cyberdrop_dl/utils/base_functions.py+++ b/cyberdrop_dl/utils/base_functions.py@@ -22,6 +22,9 @@ FILE_FORMATS = {},'Audio': {'.mp3', '.flac', '.wav', '.m4a'+ },+ 'Other': {+ '.json'}}@@ -35,14 +38,11 @@ user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTM'Safari/537.36'MAX_FILENAME_LENGTH = 100-INVALID = [chr(x) for x in range(32)] + ['<', '>', ':', '"', '/', '\\', '|', '?', '*']-TRANSLATION = str.maketrans(''.join(INVALID), '_' * len(INVALID))-logger = logging.getLogger(__name__)def sanitize(input: str) -> str:- return input.translate(TRANSLATION)+ return re.sub(r'[<>:"/\\|?*]', "", input)def log(text, style = Fore.WHITE) -> None:diff --git a/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py b/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.pyindex c7dc71ceb..f600bddee 100644--- a/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py+++ b/cyberdrop_dl/utils/crawlers/Chibisafe_Spider.py@@ -15,6 +15,9 @@ class ChibisafeCrawler():domain_obj = DomainItem(base_domain, {})cookies = []+ log("Starting scrape of " + url, Fore.WHITE)+ logging.debug("Starting scrape of " + url)+try:async with session.get(url) as response:text = await response.text()@@ -32,10 +35,15 @@ class ChibisafeCrawler():links = soup.select("a[class=image]")for link in links:link = link.get('href')+ if 'bunkr' in link:+ link = bunkr_parse(link)domain_obj.add_to_album(title, link, url)except Exception as e:logger.debug("Error encountered while handling %s", url, exc_info=True)logger.debug(e)+ log("Finished scrape of " + url, Fore.WHITE)+ logging.debug("Finished scrape of " + url)+return domain_obj, cookiesdiff --git a/cyberdrop_dl/utils/crawlers/Erome_Spider.py b/cyberdrop_dl/utils/crawlers/Erome_Spider.pyindex 1d7e195ae..8666ca709 100644--- a/cyberdrop_dl/utils/crawlers/Erome_Spider.py+++ b/cyberdrop_dl/utils/crawlers/Erome_Spider.py@@ -15,6 +15,9 @@ class EromeCrawler():domain_obj = DomainItem(base_domain, {})cookies = []+ log("Starting scrape of " + url, Fore.WHITE)+ logging.debug("Starting scrape of " + url)+try:async with session.get(url) as response:text = await response.text()@@ -39,4 +42,8 @@ class EromeCrawler():except Exception as e:logger.debug("Error encountered while handling %s", url, exc_info=True)logger.debug(e)++ log("Finished scrape of " + url, Fore.WHITE)+ logging.debug("Finished scrape of " + url)+return domain_obj, cookiesdiff --git a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py b/cyberdrop_dl/utils/crawlers/GoFile_Spider.pyindex d41c37be9..4d0795c89 100644--- a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py+++ b/cyberdrop_dl/utils/crawlers/GoFile_Spider.py@@ -3,6 +3,7 @@ from typing import Unionfrom gofile import Gofilefrom ..data_classes import *+from ..base_functions import *class GofileCrawler():@@ -13,8 +14,16 @@ class GofileCrawler():domain_obj = DomainItem('gofile.io', {})cookies = [{'name': 'accountToken', 'value': self.client.token}]results = await self.get_links(url)++ log("Starting scrape of " + url, Fore.WHITE)+ logging.debug("Starting scrape of " + url)+for result in results:domain_obj.add_to_album(result['title'], result['url'], result['referral'])++ log("Finished scrape of " + url, Fore.WHITE)+ logging.debug("Finished scrape of " + url)+return domain_obj, cookiesasync def get_links(self, url, og_title=None):diff --git a/cyberdrop_dl/utils/crawlers/ShareX_Spider.py b/cyberdrop_dl/utils/crawlers/ShareX_Spider.pyindex d4e24c179..23e9b4cf5 100644--- a/cyberdrop_dl/utils/crawlers/ShareX_Spider.py+++ b/cyberdrop_dl/utils/crawlers/ShareX_Spider.py@@ -15,6 +15,9 @@ class ShareXCrawler():domain_obj = DomainItem(base_domain, {})cookies = []+ log("Starting scrape of " + url, Fore.WHITE)+ logging.debug("Starting scrape of " + url)+if "/album/" in url or "/a/" in url:results = await self.parse(url, session)elif "/albums" in url:@@ -25,6 +28,10 @@ class ShareXCrawler():results = await self.parse_profile(url, session)for result in results:domain_obj.add_to_album(result['title'], result['url'], result['referral'])++ log("Finished scrape of " + url, Fore.WHITE)+ logging.debug("Finished scrape of " + url)+return domain_obj, cookiesasync def get_albums(self, url, session):@@ -66,7 +73,8 @@ class ShareXCrawler():albums = soup.select("div[class=pad-content-listing] div")for album in albums:album_url = album.get('data-url-short')- results.extend(result for result in await self.parse(album_url, session, og_title=og_title))+ if album_url is not None:+ results.extend(result for result in await self.parse(album_url, session, og_title=og_title))except Exception as e:logger.debug("Error encountered while handling %s", url, exc_info=True)logger.debug(e)@@ -109,9 +117,10 @@ class ShareXCrawler():link = link.get('src')link = link.replace('.md.', '.').replace('.th.', '.')results.append({'url': link, 'title': title, 'referral': url, 'cookies': ''})- next_page = soup.select_one('li.pagination-next a')+ next_page = soup.select_one('li.pagination-next a')+ if next_page is not None:+ next_page = next_page.get('href')if next_page is not None:- next_page = next_page.get('href')results.extend(result for result in await self.get_list_links(next_page, session, title))except Exception as e:logger.debug("Error encountered while handling %s", url, exc_info=True)diff --git a/cyberdrop_dl/utils/downloaders.py b/cyberdrop_dl/utils/downloaders.pyindex 3d82c8d27..b82abd28e 100644--- a/cyberdrop_dl/utils/downloaders.py+++ b/cyberdrop_dl/utils/downloaders.py@@ -98,7 +98,7 @@ class Downloader:await throttle(self, yarl.URL(url))ext = '.'+filename.split('.')[-1]- if not (ext in FILE_FORMATS['Images'] or ext in FILE_FORMATS['Videos'] or ext in FILE_FORMATS['Audio']):+ if not (ext in FILE_FORMATS['Images'] or ext in FILE_FORMATS['Videos'] or ext in FILE_FORMATS['Audio'] or ext in FILE_FORMATS['Other']):resp = await session.get(url, headers=headers, ssl=ssl_context, raise_for_status=True)filename = resp.content_disposition.filenamefilename = sanitize(filename)