诱变剂的save()不会设置或更改MP3文件的封面艺术

2024-05-29 08:11:16 发布

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

我尝试使用Mutagen以以下方式更改一组MP3文件的ID3(版本2.3)封面艺术:

from mutagen.mp3 import MP3
from mutagen.id3 import APIC

file = MP3(filename)

with open('Label.jpg', 'rb') as albumart:
    file.tags['APIC'] = APIC(
        encoding=3,
        mime='image/jpeg',
        type=3, desc=u'Cover',
        data=albumart.read()
    )
file.save(v2_version=3)

但是,文件(或者至少是APIC标记)保持不变,这是通过读回标记检查的。但是,在系统文件资源管理器中,文件确实显示更新的Date modified。如何让诱变剂正确更新封面艺术


Tags: 文件from标记import版本方式艺术mp3
2条回答

由于ID3 specification声明:

There may be several pictures attached to one file, each in their individual "APIC" frame, but only one with the same content descriptor.

这意味着ID3必须使用['APIC:Description']存储APIC标记。此外,建议的添加标记的方法不是像问题中的示例那样直接通过dictionary接口,而是使用^{}函数。使用ID3对象还允许我们使用^{}函数检查标记是否已正确附加

from mutagen.id3 import APIC, ID3
file = ID3("test.mp3")

print(file.getall('APIC')) # [] (assuming no APIC tags attached)

with open('image.jpg', 'rb') as albumart:
    file.add(APIC(
        encoding=3,
        mime='image/jpeg',
        type=3, desc=u'Cover',
        data=albumart.read()
    ))

print(file.getall('APIC'))
# [APIC(encoding=<Encoding.UTF16: 1>, mime='image/jpeg', type=<PictureType.COVER_FRONT: 3>, desc='Cover', data=...]
file.save(v2_version=3)

我需要将封面设置为“APIC:”标记,而不是“APIC”标记(我猜IDv2.3就是这样指定的)

相关问题 更多 >

    热门问题