Python + eyeD3: unable to save date in mp3 metadata

I am trying to update metadata from a heap of mp3 files using Python and its eyeD3 API.

It looks pretty simple, the code I'm using looks like this:

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: the code is executed silently (without errors or exceptions), the header is set correctly, the date is not set in the target file. It remains empty or is set to the previous value (both cases are noted).

The help for the setDate function is not particularly funny:

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 fine. Any ideas what is going on here?

+5
source share
1 answer

, . , eyeD3 lib, mutagen - .

mutagen.mp3 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()
+3

All Articles