From 37893bb0c9afdeead29e3707d2dfb67596f03897 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 23 Dec 2021 09:03:46 +0530 Subject: [PATCH] [outtmpl] Change filename sanitization type to `S` `F` is already used for float! Bug in e0fd95737d1a3c4a2bfb470c5408a396c8545ca5 --- README.md | 2 +- test/test_YoutubeDL.py | 4 ++-- yt_dlp/YoutubeDL.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 381e1b263..6a7977d25 100644 --- a/README.md +++ b/README.md @@ -1087,7 +1087,7 @@ # OUTPUT TEMPLATE 1. **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), respectively 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 NFKC diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index ee0e5eca5..61923513e 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -780,8 +780,8 @@ def expect_same_infodict(out): 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.py index 3bbde9b00..6fcd52b99 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -1006,7 +1006,7 @@ def escape_outtmpl(outtmpl): 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 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=False): } 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 @@ def create_key(outer_mobj): value), str_fmt elif fmt[-1] == 'D': # decimal suffix value, 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 sanitization value, fmt = filename_sanitizer(initial_field, value, restricted='#' in flags), str_fmt elif fmt[-1] == 'c': if value: