From 78fde6e3398ff11e5d383a66b28664badeab5180 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 24 Apr 2023 17:21:20 +0530 Subject: [PATCH] [outtmpl] Allow `\n` in replacements and default. Fixes: https://github.com/yt-dlp/yt-dlp/issues/6808#issuecomment-1510055357 Fixes: https://github.com/yt-dlp/yt-dlp/issues/6808#issuecomment-1510363645 --- test/test_YoutubeDL.py | 1 + yt_dlp/YoutubeDL.py | 2 +- yt_dlp/options.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 8da1e5e4b..49ae9e2b1 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -822,6 +822,7 @@ def expect_same_infodict(out): test('%(title&foo|baz)s.bar', 'baz.bar') test('%(x,id&foo|baz)s.bar', 'foo.bar') test('%(x,title&foo|baz)s.bar', 'baz.bar') + test('%(title&\n|)s', '\n') # Laziness def gen(): diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 31f7645dc..61c149e47 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -1156,7 +1156,7 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=False): } MATH_FIELD_RE = rf'(?:{FIELD_RE}|-?{NUMBER_RE})' MATH_OPERATORS_RE = r'(?:%s)' % '|'.join(map(re.escape, MATH_FUNCTIONS.keys())) - INTERNAL_FORMAT_RE = re.compile(rf'''(?x) + INTERNAL_FORMAT_RE = re.compile(rf'''(?xs) (?P-)? (?P{FIELD_RE}) (?P(?:{MATH_OPERATORS_RE}{MATH_FIELD_RE})*) diff --git a/yt_dlp/options.py b/yt_dlp/options.py index 84aeda7f1..d334a9caa 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -243,7 +243,7 @@ def _dict_from_options_callback( if multiple_keys: allowed_keys = fr'({allowed_keys})(,({allowed_keys}))*' mobj = re.match( - fr'(?i)(?P{allowed_keys}){delimiter}(?P.*)$', + fr'(?is)(?P{allowed_keys}){delimiter}(?P.*)$', value[0] if multiple_args else value) if mobj is not None: keys, val = mobj.group('keys').split(','), mobj.group('val')