From 3724350fb025604ebafee64cc57956cedb6ba2da Mon Sep 17 00:00:00 2001 From: Zezombye Date: Fri, 6 Dec 2024 12:54:27 +0100 Subject: [PATCH 1/3] improve windows lookalike characters --- yt_dlp/utils/_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 699bf1e7f6..dc615991e4 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -637,8 +637,18 @@ def sanitize_filename(s, restricted=False, is_id=NO_DEFAULT): elif not restricted and char == '\n': return '\0 ' elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\': - # Replace with their full-width unicode counterparts - return {'/': '\u29F8', '\\': '\u29f9'}.get(char, chr(ord(char) + 0xfee0)) + # Replace with lookalike characters + return { + '"': '\u2033', + '*': '\uA60E', + ':': '\u0589', + '<': '\u227A', + '>': '\u227B', + '?': '\uFF1F', + '|': '\u01C0', + '/': '\u29F8', + '\\': '\u29f9', + }[char] elif char == '?' or ord(char) < 32 or ord(char) == 127: return '' elif char == '"': From 7ab9621f94183e1f15d9199121d01b94977a0da5 Mon Sep 17 00:00:00 2001 From: Zezombye Date: Fri, 6 Dec 2024 13:16:20 +0100 Subject: [PATCH 2/3] fix test --- test/test_YoutubeDL.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 966d27a498..a4f3829513 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -768,7 +768,7 @@ class TestYoutubeDL(unittest.TestCase): test('%(id)s', '-abcd', info={'id': '-abcd'}) test('%(id)s', '.abcd', info={'id': '.abcd'}) test('%(id)s', 'ab__cd', info={'id': 'ab__cd'}) - test('%(id)s', ('ab:cd', 'ab:cd'), info={'id': 'ab:cd'}) + test('%(id)s', ('ab:cd', 'ab\u0589cd'), info={'id': 'ab:cd'}) test('%(id.0)s', '-', info={'id': '--'}) # Invalid templates From 3492c0123f9417194c2045cb0a09a3ae97630018 Mon Sep 17 00:00:00 2001 From: Zezombye Date: Fri, 6 Dec 2024 13:27:52 +0100 Subject: [PATCH 3/3] fix other tests --- test/test_YoutubeDL.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index a4f3829513..35fdc01dad 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -827,7 +827,7 @@ class TestYoutubeDL(unittest.TestCase): test('%(formats)j', (json.dumps(FORMATS), None)) test('%(formats)#j', ( json.dumps(FORMATS, indent=4), - json.dumps(FORMATS, indent=4).replace(':', ':').replace('"', '"').replace('\n', ' '), + json.dumps(FORMATS, indent=4).replace(':', '\u0589').replace('"', '\u2033').replace('\n', ' '), )) test('%(title5).3B', 'á') test('%(title5)U', 'áéí 𝐀') @@ -838,13 +838,13 @@ class TestYoutubeDL(unittest.TestCase): test('%(filesize)#D', '1Ki') test('%(height)5.2D', ' 1.08k') test('%(title4)#S', 'foo_bar_test') - test('%(title4).10S', ('foo "bar" ', 'foo "bar"' + ('#' if os.name == 'nt' else ' '))) + test('%(title4).10S', ('foo \u2033bar\u2033 ', 'foo \u2033bar\u2033' + ('#' if os.name == 'nt' else ' '))) if os.name == 'nt': test('%(title4)q', ('"foo ""bar"" test"', None)) test('%(formats.:.id)#q', ('"id 1" "id 2" "id 3"', None)) test('%(formats.0.id)#q', ('"id 1"', None)) else: - test('%(title4)q', ('\'foo "bar" test\'', '\'foo "bar" test\'')) + test('%(title4)q', ('\'foo "bar" test\'', '\'foo \u2033bar\u2033 test\'')) test('%(formats.:.id)#q', "'id 1' 'id 2' 'id 3'") test('%(formats.0.id)#q', "'id 1'") @@ -869,7 +869,7 @@ class TestYoutubeDL(unittest.TestCase): for f in FORMATS]) test('%(formats.:.{id,height.:2})j', (out, None)) test('%(formats.:.{id,height}.id)l', ', '.join(f['id'] for f in FORMATS)) - test('%(.{id,title})j', ('{"id": "1234"}', '{"id": "1234"}')) + test('%(.{id,title})j', ('{"id": "1234"}', '{\u2033id\u2033\u0589 \u20331234\u2033}')) # Alternates test('%(title,id)s', '1234')