A feature-rich command-line audio/video downloader
[outtmpl] Add alternate form `h` for HTML escaping
pukkandan47cdc68e034c
diff --git a/README.md b/README.mdindex 48862b6329..43137f23b4 100644--- a/README.md+++ b/README.md@@ -1206,7 +1206,7 @@ The field names themselves (the part inside the parenthesis) can also have some1. **Default**: A literal default value can be specified for when the field is empty using a `|` separator. This overrides `--output-na-template`. Eg: `%(uploader|Unknown)s`-1. **More Conversions**: In addition to the normal format types `diouxXeEfFgGcrs`, `B`, `j`, `l`, `q`, `D`, `S` can be used for converting to **B**ytes, **j**son (flag `#` for pretty-printing), a comma separated **l**ist (flag `#` for `\n` newline-separated), a string **q**uoted for the terminal (flag `#` to split a list into different arguments), to add **D**ecimal suffixes (Eg: 10M) (flag `#` to use 1024 as factor), and to **S**anitize as filename (flag `#` for restricted), respectively+1. **More Conversions**: In addition to the normal format types `diouxXeEfFgGcrs`, yt-dlp additionally supports converting to `B` = **B**ytes, `j` = **j**son (flag `#` for pretty-printing), `l` = a comma separated **l**ist (flag `#` for `\n` newline-separated), `q` = a string **q**uoted for the terminal (flag `#` to split a list into different arguments), `D` = add **D**ecimal suffixes (Eg: 10M) (flag `#` to use 1024 as factor), and `S` = **S**anitize as filename (flag `#` for restricted)1. **Unicode normalization**: The format type `U` can be used for NFC [unicode normalization](https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize). The alternate form flag (`#`) changes the normalization to NFD and the conversion flag `+` can be used for NFKC/NFKD compatibility equivalence normalization. Eg: `%(title)+.100U` is NFKCdiff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex 38d146bfc7..6455b0df20 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -90,6 +90,7 @@ from .utils import (encode_compat_str,encodeFilename,error_to_compat_str,+ escapeHTML,expand_path,filter_dict,float_or_none,@@ -1046,7 +1047,7 @@ class YoutubeDL:def validate_outtmpl(cls, outtmpl):''' @return None or Exception object '''outtmpl = re.sub(- STR_FORMAT_RE_TMPL.format('[^)]*', '[ljqBUDS]'),+ STR_FORMAT_RE_TMPL.format('[^)]*', '[ljhqBUDS]'),lambda mobj: f'{mobj.group(0)[:-1]}s',cls._outtmpl_expandpath(outtmpl))try:@@ -1089,7 +1090,7 @@ class YoutubeDL:}TMPL_DICT = {}- EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljqBUDS]'))+ EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljhqBUDS]'))MATH_FUNCTIONS = {'+': float.__add__,'-': float.__sub__,@@ -1198,6 +1199,8 @@ class YoutubeDL:value, fmt = delim.join(map(str, variadic(value, allowed_types=(str, bytes)))), str_fmtelif fmt[-1] == 'j': # jsonvalue, fmt = json.dumps(value, default=_dumpjson_default, indent=4 if '#' in flags else None), str_fmt+ elif fmt[-1] == 'h': # html+ value, fmt = escapeHTML(value), str_fmtelif fmt[-1] == 'q': # quotedvalue = map(str, variadic(value) if '#' in flags else [value])value, fmt = ' '.join(map(compat_shlex_quote, value)), str_fmt