Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -67,9 +67,14 @@ class YtDlpTool:
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, config: Optional[Dict[str, Any]] = None, *, script_dir: Optional[Path] = None
|
||||
self,
|
||||
config: Optional[Dict[str,
|
||||
Any]] = None,
|
||||
*,
|
||||
script_dir: Optional[Path] = None
|
||||
) -> None:
|
||||
self._config: Dict[str, Any] = dict(config or {})
|
||||
self._config: Dict[str,
|
||||
Any] = dict(config or {})
|
||||
# `resolve_cookies_path` expects the app root so it can fall back to ./cookies.txt.
|
||||
# This file lives under ./tool/, so default to the parent directory.
|
||||
self._script_dir = script_dir or Path(__file__).resolve().parent.parent
|
||||
@@ -79,7 +84,7 @@ class YtDlpTool:
|
||||
def _init_cookiefile(self) -> Optional[Path]:
|
||||
"""Resolve cookies once at tool init (yt-dlp is the primary consumer)."""
|
||||
try:
|
||||
from config import resolve_cookies_path
|
||||
from SYS.config import resolve_cookies_path
|
||||
|
||||
resolved = resolve_cookies_path(self._config, script_dir=self._script_dir)
|
||||
if resolved is not None and resolved.is_file():
|
||||
@@ -100,24 +105,20 @@ class YtDlpTool:
|
||||
if not isinstance(tool_block, dict):
|
||||
tool_block = {}
|
||||
|
||||
ytdlp_block = cfg.get("ytdlp") if isinstance(cfg.get("ytdlp"), dict) else {}
|
||||
ytdlp_block = cfg.get("ytdlp") if isinstance(cfg.get("ytdlp"),
|
||||
dict) else {}
|
||||
if not isinstance(ytdlp_block, dict):
|
||||
ytdlp_block = {}
|
||||
|
||||
# Accept both nested and flat styles.
|
||||
video_format = (
|
||||
tool_block.get("video_format")
|
||||
or tool_block.get("format")
|
||||
or ytdlp_block.get("video_format")
|
||||
or ytdlp_block.get("video")
|
||||
or ytdlp_block.get("format_video")
|
||||
or cfg.get("ytdlp_video_format")
|
||||
tool_block.get("video_format") or tool_block.get("format")
|
||||
or ytdlp_block.get("video_format") or ytdlp_block.get("video")
|
||||
or ytdlp_block.get("format_video") or cfg.get("ytdlp_video_format")
|
||||
)
|
||||
audio_format = (
|
||||
tool_block.get("audio_format")
|
||||
or ytdlp_block.get("audio_format")
|
||||
or ytdlp_block.get("audio")
|
||||
or ytdlp_block.get("format_audio")
|
||||
tool_block.get("audio_format") or ytdlp_block.get("audio_format")
|
||||
or ytdlp_block.get("audio") or ytdlp_block.get("format_audio")
|
||||
or cfg.get("ytdlp_audio_format")
|
||||
)
|
||||
|
||||
@@ -126,17 +127,22 @@ class YtDlpTool:
|
||||
nested_audio = _get_nested(cfg, "ytdlp", "format", "audio")
|
||||
|
||||
fmt_sort_val = (
|
||||
tool_block.get("format_sort")
|
||||
or ytdlp_block.get("format_sort")
|
||||
or ytdlp_block.get("formatSort")
|
||||
or cfg.get("ytdlp_format_sort")
|
||||
or _get_nested(cfg, "ytdlp", "format", "sort")
|
||||
tool_block.get("format_sort") or ytdlp_block.get("format_sort")
|
||||
or ytdlp_block.get("formatSort") or cfg.get("ytdlp_format_sort")
|
||||
or _get_nested(cfg,
|
||||
"ytdlp",
|
||||
"format",
|
||||
"sort")
|
||||
)
|
||||
fmt_sort = _parse_csv_list(fmt_sort_val)
|
||||
|
||||
defaults = YtDlpDefaults(
|
||||
video_format=str(nested_video or video_format or _fallback_defaults.video_format),
|
||||
audio_format=str(nested_audio or audio_format or _fallback_defaults.audio_format),
|
||||
video_format=str(
|
||||
nested_video or video_format or _fallback_defaults.video_format
|
||||
),
|
||||
audio_format=str(
|
||||
nested_audio or audio_format or _fallback_defaults.audio_format
|
||||
),
|
||||
format_sort=fmt_sort,
|
||||
)
|
||||
|
||||
@@ -155,17 +161,18 @@ class YtDlpTool:
|
||||
"""Translate DownloadOptions into yt-dlp API options."""
|
||||
ensure_directory(opts.output_dir)
|
||||
outtmpl = str((opts.output_dir / "%(title)s.%(ext)s").resolve())
|
||||
base_options: Dict[str, Any] = {
|
||||
"outtmpl": outtmpl,
|
||||
"quiet": True,
|
||||
"no_warnings": True,
|
||||
"noprogress": True,
|
||||
"socket_timeout": 30,
|
||||
"retries": 10,
|
||||
"fragment_retries": 10,
|
||||
"http_chunk_size": 10_485_760,
|
||||
"restrictfilenames": True,
|
||||
}
|
||||
base_options: Dict[str,
|
||||
Any] = {
|
||||
"outtmpl": outtmpl,
|
||||
"quiet": True,
|
||||
"no_warnings": True,
|
||||
"noprogress": True,
|
||||
"socket_timeout": 30,
|
||||
"retries": 10,
|
||||
"fragment_retries": 10,
|
||||
"http_chunk_size": 10_485_760,
|
||||
"restrictfilenames": True,
|
||||
}
|
||||
|
||||
try:
|
||||
repo_root = Path(__file__).resolve().parents[1]
|
||||
@@ -195,7 +202,9 @@ class YtDlpTool:
|
||||
base_options["format"] = fmt
|
||||
|
||||
if opts.mode == "audio":
|
||||
base_options["postprocessors"] = [{"key": "FFmpegExtractAudio"}]
|
||||
base_options["postprocessors"] = [{
|
||||
"key": "FFmpegExtractAudio"
|
||||
}]
|
||||
else:
|
||||
format_sort = self.defaults.format_sort or [
|
||||
"res:4320",
|
||||
@@ -213,7 +222,9 @@ class YtDlpTool:
|
||||
if not isinstance(pps, list):
|
||||
pps = []
|
||||
already_has_metadata = any(
|
||||
isinstance(pp, dict) and str(pp.get("key") or "") == "FFmpegMetadata" for pp in pps
|
||||
isinstance(pp,
|
||||
dict) and str(pp.get("key") or "") == "FFmpegMetadata"
|
||||
for pp in pps
|
||||
)
|
||||
if not already_has_metadata:
|
||||
pps.append(
|
||||
|
||||
Reference in New Issue
Block a user