aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 7d6041929..9784abb24 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -154,6 +154,7 @@ std_headers = {
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-us,en;q=0.5',
}
+
def preferredencoding():
"""Get preferred encoding.
@@ -187,6 +188,11 @@ else:
with open(fn, 'w', encoding='utf-8') as f:
json.dump(obj, f)
+# Some library functions return bytestring on 2.X and unicode on 3.X
+def enforce_unicode(s, encoding='utf-8'):
+ if type(s) != type(u''):
+ return s.decode(encoding)
+ return s
def htmlentity_transform(matchobj):
"""Transforms an HTML entity to a character.