add sanitize_info for get url info
This commit is contained in:
parent
b0ff4f41d0
commit
2b666517a5
3 changed files with 15 additions and 3 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -16,6 +16,8 @@
|
||||||
"ahash",
|
"ahash",
|
||||||
"aiocron",
|
"aiocron",
|
||||||
"arrowless",
|
"arrowless",
|
||||||
|
"attl",
|
||||||
|
"autonumber",
|
||||||
"changeslog",
|
"changeslog",
|
||||||
"copyts",
|
"copyts",
|
||||||
"daterange",
|
"daterange",
|
||||||
|
|
|
||||||
|
|
@ -509,6 +509,7 @@ class HttpAPI(Common):
|
||||||
debug=False,
|
debug=False,
|
||||||
no_archive=True,
|
no_archive=True,
|
||||||
follow_redirect=True,
|
follow_redirect=True,
|
||||||
|
sanitize_info=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if "formats" in data:
|
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)
|
return web.Response(body=json.dumps(data, indent=4), status=web.HTTPOk.status_code)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(f"Error encountered while grabbing video info '{url}'. '{e}'.")
|
|
||||||
LOG.exception(e)
|
LOG.exception(e)
|
||||||
|
LOG.error(f"Error encountered while getting video info for '{url}'. '{e!s}'.")
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
data={
|
data={
|
||||||
"error": "failed to get video info.",
|
"error": "failed to get video info.",
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ def extract_info(
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
no_archive: bool = False,
|
no_archive: bool = False,
|
||||||
follow_redirect: bool = False,
|
follow_redirect: bool = False,
|
||||||
|
sanitize_info: bool = False,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Extracts video information from the given URL.
|
Extracts video information from the given URL.
|
||||||
|
|
@ -78,6 +79,7 @@ def extract_info(
|
||||||
debug (bool): Enable debug logging.
|
debug (bool): Enable debug logging.
|
||||||
no_archive (bool): Disable download archive.
|
no_archive (bool): Disable download archive.
|
||||||
follow_redirect (bool): Follow URL redirects.
|
follow_redirect (bool): Follow URL redirects.
|
||||||
|
sanitize_info (bool): Sanitize the extracted information
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Video information.
|
dict: Video information.
|
||||||
|
|
@ -127,9 +129,16 @@ def extract_info(
|
||||||
data = yt_dlp.YoutubeDL(params=params).extract_info(url, download=False)
|
data = yt_dlp.YoutubeDL(params=params).extract_info(url, download=False)
|
||||||
|
|
||||||
if data and follow_redirect and "_type" in data and "url" == data["_type"]:
|
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:
|
def merge_dict(source: dict, destination: dict) -> dict:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue