Skip to content

Bulk asynchronous downloader for multiple file hosts

Added ability to blacklist domains

Jules-WinnfieldX0ffc9ce7a666
diff --git a/README.md b/README.md
index c7aa90983..81728408f 100644
--- a/README.md
+++ b/README.md
@@ -88,9 +88,20 @@ optional arguments:
--thotsbay-password password to login to thotsbay (only required if the thread requires it)
--cyberfile-username username for cyberfile (used to access the api)
--cyberfile-password password for cyberfile (used to access the api)
-```
-
-# Credit
-The majority of the new download methodology came from alexdotis' [Chibisafe-Sharex-Scraper](https://github.com/alexdotis/Chibisafe-Sharex-Scraper).
-Added to his code was the ability to take a more descriptive url object containing the album title, netloc and content urls.
-The download methodology now also checks for existing files. Simplified bunkr pairing to stop blank objects from being created and passed to the rest of the program.
+ --skip-anonfiles this removes anonfile links from downloads
+ --skip-bunkr this removes bunkr links from downloads
+ --skip-coomer this removes coomer links from downloads
+ --skip-cyberdrop this removes cyberdrop links from downloads
+ --skip-cyberfile this removes cyberfile links from downloads
+ --skip-erome this removes erome links from downloads
+ --skip-gfycat this removes gfycat links from downloads
+ --skip-gofile this removes gofile links from downloads
+ --skip-jpgchurch this removes jpgchurch links from downloads
+ --skip-kemono this removes kemono links from downloads
+ --skip-pixeldrain this removes pixeldrain links from downloads
+ --skip-pixl this removes pixl links from downloads
+ --skip-putmega this removes putmega links from downloads
+ --skip-redgif this removes redgif links from downloads
+ --skip-saint this removes saint links from downloads
+
+```
\ No newline at end of file
diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py
index c2908cf34..65d245594 100644
--- a/cyberdrop_dl/__init__.py
+++ b/cyberdrop_dl/__init__.py
@@ -1 +1 @@
-__version__ = "2.22.4"
+__version__ = "2.22.5"
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index 7654c5bd8..b75888528 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -10,7 +10,7 @@ from yarl import URL
from . import __version__ as VERSION
from .utils.base_functions import clear, log, logger, purge_dir, regex_links
-from .utils.data_classes import AuthData
+from .utils.data_classes import AuthData, SkipData
from .utils.downloaders import get_downloaders
from .utils.scraper import scrape
from .utils.sql_helper import SQLHelper
@@ -22,8 +22,7 @@ def parse_args():
parser.add_argument("-i", "--input-file", type=Path, help="file containing links to download", default="URLs.txt")
parser.add_argument("-o", "--output-folder", type=Path, help="folder to download files to", default="Downloads")
parser.add_argument("--log-file", help="log file to write to", default="downloader.log")
- parser.add_argument("--db-file", help="history database file to write to",
- default="download_history.sqlite")
+ parser.add_argument("--db-file", help="history database file to write to", default="download_history.sqlite")
parser.add_argument("--threads", type=int, help="number of threads to use (0 = max)", default=0)
parser.add_argument("--attempts", type=int, help="number of attempts to download each file", default=10)
parser.add_argument("--disable-attempt-limit", help="disables the attempt limitation", action="store_true")
@@ -33,10 +32,25 @@ def parse_args():
parser.add_argument("--exclude-audio", help="skip downloading of audio files", action="store_true")
parser.add_argument("--exclude-other", help="skip downloading of images", action="store_true")
parser.add_argument("--ignore-history", help="This ignores previous download history", action="store_true")
- parser.add_argument("--separate-posts", help="separates thotsbay scraping into folders by post",
- action="store_true")
+ parser.add_argument("--separate-posts", help="Separates thotsbay scraping into folders by post number", action="store_true")
parser.add_argument("--thotsbay-username", type=str, help="username to login to thotsbay", default=None)
parser.add_argument("--thotsbay-password", type=str, help="password to login to thotsbay", default=None)
+ parser.add_argument("--skip-anonfiles", help="This removes anonfile links from downloads", action="store_true")
+ parser.add_argument("--skip-bunkr", help="This removes bunkr links from downloads", action="store_true")
+ parser.add_argument("--skip-coomer", help="This removes coomer links from downloads", action="store_true")
+ parser.add_argument("--skip-cyberdrop", help="This removes cyberdrop links from downloads", action="store_true")
+ parser.add_argument("--skip-cyberfile", help="This removes cyberfile links from downloads", action="store_true")
+ parser.add_argument("--skip-erome", help="This removes erome links from downloads", action="store_true")
+ parser.add_argument("--skip-gfycat", help="This removes gfycat links from downloads", action="store_true")
+ parser.add_argument("--skip-gofile", help="This removes gofile links from downloads", action="store_true")
+ parser.add_argument("--skip-jpgchurch", help="This removes jpg.church links from downloads", action="store_true")
+ parser.add_argument("--skip-kemono", help="This removes kemono links from downloads", action="store_true")
+ parser.add_argument("--skip-pixeldrain", help="This removes pixeldrain links from downloads", action="store_true")
+ parser.add_argument("--skip-pixl", help="This removes pixl links from downloads", action="store_true")
+ parser.add_argument("--skip-putmega", help="This removes putmega links from downloads", action="store_true")
+ parser.add_argument("--skip-redgif", help="This removes redgif links from downloads", action="store_true")
+ parser.add_argument("--skip-saint", help="This removes saint.to links from downloads", action="store_true")
+
parser.add_argument("links", metavar="link", nargs="*",
help="link to content to download (passing multiple links is supported)", default=[])
args = parser.parse_args()
@@ -64,7 +78,12 @@ async def download_all(args: argparse.Namespace):
with open(input_file, "r", encoding="utf8") as f:
links += await regex_links(f.read())
thotsbay_auth = AuthData(args.thotsbay_username, args.thotsbay_password)
- content_object = await scrape(links, args.include_id, thotsbay_auth, args.separate_posts)
+ skip_data = SkipData()
+ await skip_data.add_skips(args.skip_anonfiles, args.skip_bunkr, args.skip_coomer, args.skip_cyberdrop,
+ args.skip_cyberfile, args.skip_erome, args.skip_gfycat, args.skip_gofile,
+ args.skip_jpgchurch, args.skip_kemono, args.skip_pixeldrain, args.skip_pixl,
+ args.skip_putmega, args.skip_redgif, args.skip_saint)
+ content_object = await scrape(links, args.include_id, thotsbay_auth, args.separate_posts, skip_data)
if await content_object.is_empty():
logging.error(f'ValueError No links')
await log("No links found, check the URL.txt\nIf the link works in your web browser, "
diff --git a/cyberdrop_dl/utils/data_classes.py b/cyberdrop_dl/utils/data_classes.py
index be29dba0e..e1553aa5b 100644
--- a/cyberdrop_dl/utils/data_classes.py
+++ b/cyberdrop_dl/utils/data_classes.py
@@ -1,11 +1,6 @@
import asyncio
-import collections
-from collections import defaultdict
from dataclasses import dataclass
-from datetime import datetime
-from types import TracebackType
-from typing import Dict, List, Optional, Tuple, Callable, Awaitable, Any, Type
-from random import gauss
+from typing import Dict, List, Optional, Tuple
import aiohttp
from yarl import URL
@@ -146,58 +141,45 @@ class AuthData:
password: str
-class AsyncRateLimiter:
- """
- Provides rate limiting for an operation with a configurable number of requests for a time period.
- """
-
- __lock: asyncio.Lock
- callback: Optional[Callable[[float], Awaitable[Any]]]
- max_calls: int
- period: float
- calls: collections.deque
-
- def __init__(
- self,
- max_calls: int,
- period: float = 1.0,
- callback: Optional[Callable[[float], Awaitable[Any]]] = None,
- ):
- if period <= 0:
- raise ValueError("Rate limiting period should be > 0")
- if max_calls <= 0:
- raise ValueError("Rate limiting number of calls should be > 0")
- self.calls = collections.deque()
-
- self.period = period
- self.max_calls = max_calls
- self.callback = callback
- self.__lock = asyncio.Lock()
-
- async def __aenter__(self) -> "AsyncRateLimiter":
- async with self.__lock:
- if len(self.calls) >= self.max_calls:
- until = datetime.utcnow().timestamp() + self.period - self._timespan
- if self.callback:
- asyncio.ensure_future(self.callback(until))
- sleep_time = until - datetime.utcnow().timestamp()
- if sleep_time > 0:
- await asyncio.sleep(sleep_time)
- return self
-
- async def __aexit__(
- self,
- exc_type: Type[BaseException],
- exc_val: BaseException,
- exc_tb: TracebackType,
- ) -> None:
- async with self.__lock:
- # Store the last operation timestamp.
- self.calls.append(datetime.utcnow().timestamp())
-
- while self._timespan >= self.period:
- self.calls.popleft()
-
- @property
- def _timespan(self) -> float:
- return self.calls[-1] - self.calls[0]
+@dataclass
+class SkipData:
+ sites = {"anonfiles.com": False, "bunkr": False, "coomer.party": False,
+ "cyberdrop": False, "cyberfile.is": False, "erome.com": False, "gfycat.com": False,
+ "gofile.io": False, "jpg.church": False, "kemono.party": False, "pixeldrain.com": False,
+ "pixl.is": False, "putme.ga": False, "putmega.com": False, "redgifs.com": False,
+ "saint.to": False, "thotsbay.com": False}
+
+ async def add_skips(self, anonfiles, bunkr, coomer, cyberdrop, cyberfile, erome, gfycat, gofile, jpgchurch,
+ kemono, pixeldrain, pixl, putmega, redgifs, saint):
+ if anonfiles:
+ self.sites['anonfiles'] = True
+ if bunkr:
+ self.sites['bunkr'] = True
+ if coomer:
+ self.sites['coomer.party'] = True
+ if cyberdrop:
+ self.sites['cyberdrop'] = True
+ if cyberfile:
+ self.sites['cyberfile.is'] = True
+ if erome:
+ self.sites['erome.com'] = True
+ if gfycat:
+ self.sites['gfycat.com'] = True
+ if gofile:
+ self.sites['gofile.io'] = True
+ if jpgchurch:
+ self.sites['jpg.church'] = True
+ if kemono:
+ self.sites['kemono.party'] = True
+ if pixeldrain:
+ self.sites['pixeldrain.com'] = True
+ if pixl:
+ self.sites['pixl.is'] = True
+ if putmega:
+ self.sites['putme.ga'] = True
+ self.sites['putmega.com'] = True
+ if redgifs:
+ self.sites['redgifs.com'] = True
+ if saint:
+ self.sites['saint.to'] = True
+
diff --git a/cyberdrop_dl/utils/downloaders.py b/cyberdrop_dl/utils/downloaders.py
index 74f250ea0..f83fc8e55 100644
--- a/cyberdrop_dl/utils/downloaders.py
+++ b/cyberdrop_dl/utils/downloaders.py
@@ -1,11 +1,10 @@
import asyncio
import logging
import multiprocessing
-import time
import traceback
from functools import wraps
from pathlib import Path
-from typing import List, Optional, Tuple
+from typing import List, Tuple
from random import gauss
import aiofiles
@@ -18,6 +17,7 @@ from yarl import URL
from .base_functions import FILE_FORMATS, MAX_FILENAME_LENGTH, log, logger, sanitize, ssl_context, user_agent
from .sql_helper import SQLHelper
from .data_classes import AlbumItem, CascadeItem, FileLock
+from .rate_limiting import throttle
class FailureException(Exception):
@@ -42,30 +42,6 @@ def retry(f):
return wrapper
-async def throttle(self, delay, host) -> None:
- if delay is None:
- return
-
- key: Optional[str] = None
- while True:
- if key is None:
- key = 'throttle:{}'.format(host)
- now = time.time()
- last = self.throttle_times.get(key, 0.0)
- elapsed = now - last
-
- if elapsed >= delay:
- self.throttle_times[key] = now
- return
-
- remaining = delay - elapsed + 0.25
-
- log_string = '\nDelaying request to %s for %.2f seconds.' % (
- host, remaining)
- logger.debug(log_string)
- await asyncio.sleep(remaining)
-
-
class Downloader:
def __init__(self, album_obj: AlbumItem, cookie_jar, folder: Path, title: str, attempts: int,
disable_attempt_limit: bool, max_workers: int, exclude_videos: bool, exclude_images: bool,
diff --git a/cyberdrop_dl/utils/rate_limiting.py b/cyberdrop_dl/utils/rate_limiting.py
new file mode 100644
index 000000000..b250f77ca
--- /dev/null
+++ b/cyberdrop_dl/utils/rate_limiting.py
@@ -0,0 +1,88 @@
+import asyncio
+import collections
+import time
+
+from datetime import datetime
+from types import TracebackType
+from typing import Optional, Callable, Awaitable, Any, Type
+
+
+class AsyncRateLimiter:
+ """
+ Provides rate limiting for an operation with a configurable number of requests for a time period.
+ """
+
+ __lock: asyncio.Lock
+ callback: Optional[Callable[[float], Awaitable[Any]]]
+ max_calls: int
+ period: float
+ calls: collections.deque
+
+ def __init__(
+ self,
+ max_calls: int,
+ period: float = 1.0,
+ callback: Optional[Callable[[float], Awaitable[Any]]] = None,
+ ):
+ if period <= 0:
+ raise ValueError("Rate limiting period should be > 0")
+ if max_calls <= 0:
+ raise ValueError("Rate limiting number of calls should be > 0")
+ self.calls = collections.deque()
+
+ self.period = period
+ self.max_calls = max_calls
+ self.callback = callback
+ self.__lock = asyncio.Lock()
+
+ async def __aenter__(self) -> "AsyncRateLimiter":
+ async with self.__lock:
+ if len(self.calls) >= self.max_calls:
+ until = datetime.utcnow().timestamp() + self.period - self._timespan
+ if self.callback:
+ asyncio.ensure_future(self.callback(until))
+ sleep_time = until - datetime.utcnow().timestamp()
+ if sleep_time > 0:
+ await asyncio.sleep(sleep_time)
+ return self
+
+ async def __aexit__(
+ self,
+ exc_type: Type[BaseException],
+ exc_val: BaseException,
+ exc_tb: TracebackType,
+ ) -> None:
+ async with self.__lock:
+ # Store the last operation timestamp.
+ self.calls.append(datetime.utcnow().timestamp())
+
+ while self._timespan >= self.period:
+ self.calls.popleft()
+
+ @property
+ def _timespan(self) -> float:
+ return self.calls[-1] - self.calls[0]
+
+
+async def throttle(self, delay, host) -> None:
+ if delay is None:
+ return
+
+ key: Optional[str] = None
+ while True:
+ if key is None:
+ key = 'throttle:{}'.format(host)
+ now = time.time()
+ last = self.throttle_times.get(key, 0.0)
+ elapsed = now - last
+
+ if elapsed >= delay:
+ self.throttle_times[key] = now
+ return
+
+ remaining = delay - elapsed + 0.25
+
+ log_string = '\nDelaying request to %s for %.2f seconds.' % (
+ host, remaining)
+ logger.debug(log_string)
+ await asyncio.sleep(remaining)
\ No newline at end of file
diff --git a/cyberdrop_dl/utils/scraper.py b/cyberdrop_dl/utils/scraper.py
index b021e1c04..4db7b39bc 100644
--- a/cyberdrop_dl/utils/scraper.py
+++ b/cyberdrop_dl/utils/scraper.py
@@ -4,18 +4,18 @@ import aiohttp
from colorama import Fore
from .base_functions import log, user_agent
-from .data_classes import AuthData
+from .data_classes import AuthData, SkipData
from .scraper_helper import ScrapeMapper
-async def scrape(urls, include_id: bool, thotsbay_auth: AuthData, separate_posts: bool):
+async def scrape(urls, include_id: bool, thotsbay_auth: AuthData, separate_posts: bool, skip_data: SkipData):
await log("Starting Scrape", Fore.WHITE)
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:
scraper = ScrapeMapper(session=session, include_id=include_id, thotsbay_auth=thotsbay_auth,
- separate_posts=separate_posts)
+ separate_posts=separate_posts, skip_data=skip_data)
tasks = []
for link in urls:
tasks.append(scraper.map_url(link))
diff --git a/cyberdrop_dl/utils/scraper_helper.py b/cyberdrop_dl/utils/scraper_helper.py
index 42e008904..ec162d9ab 100644
--- a/cyberdrop_dl/utils/scraper_helper.py
+++ b/cyberdrop_dl/utils/scraper_helper.py
@@ -18,16 +18,18 @@ from .crawlers.Saint_Spider import SaintCrawler
from .crawlers.ShareX_Spider import ShareXCrawler
from .crawlers.Thotsbay_Spider import ThotsbayCrawler
from .base_functions import log
-from .data_classes import CascadeItem, AsyncRateLimiter
+from .data_classes import CascadeItem, SkipData
+from .rate_limiting import AsyncRateLimiter
class ScrapeMapper():
- def __init__(self, *, session, include_id=False, thotsbay_auth=None, separate_posts=False):
+ def __init__(self, *, session, include_id=False, thotsbay_auth=None, separate_posts=False, skip_data: SkipData):
self.include_id = include_id
self.separate_posts = separate_posts
self.thotsbay_auth = thotsbay_auth
self.session = session
self.Cascade = CascadeItem({})
+ self.skip_data = skip_data
self.anonfiles_crawler = None
self.bunkr_crawler = None
@@ -45,8 +47,7 @@ class ScrapeMapper():
self.thotsbay_crawler = None
self.semaphore = asyncio.Semaphore(1)
- self.mapping = {"anonfiles.com": self.Anonfiles, "bunkr.is": self.Bunkr,
- "bunkr.to": self.Bunkr, "coomer.party": self.coomer,
+ self.mapping = {"anonfiles.com": self.Anonfiles, "bunkr": self.Bunkr, "coomer.party": self.coomer,
"cyberdrop": self.Cyberdrop, "cyberfile.is": self.cyberfile,
"erome.com": self.Erome, "gfycat.com": self.gfycat,
"gofile.io": self.GoFile, "jpg.church": self.ShareX,
@@ -182,8 +183,12 @@ class ScrapeMapper():
async def map_url(self, url_to_map: URL, title=None):
for key, value in self.mapping.items():
if key in url_to_map.host:
- await value(url=url_to_map, title=title)
- return
+ if not self.skip_data.sites[key]:
+ await value(url=url_to_map, title=title)
+ return
+ else:
+ await log("Skipping scrape of " + str(url_to_map))
+ return
await log(str(url_to_map) + " is not supported currently.")
async with aiofiles.open("./Unsupported_Urls.txt", mode='a') as f:
await f.write(str(url_to_map)+"\n")