Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UnicodeEncodeError on latin-1 #844

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mps_youtube/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def save():
hf.write('#EXTM3U\n\n')
if 'history' in g.userhist:
for song in g.userhist['history'].songs:
hf.write('#EXTINF:%d,%s\n' % (song.length, song.title))
hf.write('#EXTINF:%d,%s\n' % (song.length, song.title.encode('utf-8')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me.

Look at the behavior of this code, for instance: "encoded: %s" % ("test".encode("utf8"),). This results in the string "encoded: b'test'". So it produces a str (not bytes) containing b' and '.

I'm not sure the best solution here. If we want to save the file as UTF-8, then we can pass an encoding= argument to open.

hf.write('https://www.youtube.com/watch?v=%s\n' % song.ytid)

dbg(c.r + "History saved\n---" + c.w)
Expand Down