mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-05 23:37:58 +10:00
move default yt-dlp args to config.json YTDLP_ARGS for user override
- Move hardcoded default args from Python to config.json YTDLP_ARGS - Add get_ytdlp_args() function to read from YTDLP_ARGS env var - Keep format arg with max_size in code (depends on YTDLP_MAX_SIZE) - YTDLP_ARGS can be overridden as JSON array in environment
This commit is contained in:
@@ -41,20 +41,31 @@
|
|||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {"type": "string"},
|
"items": {"type": "string"},
|
||||||
"default": [
|
"default": [
|
||||||
|
"--restrict-filenames",
|
||||||
|
"--trim-filenames", "128",
|
||||||
|
"--write-description",
|
||||||
"--write-info-json",
|
"--write-info-json",
|
||||||
"--write-thumbnail",
|
"--write-thumbnail",
|
||||||
"--write-sub",
|
"--write-sub",
|
||||||
"--embed-subs",
|
"--write-auto-subs",
|
||||||
"--write-auto-sub"
|
"--convert-subs=srt",
|
||||||
|
"--yes-playlist",
|
||||||
|
"--continue",
|
||||||
|
"--no-abort-on-error",
|
||||||
|
"--ignore-errors",
|
||||||
|
"--geo-bypass",
|
||||||
|
"--add-metadata",
|
||||||
|
"--no-progress",
|
||||||
|
"-o", "%(title)s.%(ext)s"
|
||||||
],
|
],
|
||||||
"x-aliases": ["MEDIA_ARGS"],
|
"x-aliases": ["MEDIA_ARGS"],
|
||||||
"description": "Default yt-dlp arguments"
|
"description": "Default yt-dlp arguments (override to customize behavior)"
|
||||||
},
|
},
|
||||||
"YTDLP_EXTRA_ARGS": {
|
"YTDLP_EXTRA_ARGS": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"x-aliases": ["MEDIA_EXTRA_ARGS"],
|
"x-aliases": ["MEDIA_EXTRA_ARGS"],
|
||||||
"description": "Extra arguments for yt-dlp (space-separated)"
|
"description": "Extra arguments for yt-dlp (space-separated, appended after YTDLP_ARGS)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ Environment variables:
|
|||||||
YTDLP_BINARY: Path to yt-dlp binary
|
YTDLP_BINARY: Path to yt-dlp binary
|
||||||
YTDLP_TIMEOUT: Timeout in seconds (default: 3600 for large downloads)
|
YTDLP_TIMEOUT: Timeout in seconds (default: 3600 for large downloads)
|
||||||
YTDLP_CHECK_SSL_VALIDITY: Whether to check SSL certificates (default: True)
|
YTDLP_CHECK_SSL_VALIDITY: Whether to check SSL certificates (default: True)
|
||||||
YTDLP_EXTRA_ARGS: Extra arguments for yt-dlp (space-separated)
|
YTDLP_ARGS: JSON array of yt-dlp arguments (overrides defaults)
|
||||||
|
YTDLP_EXTRA_ARGS: Extra arguments for yt-dlp (space-separated, appended)
|
||||||
YTDLP_MAX_SIZE: Maximum file size (default: 750m)
|
YTDLP_MAX_SIZE: Maximum file size (default: 750m)
|
||||||
|
|
||||||
# Feature toggles (with backwards-compatible aliases)
|
# Feature toggles (with backwards-compatible aliases)
|
||||||
@@ -66,26 +67,39 @@ def has_staticfile_output() -> bool:
|
|||||||
return staticfile_dir.exists() and any(staticfile_dir.iterdir())
|
return staticfile_dir.exists() and any(staticfile_dir.iterdir())
|
||||||
|
|
||||||
|
|
||||||
# Default yt-dlp args (from old YTDLP_CONFIG)
|
# Default yt-dlp args (can be overridden via YTDLP_ARGS env var)
|
||||||
def get_ytdlp_default_args(max_size: str = '750m') -> list[str]:
|
YTDLP_DEFAULT_ARGS = [
|
||||||
"""Build default yt-dlp arguments."""
|
'--restrict-filenames',
|
||||||
return [
|
'--trim-filenames', '128',
|
||||||
'--restrict-filenames',
|
'--write-description',
|
||||||
'--trim-filenames', '128',
|
'--write-info-json',
|
||||||
'--write-description',
|
'--write-thumbnail',
|
||||||
'--write-info-json',
|
'--write-sub',
|
||||||
'--write-thumbnail',
|
'--write-auto-subs',
|
||||||
'--write-sub',
|
'--convert-subs=srt',
|
||||||
'--write-auto-subs',
|
'--yes-playlist',
|
||||||
'--convert-subs=srt',
|
'--continue',
|
||||||
'--yes-playlist',
|
'--no-abort-on-error',
|
||||||
'--continue',
|
'--ignore-errors',
|
||||||
'--no-abort-on-error',
|
'--geo-bypass',
|
||||||
'--ignore-errors',
|
'--add-metadata',
|
||||||
'--geo-bypass',
|
'--no-progress',
|
||||||
'--add-metadata',
|
'-o', '%(title)s.%(ext)s',
|
||||||
f'--format=(bv*+ba/b)[filesize<={max_size}][filesize_approx<=?{max_size}]/(bv*+ba/b)',
|
]
|
||||||
]
|
|
||||||
|
|
||||||
|
def get_ytdlp_args() -> list[str]:
|
||||||
|
"""Get yt-dlp arguments from YTDLP_ARGS env var or use defaults."""
|
||||||
|
ytdlp_args_str = get_env('YTDLP_ARGS', '')
|
||||||
|
if ytdlp_args_str:
|
||||||
|
try:
|
||||||
|
# Try to parse as JSON array
|
||||||
|
args = json.loads(ytdlp_args_str)
|
||||||
|
if isinstance(args, list):
|
||||||
|
return [str(arg) for arg in args]
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
pass
|
||||||
|
return YTDLP_DEFAULT_ARGS
|
||||||
|
|
||||||
|
|
||||||
def save_ytdlp(url: str, binary: str) -> tuple[bool, str | None, str]:
|
def save_ytdlp(url: str, binary: str) -> tuple[bool, str | None, str]:
|
||||||
@@ -103,12 +117,12 @@ def save_ytdlp(url: str, binary: str) -> tuple[bool, str | None, str]:
|
|||||||
# Output directory is current directory (hook already runs in output dir)
|
# Output directory is current directory (hook already runs in output dir)
|
||||||
output_dir = Path(OUTPUT_DIR)
|
output_dir = Path(OUTPUT_DIR)
|
||||||
|
|
||||||
# Build command (later options take precedence)
|
# Build command using configurable YTDLP_ARGS (later options take precedence)
|
||||||
cmd = [
|
cmd = [
|
||||||
binary,
|
binary,
|
||||||
*get_ytdlp_default_args(max_size),
|
*get_ytdlp_args(),
|
||||||
'--no-progress',
|
# Format with max_size limit (appended after YTDLP_ARGS so it can be overridden by YTDLP_EXTRA_ARGS)
|
||||||
'-o', '%(title)s.%(ext)s',
|
f'--format=(bv*+ba/b)[filesize<={max_size}][filesize_approx<=?{max_size}]/(bv*+ba/b)',
|
||||||
]
|
]
|
||||||
|
|
||||||
if not check_ssl:
|
if not check_ssl:
|
||||||
|
|||||||
Reference in New Issue
Block a user