Python+eyeD3:无法将日期保存到mp3 metad

2024-10-01 15:34:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python及其eyed3api更新一堆mp3文件的元数据。在

它看起来相当简单,我使用的代码如下所示:

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()

发生的情况是:代码无声地执行(没有错误或异常),标题设置正确,日期在目标文件中设置为而不是。它保持为空或设置为以前的值(两种情况都选中)。在

setDate函数的帮助并不特别有趣:

^{pr2}$

。。。但告诉我我的电话应该没问题。你知道这里发生了什么吗?在


Tags: 文件数据代码datetimeiftagnot情况
1条回答
网友
1楼 · 发布于 2024-10-01 15:34:16

我有和你一样的问题。最后,我放弃了eyeD3库,mutagen是个不错的选择。在

下面是我在Python中使用mutagen.mp3的示例。在

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()

相关问题 更多 >

    热门问题