Skip to content

Bulk asynchronous downloader for multiple file hosts

Implement a config file that can be used instead of CLI args.

Jules-WinnfieldXff3115fe41ca
diff --git a/.gitignore b/.gitignore
index 6239c3baa..641311933 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,10 @@
-# project stuff
+# Project stuff
Downloads/
*.log
*.sqlite
+config.yaml
+Unsupported_Urls.txt
+URLs_last_post.txt
# Python stuff
.venv/
@@ -10,11 +13,3 @@ __pycache__/
build/
release/
start_dev.py
-.vscode/settings.json
-
-# Scripts
-run.bat
-input.txt
-_download_log.txt
-input-test.txt
-Unsupported_Urls.txt
diff --git a/README.md b/README.md
index 36548e459..1fedc1285 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# `cyberdrop-dl`
**Bulk downloader for multiple file hosts**
-The latest version of the program is 3.3.35
+The latest version of the program is 3.3.38
<a href="https://www.buymeacoffee.com/juleswinnft" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
diff --git a/cyberdrop_dl/base_functions/base_functions.py b/cyberdrop_dl/base_functions/base_functions.py
index d2d3b630f..1994a1d17 100644
--- a/cyberdrop_dl/base_functions/base_functions.py
+++ b/cyberdrop_dl/base_functions/base_functions.py
@@ -1,12 +1,17 @@
+from typing import Dict
+
import aiofiles
import logging
import os
import re
from pathlib import Path
+import yaml
from colorama import Fore, Style
from yarl import URL
+from .config_schema import config_default, files_args, authentication_args, jdownloader_args, runtime_args
+
"""This file contains generic information and functions that are used around the program"""
FILE_FORMATS = {
@@ -61,7 +66,7 @@ async def purge_dir(dirname, in_place=True):
for tree_element in dir_tree:
sub_dir = tree_element[0]
dir_count = len(os.listdir(sub_dir))
- if dir_count == 0: # Helps with readability and i've had issues with it deleting non-empty dirs
+ if dir_count == 0: # Helps with readability and i've had issues with it deleting non-empty dirs
deleted.append(sub_dir)
if in_place:
@@ -94,6 +99,85 @@ async def write_last_post_file(file: Path, url: str):
async def check_direct(url: URL):
mapping_direct = ['i.pixl.is', r's..putmega.com', r's..putme.ga', r'img-...cyberdrop...', r'f.cyberdrop...',
- r'fs-...cyberdrop...', r'cdn.bunkr...', r'cdn..bunkr...', r'media-files.bunkr...', r'media-files..bunkr...', r'jpg.church/images/...',
- r'simp..jpg.church']
+ r'fs-...cyberdrop...', r'cdn.bunkr...', r'cdn..bunkr...', r'media-files.bunkr...',
+ r'media-files..bunkr...', r'jpg.church/images/...', r'simp..jpg.church']
return any(re.search(domain, url.host) for domain in mapping_direct)
+
+
+async def create_config(config: Path, passed_args=None):
+ if config.is_file() and not passed_args:
+ await validate_config(config)
+ return
+
+ config_data = config_default
+ if passed_args:
+ for arg in authentication_args:
+ if arg in passed_args.keys():
+ config_data[0]["Configuration"]["Authentication"][arg] = passed_args[arg]
+ for arg in files_args:
+ if arg in passed_args.keys():
+ config_data[0]["Configuration"]["Files"][arg] = str(passed_args[arg])
+ for arg in jdownloader_args:
+ if arg in passed_args.keys():
+ config_data[0]["Configuration"]["JDownloader"][arg] = passed_args[arg]
+ for arg in runtime_args:
+ if arg in passed_args.keys():
+ config_data[0]["Configuration"]["Runtime"][arg] = passed_args[arg]
+
+ with open(config, 'w') as yamlfile:
+ yaml.dump(config_data, yamlfile)
+ return
+
+
+async def validate_config(config: Path):
+ with open(config, "r") as yamlfile:
+ data = yaml.load(yamlfile, Loader=yaml.FullLoader)
+ data = data[0]["Configuration"]
+ recreate = 0
+ try:
+ if not set(authentication_args).issubset(set(data['Authentication'].keys())):
+ recreate = 1
+ if not set(authentication_args).issubset(set(data['Files'].keys())):
+ recreate = 1
+ if not set(authentication_args).issubset(set(data['JDownloader'].keys())):
+ recreate = 1
+ if not set(authentication_args).issubset(set(data['Runtime'].keys())):
+ recreate = 1
+
+ if recreate:
+ config.unlink()
+ await log("Recreating Config")
+
+ args = {}
+ args_list = [data['Authentication'], data['Files'], data['JDownloader'], data['Runtime']]
+ for dic in args_list:
+ args.update(dic)
+ await create_config(config, args)
+
+ except KeyError:
+ config.unlink()
+ await log("Config was malformed, recreating.")
+ await create_config(config)
+
+
+async def run_args(config: Path, cmd_arg: Dict):
+ with open(config, "r") as yamlfile:
+ data = yaml.load(yamlfile, Loader=yaml.FullLoader)
+ data = data[0]["Configuration"]
+ if data['Apply_Config']:
+ return data
+
+ config_data = config_default[0]["Configuration"]
+ for arg in authentication_args:
+ if arg in cmd_arg.keys():
+ config_data["Authentication"][arg] = cmd_arg[arg]
+ for arg in files_args:
+ if arg in cmd_arg.keys():
+ config_data["Files"][arg] = cmd_arg[arg]
+ for arg in jdownloader_args:
+ if arg in cmd_arg.keys():
+ config_data["JDownloader"][arg] = cmd_arg[arg]
+ for arg in runtime_args:
+ if arg in cmd_arg.keys():
+ config_data["Runtime"][arg] = cmd_arg[arg]
+ return config_data
diff --git a/cyberdrop_dl/base_functions/config_schema.py b/cyberdrop_dl/base_functions/config_schema.py
new file mode 100644
index 000000000..a3fd5b7a9
--- /dev/null
+++ b/cyberdrop_dl/base_functions/config_schema.py
@@ -0,0 +1,53 @@
+config_default = [
+ {
+ "Configuration": {
+ "Apply_Config": False,
+ "Files": {
+ "input_file": "URLs.txt",
+ "output_folder": "Downloads",
+ "db_file": "download_history.sqlite",
+ },
+ "Authentication": {
+ "simpcity_username": "",
+ "simpcity_password": "",
+ "socialmediagirls_username": "",
+ "socialmediagirls_password": "",
+ "xbunker_username": "",
+ "xbunker_password": "",
+ },
+ "JDownloader": {
+ "jdownloader_enable": False,
+ "jdownloader_username": "",
+ "jdownloader_password": "",
+ "jdownloader_device": "",
+ },
+ "Runtime": {
+ "threads": 0,
+ "attempts": 10,
+ "disable_attempt_limit": False,
+ "connection_timeout": 15,
+ "ratelimit": 50,
+ "throttle": 0.5,
+ "include_id": False,
+ "exclude_videos": False,
+ "exclude_images": False,
+ "exclude_audio": False,
+ "exclude_other": False,
+ "ignore_history": False,
+ "output_last_forum_post": False,
+ "separate_posts": False,
+ "proxy": "",
+ "skip_hosts": [],
+ }
+ }
+ }
+]
+
+files_args = ["input_file", "output_folder", "db_file"]
+authentication_args = ["simpcity_username", "simpcity_password",
+ "socialmediagirls_username", "socialmediagirls_password",
+ "xbunker_username", "xbunker_password"]
+jdownloader_args = ["jdownloader_enable", "jdownloader_username", "jdownloader_password", "jdownloader_device"]
+runtime_args = ["threads", "attempts", "disabled_attempt_limit", "connection_timeout", "ratelimit", "throttle",
+ "include_id", "exclude_videos", "exclude_images", "exclude_audio", "exclude_other", "ignore_history",
+ "output_last_forum_post", "separate_posts", "skip_hosts", "proxy"]
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index 838211ad8..0b8f28de3 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -1,10 +1,8 @@
import argparse
import multiprocessing
-import platform
from argparse import Namespace
import asyncio
import logging
-from asyncio.proactor_events import _ProactorBasePipeTransport
from pathlib import Path
from functools import wraps
@@ -12,7 +10,8 @@ from colorama import Fore
from yarl import URL
from . import __version__ as VERSION
-from cyberdrop_dl.base_functions.base_functions import clear, log, logger, purge_dir, regex_links
+from cyberdrop_dl.base_functions.base_functions import clear, create_config, log, logger, purge_dir, regex_links, \
+ run_args
from cyberdrop_dl.base_functions.data_classes import AuthData, SkipData
from cyberdrop_dl.base_functions.sql_helper import SQLHelper
from cyberdrop_dl.client.client import Client
@@ -25,8 +24,9 @@ def parse_args():
parser.add_argument("-V", "--version", action="version", version="%(prog)s " + VERSION)
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("--log-file", type=Path, help="log file to write to", default="downloader.log")
+ parser.add_argument("--config-file", type=Path, help="config file to read arguments from", default="config.yaml")
+ parser.add_argument("--db-file", type=Path, 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("--connection-timeout", type=int, help="number of seconds to wait attempting to connect to a URL during the downloading phase", default=15)
@@ -67,8 +67,33 @@ async def download_all(args: argparse.Namespace):
print_args['simpcity_password'] = '!REDACTED!'
print_args['jdownloader_password'] = '!REDACTED!'
- logging.debug(f"Starting downloader with args: {print_args}")
- input_file = args.input_file
+ cmd_args = Namespace(**vars(args)).__dict__
+ await create_config(args.config_file, print_args)
+ use_args = await run_args(args.config_file, cmd_args)
+
+ auth_args = use_args['Authentication']
+ auth_args_print = auth_args
+ auth_args_print['xbunker_password'] = '!REDACTED!'
+ auth_args_print['socialmediagirls_password'] = '!REDACTED!'
+ auth_args_print['simpcity_password'] = '!REDACTED!'
+
+ file_args = use_args['Files']
+ for key, value in file_args.items():
+ file_args[key] = Path(value)
+
+ jdownloader_args = use_args['JDownloader']
+ jdownloader_args_print = jdownloader_args
+ jdownloader_args_print['jdownloader_password'] = '!REDACTED!'
+
+ runtime_args = use_args['Runtime']
+
+ logging.debug(f"Starting Cyberdrop-DL")
+ logging.debug(f"Using authorization arguments: {auth_args_print}")
+ logging.debug(f"Using file arguments: {file_args}")
+ logging.debug(f"Using jdownloader arguments: {jdownloader_args}")
+ logging.debug(f"Using runtime arguments: {runtime_args}")
+
+ input_file = file_args['input_file']
if not input_file.is_file():
input_file.touch()
await log(f"{input_file} created. Populate it and retry.")
@@ -160,10 +185,6 @@ def main(args=None):
filemode="w"
)
- if platform.system() == 'Windows':
- # Silence the "Event loop is closed" exception here.
- _ProactorBasePipeTransport.__del__ = silence_event_loop_closed(_ProactorBasePipeTransport.__del__)
-
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(download_all(args))
diff --git a/requirements.txt b/requirements.txt
index 0dd5ce64c..9561a00c1 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -27,13 +27,14 @@ pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
PyDispatcher==2.0.6
+PyYAML==6.0
queuelib==1.6.2
requests==2.28.1
requests-file==1.5.1
six==1.16.0
tqdm==4.64.1
-typing_extensions==4.3.0
+typing_extensions==4.4.0
urllib3==1.26.12
yarl==1.8.1
-zope.interface==5.4.0
+zope.interface==5.5.0
myjdapi==1.1.6