prevent loading keys which sometimes breaks ytptube
This commit is contained in:
parent
1319c3e1ab
commit
44440aa546
2 changed files with 15 additions and 13 deletions
|
|
@ -22,6 +22,8 @@ IGNORED_KEYS: tuple[str] = (
|
|||
"outtmpl",
|
||||
"progress_hooks",
|
||||
"postprocessor_hooks",
|
||||
"format",
|
||||
"download_archive",
|
||||
)
|
||||
YTDLP_INFO_CLS: yt_dlp.YoutubeDL = None
|
||||
OS_ALT_SEP: list[str] = list(sep for sep in [os.sep, os.path.altsep] if sep is not None and sep != "/")
|
||||
|
|
@ -77,6 +79,7 @@ def get_opts(preset: str, ytdl_opts: dict) -> dict:
|
|||
LOG.debug(f"Using preset '{preset}', altered options: {opts}")
|
||||
return opts
|
||||
|
||||
|
||||
def getVideoInfo(url: str, ytdlp_opts: dict = None, no_archive: bool = True) -> Any | dict[str, Any] | None:
|
||||
"""
|
||||
Extracts video information from the given URL.
|
||||
|
|
@ -187,17 +190,9 @@ def mergeConfig(config: dict, new_config: dict) -> dict:
|
|||
Returns:
|
||||
dict: Merged config
|
||||
"""
|
||||
|
||||
ignored_keys: tuple = (
|
||||
"cookiefile",
|
||||
"download_archive" "paths",
|
||||
"outtmpl",
|
||||
"progress_hooks",
|
||||
"postprocessor_hooks",
|
||||
)
|
||||
|
||||
for key in ignored_keys:
|
||||
for key in IGNORED_KEYS:
|
||||
if key in new_config:
|
||||
LOG.error(f"Key '{key}' is not allowed to be manually set.")
|
||||
del new_config[key]
|
||||
|
||||
conf = mergeDict(new_config, config)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import coloredlogs
|
|||
from dotenv import load_dotenv
|
||||
from yt_dlp.version import __version__ as YTDLP_VERSION
|
||||
|
||||
from .Utils import load_file
|
||||
from .Utils import load_file, mergeDict, IGNORED_KEYS
|
||||
from .version import APP_VERSION
|
||||
|
||||
|
||||
|
|
@ -218,15 +218,22 @@ class Config:
|
|||
LOG.error(f"Error starting debugpy server at '0.0.0.0:{self.debugpy_port}'. {e}")
|
||||
|
||||
optsFile: str = os.path.join(self.config_path, "ytdlp.json")
|
||||
if os.path.exists(optsFile) and os.path.getsize(optsFile) > 4:
|
||||
if os.path.exists(optsFile) and os.path.getsize(optsFile) > 5:
|
||||
LOG.info(f"Loading yt-dlp custom options from '{optsFile}'.")
|
||||
|
||||
(opts, status, error) = load_file(optsFile, dict)
|
||||
if not status:
|
||||
LOG.error(f"Could not load yt-dlp custom options from '{optsFile}'. {error}")
|
||||
sys.exit(1)
|
||||
if isinstance(opts, dict):
|
||||
for key in IGNORED_KEYS:
|
||||
if key in opts:
|
||||
LOG.error(f"Key '{key}' is not allowed to be loaded via 'ytdlp.json' file.")
|
||||
del opts[key]
|
||||
|
||||
self.ytdl_options.update(opts)
|
||||
self.ytdl_options = mergeDict(self.ytdl_options, opts)
|
||||
else:
|
||||
LOG.error(f"Invalid yt-dlp custom options file '{optsFile}'.")
|
||||
else:
|
||||
LOG.info(f"No yt-dlp custom options found at '{optsFile}'.")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue