Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: allow any file name for cookie files (#403)
NTFSvolumece5e7582abae
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex aca016e77..872193b9e 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -18,7 +18,6 @@ from cyberdrop_dl.clients.errors import InvalidYamlErrorfrom cyberdrop_dl.managers.manager import Managerfrom cyberdrop_dl.scraper.scraper import ScrapeMapperfrom cyberdrop_dl.ui.program_ui import ProgramUI-from cyberdrop_dl.ui.prompts.user_prompts import get_cookies_from_browsersfrom cyberdrop_dl.utils.logger import RedactedConsole, log, log_spacer, log_with_color, print_to_consolefrom cyberdrop_dl.utils.sorting import Sorterfrom cyberdrop_dl.utils.utilities import (@@ -81,12 +80,6 @@ async def runtime(manager: Manager) -> None:await scrape_mapper.start()-def pre_runtime(manager: Manager) -> None:- """Actions to complete before main runtime."""- if manager.config_manager.settings_data.browser_cookies.auto_import:- get_cookies_from_browsers(manager)--async def post_runtime(manager: Manager) -> None:"""Actions to complete after main runtime, and before ui shutdown."""log_spacer(20, log_to_console=False)@@ -218,7 +211,6 @@ async def director(manager: Manager) -> None:log_spacer(10)log("Starting CDL...\n", 20)- pre_runtime(manager)await runtime(manager)await post_runtime(manager)diff --git a/cyberdrop_dl/managers/client_manager.py b/cyberdrop_dl/managers/client_manager.pyindex 03604553c..1532e181a 100644--- a/cyberdrop_dl/managers/client_manager.py+++ b/cyberdrop_dl/managers/client_manager.py@@ -4,6 +4,7 @@ import asyncioimport contextlibimport sslfrom http import HTTPStatus+from http.cookiejar import MozillaCookieJarfrom typing import TYPE_CHECKINGimport aiohttp@@ -17,8 +18,9 @@ from cyberdrop_dl.clients.download_client import DownloadClientfrom cyberdrop_dl.clients.errors import DDOSGuardError, DownloadError, ScrapeErrorfrom cyberdrop_dl.clients.scraper_client import ScraperClientfrom cyberdrop_dl.managers.download_speed_manager import DownloadSpeedLimiter+from cyberdrop_dl.ui.prompts.user_prompts import get_cookies_from_browsersfrom cyberdrop_dl.utils.constants import CustomHTTPStatus-from cyberdrop_dl.utils.logger import log+from cyberdrop_dl.utils.logger import log, log_spacerif TYPE_CHECKING:from cyberdrop_dl.managers.manager import Manager@@ -97,6 +99,34 @@ class ClientManager:"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""+ def load_cookie_files(self) -> None:+ if self.manager.config_manager.settings_data.browser_cookies.auto_import:+ get_cookies_from_browsers(self.manager)+ cookie_files = sorted(self.manager.path_manager.cookies_dir.glob("*.txt"))+ if not cookie_files:+ return++ domains_seen = set()+ for file in cookie_files:+ cookie_jar = MozillaCookieJar(file)+ try:+ cookie_jar.load(ignore_discard=True)+ except OSError as e:+ log(f"Unable to load cookies from '{file.name}':\n {e!s}", 40)+ continue+ current_cookie_file_domains = set()+ for cookie in cookie_jar:+ simplified_domain = cookie.domain[1:] if cookie.domain.startswith(".") else cookie.domain+ if simplified_domain not in current_cookie_file_domains:+ log(f"Found cookies for {simplified_domain} in file '{file.name}'", 20)+ current_cookie_file_domains.add(simplified_domain)+ if simplified_domain in domains_seen:+ log(f"Previous cookies for domain {simplified_domain} detected. They will be overwritten", 30)+ domains_seen.add(simplified_domain)+ self.cookies.update_cookies({cookie.name: cookie.value}, response_url=URL(f"https://{cookie.domain}"))++ log_spacer(20, log_to_console=False)+async def get_downloader_spacer(self, key: str) -> float:"""Returns the download spacer for a domain."""if key in self.download_spacer:diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex d9afcc383..6d059f0ca 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -196,9 +196,6 @@ class Manager:config_settings.runtime_options.deep_scrape = self.config_manager.deep_scrapeconfig_settings = config_settings.model_dump_json(indent=4)global_settings = self.config_manager.global_settings_data.model_dump_json(indent=4)- cookie_files = [str(p) for p in self.path_manager.cookies_dir.rglob("*.txt")] or None- if cookie_files:- cookie_files = f"\n{json.dumps(sorted(cookie_files), indent=4, sort_keys=True)}"log("Starting Cyberdrop-DL Process", 10)log(f"Running Version: {__version__}", 10)@@ -210,7 +207,6 @@ class Manager:log(f"Using Authentication: \n{json.dumps(auth_provided, indent=4, sort_keys=True)}", 10)log(f"Using Settings: \n{config_settings}", 10)log(f"Using Global Settings: \n{global_settings}", 10)- log(f"Using Cookie Files: {cookie_files}", 10)async def close(self) -> None:"""Closes the manager."""diff --git a/cyberdrop_dl/scraper/crawler.py b/cyberdrop_dl/scraper/crawler.pyindex bfc73de89..56345dcfd 100644--- a/cyberdrop_dl/scraper/crawler.py+++ b/cyberdrop_dl/scraper/crawler.py@@ -5,7 +5,6 @@ import copyfrom abc import ABC, abstractmethodfrom dataclasses import fieldfrom functools import wraps-from http.cookiejar import MozillaCookieJarfrom typing import TYPE_CHECKING, Any, ClassVarfrom bs4 import BeautifulSoup@@ -50,19 +49,6 @@ class Crawler(ABC):"""Starts the crawler."""self.client = self.manager.client_manager.scraper_sessionself.downloader = Downloader(self.manager, self.domain)- self.cookiejar_file = self.manager.path_manager.cookies_dir / f"{self.primary_base_domain.host}.txt"- if self.cookiejar_file.is_file():- log(f"Found cookie file for: {self.domain}", 10)- try:- cookie_jar = MozillaCookieJar(self.cookiejar_file)- cookie_jar.load(ignore_discard=True)- for cookie in cookie_jar:- self.manager.client_manager.cookies.update_cookies(- {cookie.name: cookie.value}, response_url=URL(f"https://{cookie.domain}")- )- except Exception:- log(f"Unable to apply cookies from {self.cookiejar_file}", 10, exc_info=True)-self.downloader.startup()async def run(self, item: ScrapeItem) -> None:diff --git a/cyberdrop_dl/scraper/scraper.py b/cyberdrop_dl/scraper/scraper.pyindex 3c36a1438..c0d40bf6c 100644--- a/cyberdrop_dl/scraper/scraper.py+++ b/cyberdrop_dl/scraper/scraper.py@@ -82,11 +82,10 @@ class ScrapeMapper:async def start(self) -> None:"""Starts the orchestra."""self.manager.scrape_mapper = self-+ self.manager.client_manager.load_cookie_files()self.start_scrapers()self.start_jdownloader()self.start_real_debrid()-self.no_crawler_downloader.startup()if self.manager.parsed_args.cli_only_args.retry_failed:diff --git a/docs/reference/configuration-options/settings/browser_cookies.md b/docs/reference/configuration-options/settings/browser_cookies.mdindex d66a6e617..8387ebf86 100644--- a/docs/reference/configuration-options/settings/browser_cookies.md+++ b/docs/reference/configuration-options/settings/browser_cookies.md@@ -56,10 +56,8 @@ List of domains to extract cookies from. You can put any domain on the list, but## Manual Cookie Extraction-If cookie extraction fails, you can manually extract the cookies from your browser using tools like [cookie-editor](https://cookie-editor.com) and save them at `AppData/Cookies/<domain>.txt`, where domain is the full primary base domain of the site you exported the cookies from. The file must be a Netscape formatted cookie file+If cookie extraction fails, you can manually extract the cookies from your browser using tools like [cookie-editor](https://cookie-editor.com) and save them at `AppData/Cookies/<site_name>.txt`. The file must be a Netscape formatted cookie file. You can use any name for the file as long as it has a `.txt` extension.-### Examples--- For SocialMediaGirls, the name should be `forums.socialmediagirls.com.txt`-- For bunkrr, the name should be `bunkr.site.txt`-- For cyberdrop, the name should be `cyberdrop.me.txt`+{% hint style="info" %}+Multiple cookie files are supported. You could have a `SocialMediaGirls.txt` file and a `cyberdrop.txt` file, for example+{% endhint %}