1
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-03-09 12:50:23 -05:00
This commit is contained in:
Zezombye 2025-03-09 04:30:18 +05:30 committed by GitHub
commit 1acba47914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View file

@ -802,7 +802,7 @@ def test(tmpl, expected, *, info=None, **params):
test('%(id)s', '-abcd', info={'id': '-abcd'}) test('%(id)s', '-abcd', info={'id': '-abcd'})
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', info={'id': 'ab__cd'})
test('%(id)s', ('ab:cd', 'abcd'), info={'id': 'ab:cd'}) test('%(id)s', ('ab:cd', 'ab\u0589cd'), info={'id': 'ab:cd'})
test('%(id.0)s', '-', info={'id': '--'}) test('%(id.0)s', '-', info={'id': '--'})
# Invalid templates # Invalid templates
@ -861,7 +861,7 @@ def expect_same_infodict(out):
test('%(formats)j', (json.dumps(FORMATS), None)) test('%(formats)j', (json.dumps(FORMATS), None))
test('%(formats)#j', ( test('%(formats)#j', (
json.dumps(FORMATS, indent=4), 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).3B', 'á')
test('%(title5)U', 'áéí 𝐀') test('%(title5)U', 'áéí 𝐀')
@ -872,13 +872,13 @@ def expect_same_infodict(out):
test('%(filesize)#D', '1Ki') test('%(filesize)#D', '1Ki')
test('%(height)5.2D', ' 1.08k') test('%(height)5.2D', ' 1.08k')
test('%(title4)#S', 'foo_bar_test') 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': if os.name == 'nt':
test('%(title4)q', ('"foo ""bar"" test"', None)) test('%(title4)q', ('"foo ""bar"" test"', None))
test('%(formats.:.id)#q', ('"id 1" "id 2" "id 3"', None)) test('%(formats.:.id)#q', ('"id 1" "id 2" "id 3"', None))
test('%(formats.0.id)#q', ('"id 1"', None)) test('%(formats.0.id)#q', ('"id 1"', None))
else: 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.:.id)#q', "'id 1' 'id 2' 'id 3'")
test('%(formats.0.id)#q', "'id 1'") test('%(formats.0.id)#q', "'id 1'")
@ -903,7 +903,7 @@ def expect_same_infodict(out):
for f in FORMATS]) for f in FORMATS])
test('%(formats.:.{id,height.:2})j', (out, None)) test('%(formats.:.{id,height.:2})j', (out, None))
test('%(formats.:.{id,height}.id)l', ', '.join(f['id'] for f in FORMATS)) 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 # Alternates
test('%(title,id)s', '1234') test('%(title,id)s', '1234')

View file

@ -639,8 +639,18 @@ def replace_insane(char):
elif not restricted and char == '\n': elif not restricted and char == '\n':
return '\0 ' return '\0 '
elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\': elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\':
# Replace with their full-width unicode counterparts # Replace with lookalike characters
return {'/': '\u29F8', '\\': '\u29f9'}.get(char, chr(ord(char) + 0xfee0)) return {
'"': '\u2033',
'*': '\uA60E',
':': '\u0589',
'<': '\u227A',
'>': '\u227B',
'?': '\uFF1F',
'|': '\u01C0',
'/': '\u29F8',
'\\': '\u29f9',
}[char]
elif char == '?' or ord(char) < 32 or ord(char) == 127: elif char == '?' or ord(char) < 32 or ord(char) == 127:
return '' return ''
elif char == '"': elif char == '"':