mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-06-30 11:02:54 -05:00
Use --encoding when outputting
This commit is contained in:
@ -910,22 +910,25 @@ def platform_name():
|
||||
return res
|
||||
|
||||
|
||||
def write_string(s, out=None):
|
||||
def write_string(s, out=None, encoding=None):
|
||||
if out is None:
|
||||
out = sys.stderr
|
||||
assert type(s) == compat_str
|
||||
|
||||
if ('b' in getattr(out, 'mode', '') or
|
||||
sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr
|
||||
s = s.encode(preferredencoding(), 'ignore')
|
||||
s = s.encode(encoding or preferredencoding(), 'ignore')
|
||||
try:
|
||||
out.write(s)
|
||||
except UnicodeEncodeError:
|
||||
# In Windows shells, this can fail even when the codec is just charmap!?
|
||||
# See https://wiki.python.org/moin/PrintFails#Issue
|
||||
if sys.platform == 'win32' and hasattr(out, 'encoding'):
|
||||
s = s.encode(out.encoding, 'ignore').decode(out.encoding)
|
||||
out.write(s)
|
||||
if sys.platform == 'win32':
|
||||
if not encoding and hasattr(out, 'encoding'):
|
||||
encoding = out.encoding
|
||||
if encoding:
|
||||
b = s.encode(encoding, 'ignore').decode(encoding)
|
||||
out.write(b)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
Reference in New Issue
Block a user