pythonmp3id3v2

How to add SYLT(synced lyrics) tag on ID3v2 mp3 file using python?


I want to add synced lyrics from vtt on my mp3 file using python. I tried using the mutagen module but it didn't work as intended.

from mutagen.id3 import ID3, USLT, SLT
import sys
import webvtt

lyrics = webvtt.read(sys.argv[2])
lyri = []
lyr = []
for lyric in lyrics:
    times = [int(x) for x in lyric.start.replace(".", ":").split(":")]
    ms = times[-1]+1000*times[-2]+1000*60*times[-3]+1000*60*60*times[-4]
    lyri.append((lyric.text,ms))
    lyr.append(lyric.text)
fil = ID3(sys.argv[1])
tag = USLT(encoding=3, lang='kor', text="\n".join(lyr)) # this is unsynced lyrics
#tag = SLT(encoding=3, lang='kor', format=2, type=1, text=lyri) --- not working
print(tag)
fil.add(tag)
fil.save(v1=0)

How can I solve this problem?


Solution

  • I use mutagen to parse an mp3 file that already has SYLT data, and found the usage of SYLT:

    from mutagen.id3 import ID3, SYLT, Encoding
    
    tag = ID3(mp3path)
    sync_lrc = [("Do you know what's worth fighting for", 17640), 
                ("When it's not worth dying for?", 23640), ...]  # [(lrc, millisecond), ]
    tag.setall("SYLT", [SYLT(encoding=Encoding.UTF8, lang='eng', format=2, type=1, text=sync_lrc)])
    tag.save(v2_version=3)
    

    But I can't figure out format=2, type=1 means.