]> jfr.im git - yt-dlp.git/commitdiff
[outtmpl] Smarter replacing of unsupported characters
authorpukkandan <redacted>
Thu, 4 Aug 2022 14:49:32 +0000 (20:19 +0530)
committerpukkandan <redacted>
Thu, 4 Aug 2022 14:51:32 +0000 (20:21 +0530)
Closes #1330

yt_dlp/utils.py

index c56f31013f9ac535956279d0b78f9ec9b50eaab3..3a33cad2e77533125357ec3ba190301967eedb7c 100644 (file)
@@ -40,6 +40,7 @@
 import time
 import traceback
 import types
+import unicodedata
 import urllib.error
 import urllib.parse
 import urllib.request
@@ -647,6 +648,9 @@ def replace_insane(char):
             return ACCENT_CHARS[char]
         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))
         elif char == '?' or ord(char) < 32 or ord(char) == 127:
             return ''
         elif char == '"':
@@ -659,6 +663,8 @@ def replace_insane(char):
             return '\0_'
         return char
 
+    if restricted and is_id is NO_DEFAULT:
+        s = unicodedata.normalize('NFKC', s)
     s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)  # Handle timestamps
     result = ''.join(map(replace_insane, s))
     if is_id is NO_DEFAULT: