diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-04-07 19:57:42 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-04-07 19:57:42 +0200 |
commit | 734f90bb41baa76d9af84a949d61f3ec669d3a3b (patch) | |
tree | 94a58742dbbd575b4c5c7d1d66c3e00a92fe0cc1 /youtube_dl/utils.py | |
parent | 9afb76c5adc16e1f484f75aff30a57712815dc34 (diff) |
Use --encoding when outputting
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 92fee966f..f53db0228 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -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 |