ID3_V1 supports only latin1
encoding. In order to write V1 tags with Russian characters, cp1251
encoding is used. I would like to copy data from V2 tags (unicode) to V1 tags. I get V2 tags with the following code with eyeD3 usage:
tag.link(mp3path, v=eyeD3.ID3_V2)
mp3album_v2 = tag.getAlbum()
...
tag.link(mp3path, v=eyeD3.ID3_V1)
tag.setTextEncoding(eyeD3.LATIN1_ENCODING)
tag.setAlbum(mp3album_v2.encode('cp1251')) # ???
tag.update()
The following is returned:
>>> print mp3album_v2
Жить в твоей голове
>>> print type(mp3album_v2)
<type 'unicode'>
>>> print repr(mp3album_v2)
u'\u0416\u0438\u0442\u044c \u0432 \u0442\u0432\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435'
Looks like setAlbum
expects utf-8
string (?):
def setAlbum(self, a):
self.setTextFrame(ALBUM_FID, self.strToUnicode(a));
def strToUnicode(self, s):
t = type(s);
if t != unicode and t == str:
s = unicode(s, eyeD3.LOCAL_ENCODING);
elif t != unicode and t != str:
raise TagException("Wrong type passed to strToUnicode: %s" % str(t));
return s;
But if I try to do tag.setAlbum(mp3album_v2.encode('cp1251').encode('utf-8'))
, then I am getting an error UnicodeDecodeError: 'utf8' codec can't decode byte 0xc6 in position 0: invalid continuation byte