无法在 Python 3.5.2 中将封面艺术嵌入到 Mp3
Cannot Embed Cover Art To Mp3 in Python 3.5.2
我有这个文件“image.jp
和这个 .mp3 文件:
"Green Day - When I Come Around [Official Music Video].mp3"
目录中"test"
我已经使用 eyeD3 库成功设置了作者、标题、专辑等标签。
然后我尝试设置封面艺术。
我已经尝试了两种可能性,但 none 其中一种可行:
第一个:诱变剂:
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
complete_file_path = "test\"+"Green Day - When I Come Around [Official Music Video].mp3"
path_to_thumb_wf = "test\"+"image.jpg"
audio = MP3(complete_file_path, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
audio.add_tags()
except error:
pass
print(path_to_thumb_wf)
audio.tags.add(
APIC(
encoding=3, # 3 is for utf-8
mime='image/jpg', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(path_to_thumb_wf, 'rb').read()
)
)
audio.save(v2_version=3)
以及使用 eyeD3
的解决方案
audiofile = eyed3.load(complete_file_path)
# read image into memory
imagedata = open(path_to_thumb_wf,"rb").read()
# append image to tags
audiofile.tag.images.set(3,imagedata,"image/jpeg", u"you can put a description here")
audiofile.tag.save()
我在 Windows 10 上使用 python 3.5.2。我不知道它是否会影响结果,但我还是要说,这首歌已经翻唱了我想改变的艺术。
如 ID3v2.3 section on APIC
中所述:
There may be several pictures attached to one file, each in their individual "APIC" frame, but only one with the same content descriptor. There may only be one picture with the picture type declared as picture type and respectively.
在 v2.3 中,IIRC,"content descriptor" 实际上并没有在任何地方记录,所以不同的客户端在这里做的事情可能略有不同,但大多数工具会将其视为图片类型加描述字符串,或者作为整个 header(文本编码、MIME 类型、图片类型和编码描述)作为二进制 blob。 (有些工具会忽略它并允许您存储具有完全相同帧 headers 的图片,但我认为这与 Mutagen 无关。)
无论如何,这意味着您可能只是添加另一张名为 'Cover'
的 Cover (front)
图片,而不是替换任何现有图片。
你没有解释你是如何查看文件的。但我猜你正试图在 Windows Media Player 或 iTunes 或其他播放器中打开它,或在 Windows Explorer 中查看它(我认为它只是要求 WMP 读取标签),或类似的东西?
几乎所有此类工具,当面对多张图片时,只显示第一张。 (有的连图片类型都不区分,第一张图给你任意类型,哪怕是32x32的文件图标……)
但是,有些确实可以查看其他图片。例如,在 iTunes 中,如果您在曲目上 Get Info
或 Properties
,则转到 Cover Art
或类似的选项卡(抱歉含糊不清,但名称已在各个版本中更改),你可以看到标签中的所有图片。
无论如何,如果您想用不同的 APIC 替换 APIC,您要么需要与描述符完全匹配(同样,这对不同的库可能意味着不同的东西......),或者更简单地说,只需删除旧的并添加新的。
还有一件事需要注意:iTunes 和 WMP 缓存封面艺术,并假设一旦文件被导入它就永远不会改变。而且WMP还有各种东西可以覆盖文件中的图片,比如在同一目录下properly-UUID'文件夹封面图片。
我有这个文件“image.jp 和这个 .mp3 文件:
"Green Day - When I Come Around [Official Music Video].mp3"
目录中"test"
我已经使用 eyeD3 库成功设置了作者、标题、专辑等标签。 然后我尝试设置封面艺术。
我已经尝试了两种可能性,但 none 其中一种可行: 第一个:诱变剂:
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
complete_file_path = "test\"+"Green Day - When I Come Around [Official Music Video].mp3"
path_to_thumb_wf = "test\"+"image.jpg"
audio = MP3(complete_file_path, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
audio.add_tags()
except error:
pass
print(path_to_thumb_wf)
audio.tags.add(
APIC(
encoding=3, # 3 is for utf-8
mime='image/jpg', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(path_to_thumb_wf, 'rb').read()
)
)
audio.save(v2_version=3)
以及使用 eyeD3
的解决方案audiofile = eyed3.load(complete_file_path)
# read image into memory
imagedata = open(path_to_thumb_wf,"rb").read()
# append image to tags
audiofile.tag.images.set(3,imagedata,"image/jpeg", u"you can put a description here")
audiofile.tag.save()
我在 Windows 10 上使用 python 3.5.2。我不知道它是否会影响结果,但我还是要说,这首歌已经翻唱了我想改变的艺术。
如 ID3v2.3 section on APIC
中所述:
There may be several pictures attached to one file, each in their individual "APIC" frame, but only one with the same content descriptor. There may only be one picture with the picture type declared as picture type and respectively.
在 v2.3 中,IIRC,"content descriptor" 实际上并没有在任何地方记录,所以不同的客户端在这里做的事情可能略有不同,但大多数工具会将其视为图片类型加描述字符串,或者作为整个 header(文本编码、MIME 类型、图片类型和编码描述)作为二进制 blob。 (有些工具会忽略它并允许您存储具有完全相同帧 headers 的图片,但我认为这与 Mutagen 无关。)
无论如何,这意味着您可能只是添加另一张名为 'Cover'
的 Cover (front)
图片,而不是替换任何现有图片。
你没有解释你是如何查看文件的。但我猜你正试图在 Windows Media Player 或 iTunes 或其他播放器中打开它,或在 Windows Explorer 中查看它(我认为它只是要求 WMP 读取标签),或类似的东西?
几乎所有此类工具,当面对多张图片时,只显示第一张。 (有的连图片类型都不区分,第一张图给你任意类型,哪怕是32x32的文件图标……)
但是,有些确实可以查看其他图片。例如,在 iTunes 中,如果您在曲目上 Get Info
或 Properties
,则转到 Cover Art
或类似的选项卡(抱歉含糊不清,但名称已在各个版本中更改),你可以看到标签中的所有图片。
无论如何,如果您想用不同的 APIC 替换 APIC,您要么需要与描述符完全匹配(同样,这对不同的库可能意味着不同的东西......),或者更简单地说,只需删除旧的并添加新的。
还有一件事需要注意:iTunes 和 WMP 缓存封面艺术,并假设一旦文件被导入它就永远不会改变。而且WMP还有各种东西可以覆盖文件中的图片,比如在同一目录下properly-UUID'文件夹封面图片。