Accessing lyrics through mp3agic

368 Views Asked by At

I'm not good at java. I'm doing a project that updates the metadata of music files using the library, mp3agic. I don't find the lyrics part in the library. Can someone who is good with ID3 tags, help me access the lyrics?

1

There are 1 best solutions below

0
On

I know this might be too late and OP might have figured it out already but if someone is still stucked with this, please have a look here

Set Lyrics in MP3 ID3v2 Tag

and give the below a try

Edit AbstractID3v2Tag with following changes;

public static final String ID_TEXT_LYRICS = "USLT";

private ID3v2CommentFrameData extractLyricsFrameData(String id) {
        ID3v2FrameSet frameSet = frameSets.get(id);
        if (frameSet != null) {
            Iterator<ID3v2Frame> iterator = frameSet.getFrames().iterator();
            while (iterator.hasNext()) {
                ID3v2Frame frame = (ID3v2Frame) iterator.next();
                ID3v2CommentFrameData frameData;
                try {
                    frameData = new ID3v2CommentFrameData(useFrameUnsynchronisation(), frame.getData());
                    return frameData;
                } catch (InvalidDataException e) {
                    // Do nothing
                }
            }
        }
        return null;
    }

public String getLyrics() {
        ID3v2CommentFrameData frameData;
        if (obseleteFormat) return null;
        else frameData = extractLyricsFrameData(ID_TEXT_LYRICS);
        if (frameData != null)
            return frameData.getComment().toString();
        return null;
    }

public void setLyrics(String lyrics) {
        if (lyrics != null && lyrics.length() > 0) {
            invalidateDataLength();
            ID3v2CommentFrameData frameData = new ID3v2CommentFrameData(useFrameUnsynchronisation(), "eng", null, new EncodedText(lyrics));
            addFrame(createFrame(ID_TEXT_LYRICS, frameData.toBytes()), true);
        }
    }

Afterwards you can simply call id3v2Tag.setLyrics() and id3v2tag.getLyrics(), this seems to be working fine. Make sure to ascii encode your lyrics body when using setLyrics().