aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-30 18:22:36 +0100
committerFilippo Valsorda <filippo.valsorda@gmail.com>2012-12-30 19:50:33 +0100
commitf427df17abc9508f88af9d904ac0520d610c0e9c (patch)
tree93270e1364b29ed7bba78d341bf2f7727e0cfc56 /youtube_dl/utils.py
parent4e38899e9754c0bd0655732a02388559046b004e (diff)
some fixes, pulled the codename from the code
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.