I am trying to update metadata of a bunch of mp3 files using Python and its eyeD3 API.
It looks fairly simple, code I'm using looks as follows:
if not eyeD3.isMp3File(filename):
print filename, 'is not a mp3 file. Ignoring it.'
tag = eyeD3.Tag()
tag.link(filename)
tag.setVersion(eyeD3.ID3_V2)
tag.setTextEncoding(eyeD3.UTF_8_ENCODING)
tag.setTitle(dataset['Title'])
tag.setDate(datetime.datetime.now().year)
tag.update()
What happens is: code executes silently (no errors or exceptions), title is set correctly, date is not set in target file. It remains empty or set to previous value (checked both cases).
Help for setDate function is not particulary amusing:
setDate(self, year, month=None, dayOfMonth=None, hour=None, minute=None, second=None, fid=None) unbound eyeD3.tag.Tag method
... but tells me that my call should be ok. Any ideas what's happening here?
I got the same question as yours. Finally, I abandoned the eyeD3 lib, mutagen
is a good option.
Here is my example using mutagen.mp3
in Python.
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TRCK, TALB, USLT, error
# ID3 info:
# APIC: picture
# TIT2: title
# TPE1: artist
# TRCK: track number
# TALB: album
# USLT: lyric
def id3_cook(directory, filename, item, track_num):
pic_file = directory + '/cover.jpg' # pic file
audio = MP3(filename, ID3=ID3)
try:
audio.add_tags()
except:
pass
audio.tags.add(APIC(
encoding=3,
mime='image/jpeg',
type=3,
desc=u'Cover Picture',
data=open(pic_file).read()
))
audio.tags.add(TIT2(encoding=3, text=item['song'].decode('utf-8')))
audio.tags.add(TALB(encoding=3, text=item['album'].decode('utf-8')))
audio.tags.add(TPE1(encoding=3, text=item['artist'].decode('utf-8')))
audio.tags.add(TRCK(encoding=3, text=str(track_num).decode('utf-8')))
audio.tags.add(USLT(encoding=3, lang=u'eng', desc=u'desc', text=item['lyric'].decode('utf-8')))
audio.save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With