Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: disable cache (#759)
datawhores8dc82ef4ae4c
diff --git a/cyberdrop_dl/clients/scraper_client.py b/cyberdrop_dl/clients/scraper_client.pyindex 20caa319c..9d038f0da 100644--- a/cyberdrop_dl/clients/scraper_client.py+++ b/cyberdrop_dl/clients/scraper_client.py@@ -10,6 +10,7 @@ from aiohttp_client_cache import CachedSessionfrom aiohttp_client_cache.response import CachedStreamReaderfrom bs4 import BeautifulSoup+import cyberdrop_dl.utils.constants as constantsfrom cyberdrop_dl.clients.errors import DDOSGuardError, InvalidContentTypeErrorfrom cyberdrop_dl.utils.logger import log_debug@@ -49,7 +50,7 @@ def limiter(func: Callable) -> Any:@asynccontextmanagerasync def cache_control_manager(client_session: CachedSession, disabled: bool = False):- client_session.cache.disabled = disabled+ client_session.cache.disabled = constants.DISABLE_CACHE or disabledyieldclient_session.cache.disabled = Falsediff --git a/cyberdrop_dl/managers/cache_manager.py b/cyberdrop_dl/managers/cache_manager.pyindex c25b00dcd..a528039c9 100644--- a/cyberdrop_dl/managers/cache_manager.py+++ b/cyberdrop_dl/managers/cache_manager.py@@ -5,7 +5,7 @@ from datetime import timedeltafrom http import HTTPStatusfrom typing import TYPE_CHECKING, Any-from aiohttp_client_cache import SQLiteBackend+from aiohttp_client_cache import CacheBackend, SQLiteBackendfrom cyberdrop_dl import __version__ as current_versionfrom cyberdrop_dl.scraper.filters import filter_fn@@ -22,7 +22,7 @@ class CacheManager:def __init__(self, manager: Manager) -> None:self.manager = manager- self.request_cache: SQLiteBackend = field(init=False)+ self.request_cache: SQLiteBackend | CacheBackend = field(init=False)self.cache_file: Path = field(init=False)self._cache = {}@@ -50,7 +50,6 @@ class CacheManager:urls_expire_after[match_host] = rate_limiting_options.file_host_cache_expire_afterfor forum in SUPPORTED_FORUMS.values():urls_expire_after[forum] = rate_limiting_options.forum_cache_expire_after-self.request_cache = SQLiteBackend(cache_name=self.manager.path_manager.cache_db,autoclose=False,diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex 191768e72..013d7deb9 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -80,6 +80,7 @@ class Manager:self.adjust_for_simpcity()if self.config_manager.loaded_config.casefold() == "all" or self.parsed_args.cli_only_args.multiconfig:self.multiconfig = True+ self.set_constants()def adjust_for_simpcity(self) -> None:"""Adjusts settings for SimpCity update."""@@ -245,6 +246,12 @@ class Manager:for config in all_configs:self.config_manager.change_config(config)+ def set_constants(self):+ """+ rewrite constants after config/arg manager have loaded+ """+ constants.DISABLE_CACHE = self.parsed_args.cli_only_args.disable_cache+def get_system_information() -> str:system_info = {diff --git a/cyberdrop_dl/scraper/crawlers/reddit_crawler.py b/cyberdrop_dl/scraper/crawlers/reddit_crawler.pyindex afb5ecdb6..4e7f26f17 100644--- a/cyberdrop_dl/scraper/crawlers/reddit_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/reddit_crawler.py@@ -12,6 +12,7 @@ from asyncpraw import Redditfrom yarl import URLfrom cyberdrop_dl.clients.errors import LoginError, NoExtensionError, ScrapeError+from cyberdrop_dl.clients.scraper_client import cache_control_managerfrom cyberdrop_dl.scraper.crawler import Crawler, create_task_idfrom cyberdrop_dl.utils.data_enums_classes.url_objects import FILE_HOST_ALBUM, FILE_HOST_PROFILE, ScrapeItemfrom cyberdrop_dl.utils.logger import log, log_debug@@ -66,14 +67,15 @@ class RedditCrawler(Crawler):async with CachedSession(cache=self.manager.cache_manager.request_cache, trace_configs=self.trace_configs) as session:- reddit = self.new_reddit_conn(session)- if any(part in scrape_item.url.parts for part in ("user", "u")):- return await self.user(scrape_item, reddit)- if any(part in scrape_item.url.parts for part in ("comments", "r")):- return await self.subreddit(scrape_item, reddit)- if "redd.it" in scrape_item.url.host:- return await self.media(scrape_item, reddit)- raise ValueError+ async with cache_control_manager(session):+ reddit = self.new_reddit_conn(session)+ if any(part in scrape_item.url.parts for part in ("user", "u")):+ return await self.user(scrape_item, reddit)+ if any(part in scrape_item.url.parts for part in ("comments", "r")):+ return await self.subreddit(scrape_item, reddit)+ if "redd.it" in scrape_item.url.host:+ return await self.media(scrape_item, reddit)+ raise ValueError@error_handling_wrapperasync def user(self, scrape_item: ScrapeItem, reddit: Reddit) -> None:diff --git a/cyberdrop_dl/scraper/filters.py b/cyberdrop_dl/scraper/filters.pyindex aa8511c8f..03e2f8f44 100644--- a/cyberdrop_dl/scraper/filters.py+++ b/cyberdrop_dl/scraper/filters.py@@ -7,6 +7,7 @@ import arrowfrom bs4 import BeautifulSoupfrom yarl import URL+import cyberdrop_dl.utils.constants as constantsfrom cyberdrop_dl.clients.errors import NoExtensionErrorfrom cyberdrop_dl.utils.constants import FILE_FORMATSfrom cyberdrop_dl.utils.utilities import get_filename_and_ext@@ -98,6 +99,8 @@ async def get_return_value(url: URL | str) -> bool | None:async def filter_fn(response: ClientResponse) -> bool:"""Filter function for aiohttp_client_cache"""+ if constants.DISABLE_CACHE:+ return FalseHTTP_404_LIKE_STATUS = {HTTPStatus.NOT_FOUND, HTTPStatus.GONE, HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS}if response.status in HTTP_404_LIKE_STATUS:diff --git a/cyberdrop_dl/utils/args.py b/cyberdrop_dl/utils/args.pyindex d08f8868c..36cc70bae 100644--- a/cyberdrop_dl/utils/args.py+++ b/cyberdrop_dl/utils/args.py@@ -58,6 +58,7 @@ class CommandLineOnlyArgs(BaseModel):print_stats: bool = Field(True, description="Show stats report at the end of a run")ui: UIOptions = Field(UIOptions.FULLSCREEN, description="DISABLED, ACTIVITY, SIMPLE or FULLSCREEN")portrait: bool = Field(False, description="show UI in a portrait layout")+ disable_cache: bool = Field(False, description="Temporarily disable the requests cache")@propertydef retry_any(self) -> bool:diff --git a/cyberdrop_dl/utils/constants.py b/cyberdrop_dl/utils/constants.pyindex 982da2ec3..7ece8738c 100644--- a/cyberdrop_dl/utils/constants.py+++ b/cyberdrop_dl/utils/constants.py@@ -143,3 +143,4 @@ FILE_FORMATS = {MEDIA_EXTENSIONS = FILE_FORMATS["Audio"] | FILE_FORMATS["Videos"] | FILE_FORMATS["Images"]+DISABLE_CACHE = Nonediff --git a/docs/reference/cli-arguments.md b/docs/reference/cli-arguments.mdindex 84eef2ef0..946aecb62 100644--- a/docs/reference/cli-arguments.md+++ b/docs/reference/cli-arguments.md@@ -137,6 +137,22 @@ Retry failed downloadsRetry download of maintenance files (bunkr). Requires files to be hashed+***++### `disable-cache`++| Type | Default | Action |+| ---------- | ------- | ------------ |+| `BoolFlag` | `False` | `store_true` |++Disables the use of the requests cache for the current run only+all config settings or arguments relating to the cache expiry such as file_host_cache_expire_after will be ignored++{% hint style="info" %}+This does not affect the original cache+{% endhint %}++***## Overview