A feature-rich command-line audio/video downloader
[outtmpl] Change filename sanitization type to `S` `F` is already used for float! Bug in e0fd95737d1a3c4a2bfb470c5408a396c8545ca5
pukkandan37893bb0c9af
diff --git a/README.md b/README.mdindex 381e1b263e..6a7977d25e 100644--- a/README.md+++ b/README.md@@ -1087,7 +1087,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`, 'F' 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), and to sanitize as **F**ilename (flag `#` for restricted), respectively+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), and to **S**anitize as filename (flag `#` for restricted), respectively1. **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/test/test_YoutubeDL.py b/test/test_YoutubeDL.pyindex ee0e5eca58..61923513ee 100644--- a/test/test_YoutubeDL.py+++ b/test/test_YoutubeDL.py@@ -780,8 +780,8 @@ class TestYoutubeDL(unittest.TestCase):test('%(title5)+#U', 'a\u0301e\u0301i\u0301 A')test('%(height)D', '1K')test('%(height)5.2D', ' 1.08K')- test('%(title4)#F', 'foo_bar_test')- test('%(title4).10F', ('foo \'bar\' ', 'foo \'bar\'' + ('#' if compat_os_name == 'nt' else ' ')))+ test('%(title4)#S', 'foo_bar_test')+ test('%(title4).10S', ('foo \'bar\' ', 'foo \'bar\'' + ('#' if compat_os_name == 'nt' else ' ')))if compat_os_name == 'nt':test('%(title4)q', ('"foo \\"bar\\" test"', "'foo _'bar_' test'"))test('%(formats.:.id)#q', ('"id 1" "id 2" "id 3"', "'id 1' 'id 2' 'id 3'"))diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex 3bbde9b00f..6fcd52b995 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -1006,7 +1006,7 @@ class YoutubeDL(object):def validate_outtmpl(cls, outtmpl):''' @return None or Exception object '''outtmpl = re.sub(- STR_FORMAT_RE_TMPL.format('[^)]*', '[ljqBUDF]'),+ STR_FORMAT_RE_TMPL.format('[^)]*', '[ljqBUDS]'),lambda mobj: f'{mobj.group(0)[:-1]}s',cls._outtmpl_expandpath(outtmpl))try:@@ -1048,7 +1048,7 @@ class YoutubeDL(object):}TMPL_DICT = {}- EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljqBUDF]'))+ EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljqBUDS]'))MATH_FUNCTIONS = {'+': float.__add__,'-': float.__sub__,@@ -1167,7 +1167,7 @@ class YoutubeDL(object):value), str_fmtelif fmt[-1] == 'D': # decimal suffixvalue, fmt = format_decimal_suffix(value, f'%{fmt[:-1]}f%s' if fmt[:-1] else '%d%s'), 's'- elif fmt[-1] == 'F': # filename sanitization+ elif fmt[-1] == 'S': # filename sanitizationvalue, fmt = filename_sanitizer(initial_field, value, restricted='#' in flags), str_fmtelif fmt[-1] == 'c':if value: