From 3ae8ccc4f8ae478559f3aefc8dc44e289cbef79a Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 5 Apr 2014 16:20:03 +0300 Subject: [PATCH] Fix subprocess encoding --- youtube_dl_gui/Utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/youtube_dl_gui/Utils.py b/youtube_dl_gui/Utils.py index 753a43f..8b5eedc 100644 --- a/youtube_dl_gui/Utils.py +++ b/youtube_dl_gui/Utils.py @@ -2,6 +2,7 @@ import os import sys +import locale def remove_empty_items(array): return [x for x in array if x != ''] @@ -11,10 +12,21 @@ def remove_spaces(string): def string_to_array(string, char=' '): return string.split(char) + +def preferredencoding(): + try: + pref = locale.getpreferredencoding() + u'TEST'.encode(pref) + except: + pref = 'UTF-8' + return pref def get_encoding(): + if sys.version_info >= (3, 0): + return None if sys.platform == 'win32': - return sys.getfilesystemencoding() + # Refer to http://stackoverflow.com/a/9951851/35070 + return preferredencoding() return None def encode_list(data_list, encoding):