Skip to content

Bulk asynchronous downloader for multiple file hosts

Include better direct link handling. Fix error message stating it wasn't supported, and test adjustable retry count.

Julesb23e6707c798
diff --git a/main.py b/main.py
index 62788b7da..ade58ee0a 100644
--- a/main.py
+++ b/main.py
@@ -60,7 +60,7 @@ async def main():
cookies, content_object = scrape(urls)
if not content_object:
logging.error(f'ValueError No links: {content_object}')
- raise ValueError('No links found, check the URL.txt\nNote: This utility only supports album links, not direct links to pictures or videos.')
+ raise ValueError('No links found, check the URL.txt\nIf the link works in your web browser, please open an issue ticket with me.')
downloaders = get_downloaders(content_object, cookies=cookies, folder=Path(DOWNLOAD_FOLDER), max_workers=CPU_COUNT)
diff --git a/settings.py b/settings.py
index 3297e46b4..27421b6c5 100644
--- a/settings.py
+++ b/settings.py
@@ -4,4 +4,5 @@
# download_folder = "./Downloads/" will download in the CyberDropDownloader folder
threads = 0
-download_folder = "./Downloads/"
\ No newline at end of file
+download_folder = "./Downloads/"
+download_attempts = 1
\ No newline at end of file
diff --git a/utils/downloaders.py b/utils/downloaders.py
index 26b9b1715..342ccfa57 100644
--- a/utils/downloaders.py
+++ b/utils/downloaders.py
@@ -15,6 +15,7 @@ from sanitize_filename import sanitize
import ssl
import certifi
from http.cookies import SimpleCookie
+import settings
logger = logging.getLogger(__name__)
@@ -62,6 +63,7 @@ def retry(
# logger.exception(exc)
if times_tried > attempts:
logger.exception(f'Raised {exc} exceeded times_tried')
+ input("We've reached exception")
raise exc
times_tried += 1
await asyncio.sleep(timeout)
@@ -81,7 +83,7 @@ class Downloader:
self._semaphore = asyncio.Semaphore(max_workers)
"""Changed from aiohttp exceptions caught to FailureException to allow for partial downloads."""
- @retry(attempts=10, timeout=4, exceptions=FailureException)
+ @retry(attempts=settings.download_attempts, timeout=4, exceptions=FailureException)
async def download_file(
self,
url: str,
@@ -259,11 +261,15 @@ def get_downloaders(urls: Dict[str, Dict[str, List[str]]], cookies: Iterable[str
"""
mapping = {
'cyberdrop.me': Downloader,
+ 'cyberdrop.cc': Downloader,
+ 'cyberdrop.to': Downloader,
+ 'cyberdrop.nl': Downloader,
'bunkr.is': LimitDownloader,
+ 'bunkr.to': LimitDownloader,
'pixl.is': Downloader,
+ 'rpcs0112.b-cdn.net': Downloader,
'putme.ga': Downloader,
'putmega.com': Downloader,
- 'cyberdrop.to': Downloader,
'gofile.io': Downloader
}
@@ -272,8 +278,8 @@ def get_downloaders(urls: Dict[str, Dict[str, List[str]]], cookies: Iterable[str
for domain, url_object in urls.items():
if domain not in mapping:
- logging.error('Invalid URL!')
- raise ValueError('Invalid URL!')
+ logging.error('Invalid domain '+domain)
+ raise ValueError('Invalid domain '+domain)
for title, urls in url_object.items():
downloader = mapping[domain](urls, morsels=morsels, title=title, folder=folder, max_workers=max_workers)
downloaders.append(downloader)
diff --git a/utils/scrapers.py b/utils/scrapers.py
index 0a65056e1..07fb7cde3 100644
--- a/utils/scrapers.py
+++ b/utils/scrapers.py
@@ -171,18 +171,27 @@ def sanitize_key(key):
return key
+def check_direct(url):
+ mapping_direct = ['i.pixl.is', r's..putmega.com', r's..putme.ga', 'img-...cyberdrop...', 'f.cyberdrop...', 'fs-...cyberdrop...', 'cdn.bunkr...']
+ for domain in mapping_direct:
+ if re.search(domain, url): return True
+ return False
+
+
def scrape(urls):
mapping_ShareX = ["pixl.is", "putme.ga", "putmega.com"]
- mapping_Chibisafe = ["cyberdrop.me", "cyberdrop.cc", "cyberdrop.to", "bunkr.is", "bunkr.to"]
+ mapping_Chibisafe = ["cyberdrop.me", "cyberdrop.cc", "cyberdrop.to", "cyberdrop.nl", "bunkr.is", "bunkr.to"]
mapping_GoFile = ["gofile.io"]
replacements = [
('fs-...', ''),
+ ('f\.', ''),
('img-...', ''),
('i\.', ''),
- ('stream.', ''),
- ('www.', ''),
- ('cdn.', '')
+ ('stream\.', ''),
+ ('www\.', ''),
+ ('cdn\.', ''),
+ ('s.\.', '')
]
ShareX_urls = []
@@ -198,11 +207,16 @@ def scrape(urls):
base_domain = urlparse(url).netloc
for old, new in replacements:
base_domain = re.sub(old, new, base_domain)
-
if base_domain in mapping_ShareX:
- ShareX_urls.append(url)
+ if check_direct(url):
+ result_links.setdefault(base_domain, OrderedDict()).setdefault("ShareX Loose Files", []).append([url, url])
+ else:
+ ShareX_urls.append(url)
elif base_domain in mapping_Chibisafe:
- Chibisafe_urls.append(url)
+ if check_direct(url):
+ result_links.setdefault(base_domain, OrderedDict()).setdefault("Chibisafe Loose Files", []).append([url, url])
+ else:
+ Chibisafe_urls.append(url)
elif base_domain in mapping_GoFile:
GoFile_urls.append(url)
else: