Skip to content

Commit

Permalink
Fixed a locale issue in the youtube plugin
Browse files Browse the repository at this point in the history
locale.format() can throw a UnicodeDecodeError in some cases. The use of str.decode() prevents its occurrence.
See http://stackoverflow.com/questions/4082645/using-python-2-xs-locale-module-to-format-numbers-and-currency
  • Loading branch information
stoneLeaf committed Apr 11, 2012
1 parent b3e97f2 commit ff1832c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def get_video_description(vid_id):
out += ' - rated \x02%.2f/5.0\x02 (%d)' % (j['rating'],
j['ratingCount'])

# The use of str.decode() prevents UnicodeDecodeError with some locales
# See http://stackoverflow.com/questions/4082645/
if 'viewCount' in j:
out += ' - \x02%s\x02 views' % locale.format('%d',
j['viewCount'], 1)
j['viewCount'], 1).decode(locale.getlocale()[1])

upload_time = time.strptime(j['uploaded'], "%Y-%m-%dT%H:%M:%S.000Z")
out += ' - \x02%s\x02 on \x02%s\x02' % (j['uploader'],
Expand Down

0 comments on commit ff1832c

Please sign in to comment.