From 2b666517a5ac05ad1f70432fe6c900a6d7c3f227 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Tue, 25 Mar 2025 20:42:09 +0300 Subject: [PATCH] add sanitize_info for get url info --- .vscode/settings.json | 2 ++ app/library/HttpAPI.py | 3 ++- app/library/Utils.py | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dcd61db2..eee8b4c8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,8 @@ "ahash", "aiocron", "arrowless", + "attl", + "autonumber", "changeslog", "copyts", "daterange", diff --git a/app/library/HttpAPI.py b/app/library/HttpAPI.py index 9aab0a9c..3a624dd9 100644 --- a/app/library/HttpAPI.py +++ b/app/library/HttpAPI.py @@ -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.", diff --git a/app/library/Utils.py b/app/library/Utils.py index bfd7d55d..bd0dcd5b 100644 --- a/app/library/Utils.py +++ b/app/library/Utils.py @@ -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: