h
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# pyright: reportUnusedFunction=false
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
@@ -960,26 +961,20 @@ class YtDlpTool:
|
||||
# Special handling for format keywords explicitly passed in via options
|
||||
if opts.ytdl_format == "audio":
|
||||
try:
|
||||
opts = opts._replace(mode="audio", ytdl_format=None)
|
||||
except Exception:
|
||||
try:
|
||||
import dataclasses as _dc
|
||||
import dataclasses as _dc
|
||||
|
||||
opts = _dc.replace(opts, mode="audio", ytdl_format=None)
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to audio via dataclasses.replace")
|
||||
opts = _dc.replace(opts, mode="audio", ytdl_format=None)
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to audio via dataclasses.replace")
|
||||
elif opts.ytdl_format == "video":
|
||||
try:
|
||||
opts = opts._replace(mode="video", ytdl_format=None)
|
||||
except Exception:
|
||||
try:
|
||||
import dataclasses as _dc
|
||||
import dataclasses as _dc
|
||||
|
||||
opts = _dc.replace(opts, mode="video", ytdl_format=None)
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to video via dataclasses.replace")
|
||||
opts = _dc.replace(opts, mode="video", ytdl_format=None)
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to video via dataclasses.replace")
|
||||
|
||||
if opts.no_playlist:
|
||||
base_options["noplaylist"] = True
|
||||
@@ -992,15 +987,12 @@ class YtDlpTool:
|
||||
if configured_format.lower() == "audio":
|
||||
# Default to audio-only downloads
|
||||
try:
|
||||
opts = opts._replace(mode="audio")
|
||||
except Exception:
|
||||
try:
|
||||
import dataclasses as _dc
|
||||
import dataclasses as _dc
|
||||
|
||||
opts = _dc.replace(opts, mode="audio")
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to audio via dataclasses.replace (configured default)")
|
||||
opts = _dc.replace(opts, mode="audio")
|
||||
except Exception:
|
||||
from SYS.logger import logger
|
||||
logger.exception("Failed to set opts mode to audio via dataclasses.replace (configured default)")
|
||||
ytdl_format = None
|
||||
else:
|
||||
# Leave ytdl_format None so that default_format(opts.mode)
|
||||
@@ -1854,7 +1846,7 @@ def download_media(opts: DownloadOptions, *, config: Optional[Dict[str, Any]] =
|
||||
info = None
|
||||
else:
|
||||
with yt_dlp.YoutubeDL(ytdl_options) as ydl: # type: ignore[arg-type]
|
||||
info = ydl.extract_info(opts.url, download=True)
|
||||
info = cast(Dict[str, Any], ydl.extract_info(opts.url, download=True))
|
||||
except Exception as exc:
|
||||
retry_attempted = False
|
||||
if _is_http_403(exc) and not ytdl_options.get("download_sections"):
|
||||
@@ -1879,7 +1871,7 @@ def download_media(opts: DownloadOptions, *, config: Optional[Dict[str, Any]] =
|
||||
fallback_options["extractor_args"] = extractor_args
|
||||
|
||||
with yt_dlp.YoutubeDL(fallback_options) as ydl: # type: ignore[arg-type]
|
||||
info = ydl.extract_info(opts.url, download=True)
|
||||
info = cast(Dict[str, Any], ydl.extract_info(opts.url, download=True))
|
||||
except Exception as exc2:
|
||||
log(f"yt-dlp failed: {exc2}", file=sys.stderr)
|
||||
if debug_logger is not None:
|
||||
|
||||
Reference in New Issue
Block a user