Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: enable `--force-original-path` (#2131)

NTFSvolumeeb0e8c069c10
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5363465c8..ca6a53356 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support premium URLs (direct links)(GoFile)
- FileditchAlbums support
+### Changed
+
+- Enable the `--force-original-path` option on retry commands
+- Ask the user if they want to use the original download path after choosing `retry failed downloads` (main menu)
+
### Fixed
- Pagination of some profiles stopping early (Twitter/x.com)
diff --git a/cyberdrop_dl/clients/downloads.py b/cyberdrop_dl/clients/downloads.py
index 59b48db59..ddd92e969 100644
--- a/cyberdrop_dl/clients/downloads.py
+++ b/cyberdrop_dl/clients/downloads.py
@@ -13,7 +13,7 @@ from aiohttp import hdrs
from cyberdrop_dl import aio, constants, ffmpeg, storage
from cyberdrop_dl.clients import etag
from cyberdrop_dl.clients.http import JSON_CHECK, check_http_status
-from cyberdrop_dl.constants import FileExt
+from cyberdrop_dl.constants import USE_RETRY_PATH, FileExt
from cyberdrop_dl.exceptions import DownloadError, InvalidContentTypeError, SlowDownloadError
from cyberdrop_dl.signature import simple_repr
from cyberdrop_dl.utils import dates, enter_context
@@ -479,7 +479,7 @@ async def _check_response(media_item: MediaItem, resp: AbstractResponse[Any], re
def resolve_download_dir(download_folder: Path, config: Config) -> Path:
- if config.subfolders.create:
+ if config.subfolders.create or USE_RETRY_PATH.get():
return download_folder
while download_folder.parent != config.download_folder:
diff --git a/cyberdrop_dl/commands/retry.py b/cyberdrop_dl/commands/retry.py
index 2910dea2c..886c325a1 100644
--- a/cyberdrop_dl/commands/retry.py
+++ b/cyberdrop_dl/commands/retry.py
@@ -6,7 +6,7 @@ from cyclopts import App, Parameter
from cyberdrop_dl.commands import CLIarguments
from cyberdrop_dl.commands.scrape import prepare_manager, scrape
from cyberdrop_dl.config import Config
-from cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup
+from cyberdrop_dl.constants import USE_RETRY_PATH
from cyberdrop_dl.models import ConfigModel
from cyberdrop_dl.scrape_source import RetryScrapeSource, RetrySource
@@ -35,8 +35,7 @@ def _tomorrow() -> datetime.date:
def create_retry_src(retry: RetrySource, args: RetryArgs | None = None) -> RetryScrapeSource:
args = args or RetryArgs()
if args.force_original_path:
- error = RuntimeError("Support for '--force-original-path' has been temporarily removed")
- raise CDLConfigRuntimeErrorsGroup("Unsupported option", (error,))
+ USE_RETRY_PATH.set(True)
return RetryScrapeSource(retry, after=args.from_, before=args.to or _tomorrow())
diff --git a/cyberdrop_dl/constants.py b/cyberdrop_dl/constants.py
index 9c7b4fd51..67f96374c 100644
--- a/cyberdrop_dl/constants.py
+++ b/cyberdrop_dl/constants.py
@@ -25,6 +25,7 @@ MISSING: Any = Sentinel("MISSING")
HttpMethod = Literal["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE", "PATCH", "QUERY"]
MAIN_LOG_FILE: ContextVar[Path] = ContextVar("MAIN_LOG_FILE")
+USE_RETRY_PATH: ContextVar[bool] = ContextVar("USE_RETRY_PATH", default=False)
DEFAULT_PARAMETER = Parameter(
negative_iterable=[],
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index c504b2fe3..bec679aba 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -18,7 +18,7 @@ from cyberdrop_dl import aio, env
from cyberdrop_dl.cache import TTLCacheAdapter
from cyberdrop_dl.clients.downloads import IGNORE_CONTENT_TYPE
from cyberdrop_dl.clients.http import HTTPClient, HTTPConfig, HTTPContext, HTTPMixin
-from cyberdrop_dl.constants import FileExt, HttpMethod
+from cyberdrop_dl.constants import USE_RETRY_PATH, FileExt, HttpMethod
from cyberdrop_dl.crawlers import ALLOW_NO_EXT, SKIP_DOWNLOAD, Registry
from cyberdrop_dl.crawlers._hls import HLSMixin
from cyberdrop_dl.downloader.http import Downloader
@@ -1231,6 +1231,8 @@ def _should_skip_by_config(media_item: MediaItem, config: Config) -> bool:
def _prepare_download_path(item: ScrapeItem, domain: str) -> Path:
+ if item.retry_info and USE_RETRY_PATH.get():
+ return item.retry_info.download_path
path = item.download_folder / item.path
if item.is_loose_file:
path = path / f"Loose Files ({domain})"
diff --git a/cyberdrop_dl/program_ui.py b/cyberdrop_dl/program_ui.py
index fd906a6b9..bc31463b8 100644
--- a/cyberdrop_dl/program_ui.py
+++ b/cyberdrop_dl/program_ui.py
@@ -8,6 +8,7 @@ import aiohttp
from rich.markdown import Markdown
from cyberdrop_dl import __version__, aio, stats
+from cyberdrop_dl.constants import USE_RETRY_PATH
from cyberdrop_dl.hasher import Hasher, hash_directory
from cyberdrop_dl.progress import hyperlink
from cyberdrop_dl.prompts import (
@@ -15,6 +16,7 @@ from cyberdrop_dl.prompts import (
ask_confirmation,
ask_dir,
ask_should_create_config,
+ ask_should_use_retry_path,
console,
enter_to_continue,
)
@@ -45,7 +47,7 @@ def run(manager: Manager, input_file: Path) -> RetrySource | Path:
_INPUT_FILE.set(input_file)
choices: dict[str, Callable[[Manager], RetrySource | Path | None]] = {
"Download": lambda _: input_file,
- "Retry failed downloads": lambda _: RetrySource.FAILED,
+ "Retry failed downloads": _retry_failed,
"Create file hashes": _scan_and_create_hashes,
"Sort files in download folder": _sort_files,
"Edit URLs.txt": lambda _: _edit_urls(),
@@ -62,6 +64,11 @@ def run(manager: Manager, input_file: Path) -> RetrySource | Path:
return source
+def _retry_failed(_: object) -> RetrySource:
+ USE_RETRY_PATH.set(ask_should_use_retry_path())
+ return RetrySource.FAILED
+
+
def _scan_and_create_hashes(manager: Manager) -> None:
path = ask_dir("Select the directory to scan", default=manager.config.download_folder)
with Hasher.create(manager.config, manager.database, path) as hasher:
diff --git a/cyberdrop_dl/prompts.py b/cyberdrop_dl/prompts.py
index 8c21677b6..96a1dfa2b 100644
--- a/cyberdrop_dl/prompts.py
+++ b/cyberdrop_dl/prompts.py
@@ -125,3 +125,7 @@ def ask_should_create_config(file: Path) -> bool:
def ask_should_create_folder(folder: Path) -> bool:
console.warning(f"Folder '{folder}' does not exists")
return ask_confirmation("Do you want to create it?")
+
+
+def ask_should_use_retry_path() -> bool:
+ return ask_confirmation("Do you want to use the exact same download path as the original attempt?")