aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-04-07 23:23:48 +0200
committerPhilipp Hagemeister <phihag@phihag.de>2014-04-07 23:23:48 +0200
commit89938c719e2ef5afea7a292b72c6e9f95c1974e2 (patch)
tree4b8f38a1e19bbe5f1973c943c1f7781156e5d43f /youtube_dl/utils.py
parenta5863bdf331e6a54068912ea216612e812d7100d (diff)
Fix Windows output for non-BMP unicode characters
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index b57fd7a33..9c9320934 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -923,6 +923,9 @@ def _windows_write_string(s, out):
2: -12,
}
+ def ucs2_len(s):
+ return sum((2 if ord(c) > 0xffff else 1) for c in s)
+
fileno = out.fileno()
if fileno not in WIN_OUTPUT_IDS:
return False
@@ -956,10 +959,10 @@ def _windows_write_string(s, out):
if not_a_console(h):
return False
- remaining = len(s)
+ remaining = ucs2_len(s)
while remaining > 0:
ret = WriteConsoleW(
- h, s, min(len(s), 1024), ctypes.byref(written), None)
+ h, s, min(remaining, 1024), ctypes.byref(written), None)
if ret == 0:
raise OSError('Failed to write string')
remaining -= written.value