0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-12-22 06:00:00 +00:00

Improve preferred encoding detection method

This commit is contained in:
Ricardo Garcia 2009-09-20 00:08:50 +02:00
parent 0833f1eb83
commit f94b636c3e

View file

@ -33,15 +33,15 @@ def preferredencoding():
Returns the best encoding scheme for the system, based on Returns the best encoding scheme for the system, based on
locale.getpreferredencoding() and some further tweaks. locale.getpreferredencoding() and some further tweaks.
""" """
try: def yield_preferredencoding():
pref = locale.getpreferredencoding() try:
# Mac OSX systems have this problem sometimes pref = locale.getpreferredencoding()
if pref == '': u'TEST'.encode(pref)
return 'UTF-8' except:
return pref pref = 'UTF-8'
except: while True:
sys.stderr.write('WARNING: problem obtaining preferred encoding. Falling back to UTF-8.\n') yield pref
return 'UTF-8' return yield_preferredencoding().next()
class DownloadError(Exception): class DownloadError(Exception):
"""Download Error exception. """Download Error exception.