penfold1992
penfold1992

Reputation: 314

why am I unable to display the USLT lyrics

I am using mutagen to try to find lyrics on my media. when i run the following

import mutagen.mp3

mp3 = MP3(mp3file)
print mp3.pprint()

I can see that the frame USLT exists and it contains:

USLT=[unrepresentable data]

I do not understand why the data is not representable. I have inserted the tag into the mp3 file as follows:

tags = ID3(mp3file)
tags[u"USLT::'eng'"] = (USLT(encoding=3, lang=u'eng', desc=u'desc', text="this is a test"))
tags.save()

I dont really understand why I need to declare the tag as u"USLT::'eng'"] rather than using "USLT" on its own but I can confirm this works because I can see the tag appear in mp3tag (software used to modify mp3 tags)

so the tag exists, with lyrics. I can see this on both mp3.pprint() and in mp3tag yet I am not able to view it with the following code:

ulyrics = mp3["USLT"]
print ulyrics

I have tried changing the "USLT" to u"USLT::'eng'" but I get no difference. I regularly see the error message:

File "filepath\mutagen_util.py", line 206, in getitem return self.__dict[key] KeyError: 'USLT'

but I cannot tell if this is an error in mutagen or my code (seeing as I can see results of all other tags I require)

Upvotes: 3

Views: 584

Answers (1)

Nicolás Ozimica
Nicolás Ozimica

Reputation: 9758

At this moment, what worked for me is this:

from mutagen.id3 import ID3

mp3file = "... path to mp3 file ..."

tags = ID3(mp3file)
ulyrics = tags.getall('USLT')[0]

# change the lyrics text
ulyrics.text = " An arbitrary new lyrics text..."
tags.setall('USLT', [ulyrics])

# change the lyrics object completely
ulyrics = USLT(encoding=3, lang=u'eng', desc=u'desc', text="this is a test")
tags.setall('USLT', [ulyrics])

It's important to note that it's not necessary to use the key "USLT::'eng'", since the lang is included in the USLT object.

Upvotes: 1

Related Questions