add sanitize_info for get url info

This commit is contained in:
arabcoders 2025-03-25 20:42:09 +03:00
parent b0ff4f41d0
commit 2b666517a5
3 changed files with 15 additions and 3 deletions

View file

@ -16,6 +16,8 @@
"ahash",
"aiocron",
"arrowless",
"attl",
"autonumber",
"changeslog",
"copyts",
"daterange",

View file

@ -509,6 +509,7 @@ class HttpAPI(Common):
debug=False,
no_archive=True,
follow_redirect=True,
sanitize_info=True,
)
if "formats" in data:
@ -531,8 +532,8 @@ class HttpAPI(Common):
return web.Response(body=json.dumps(data, indent=4), status=web.HTTPOk.status_code)
except Exception as e:
LOG.error(f"Error encountered while grabbing video info '{url}'. '{e}'.")
LOG.exception(e)
LOG.error(f"Error encountered while getting video info for '{url}'. '{e!s}'.")
return web.json_response(
data={
"error": "failed to get video info.",

View file

@ -68,6 +68,7 @@ def extract_info(
debug: bool = False,
no_archive: bool = False,
follow_redirect: bool = False,
sanitize_info: bool = False,
) -> dict:
"""
Extracts video information from the given URL.
@ -78,6 +79,7 @@ def extract_info(
debug (bool): Enable debug logging.
no_archive (bool): Disable download archive.
follow_redirect (bool): Follow URL redirects.
sanitize_info (bool): Sanitize the extracted information
Returns:
dict: Video information.
@ -127,9 +129,16 @@ def extract_info(
data = yt_dlp.YoutubeDL(params=params).extract_info(url, download=False)
if data and follow_redirect and "_type" in data and "url" == data["_type"]:
return extract_info(config, data["url"], debug=debug, no_archive=no_archive, follow_redirect=follow_redirect)
return extract_info(
config,
data["url"],
debug=debug,
no_archive=no_archive,
follow_redirect=follow_redirect,
sanitize_info=sanitize_info,
)
return data
return yt_dlp.YoutubeDL.sanitize_info(data) if sanitize_info else data
def merge_dict(source: dict, destination: dict) -> dict: