Open hexchain opened 7 years ago
I'm not sure if broken Python 2 support is a real bug nowadays... If you can use Py3, then use Py3. (Even Mutagen has been ported already.)
That said:
(FWIW, I'm testing the Python 2 version against python-mpd 0.3.0.)
Sorry for the confusion. Title and description updated. According to the exception, the problem is not about metadata, but song_url
.
Yes, I've tested that as well.
Actually, could you try inserting the following above the failing line in update_metadata
?
logger.debug("music_dir is %s" % repr(params["music_dir"]))
logger.debug("song_url is %s" % repr(song_url))
I've tried adding two print
statement:
print(repr(song_url), type(song_url))
print(repr(params['music_dir']), type(params['music_dir']))
and the result is:
'\xe9\xa2\xa8\xe3\x81\xaf\xe4\xba\x88\xe5\x91\x8a\xe3\x81\xaa\xe3\x81\x8f\xe5\x90\xb9\xe3\x81\x8f.mp3' <type 'str'>
u'file:///home/hexchain/Music' <type 'unicode'>
Can't imagine where it gets the latter one from. Could you test something else, though – your locale settings? What does env | egrep "^LANG|^LC"
find, and what does locale charmap
print out?
I've noticed Python 2 handles UTF-8 paths fine as long as the system locale is also an UTF-8 one.
$ env | egrep '^LANG|^LC'
LANG=en_US.utf8
$ locale charmap
UTF-8
$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
¯_(ツ)_/¯
This seems to be one of those situations where Python chooses string types through a dice roll, and as a result the Python 2 code needs to be the exact opposite of Python 3 code... Or something.
Will take a look again later. In the mean time you're encouraged again to mgirate to Python 3.
Well, this program doesn't seem to be fully unicode-aware.
Since in Python2 the sys.getdefaultencoding()
is always ascii
on Linux, trying to concatenate a unicode and a string will fail because Python will try to decode the string using ascii.
The question is how params['music_dir']
becomes an unicode() though... In all my tests – from env, from args, from config file – I only get a str().
That's because config.get('Library', 'music_dir')
-> unicode but find_music_dir()
-> str, around line 1219.
Due to different handling of string and bytes, mpDris running with Python 2 does not support non-ascii chars in
song_url
:With Python 3: