我制作了一个脚本,将 MP3 文件的一些元数据更改为标题大小写,同时擦除所有其他字段。它通过将现有元数据复制到单独的变量,然后使用 tag.clear() 擦除原始数据,最后在标题大小写中添加回元数据来实现此目的。这适用于我使用过的每个标签,除了评论。
当有现有评论时,我可以用以下方式编辑它们:
import eyed3
mp3 = eyed3.load(FILE_PATH)
comments = mp3.tag.comments
comments_list = []
for comment in comments:
comments_list.append(comment.text.title()) #This creates an editable list for recall
for comment in comments: #As long as there were already comments, I can change them with this:
comment.text = ("anything")
mp3.tag.save()
但是,由于清除了所有元数据,注释仅返回 None,并且我不知道如何添加或替换它。
为了澄清,我想向空白 MP3 文件添加注释。我已经知道如何编辑现有评论。
正如我所评论的,我不清楚您的代码想要实现什么(例如,如果文件元数据为空,您想在
comments_list
中追加什么以及为什么?)。
但无论如何,以下代码应该向您的文件添加一般注释。
comment_to_add = "My new comment" # Change this to the comment you want
import eyed3
mp3 = eyed3.load(FILE_PATH)
mp3.tag.clear()
comments = mp3.tag.comments
comments.set(comment_to_add)
mp3.tag.save()
还不清楚 For 循环的意图是什么。可以按照以下格式在不同的键/描述下添加注释
comments.set(TEXT, DESCRIPTION)
在这种情况下,For循环将迭代这些。例如,
comment_to_add = "My new comment"
import eyed3
mp3 = eyed3.load(FILE_PATH)
mp3.tag.clear()
comments = mp3.tag.comments
comments.set(comment_to_add)
comments.set("Classical", "Genre")
comments.set("1824", "year")
mp3.tag.save()
"""The code below should return:
My new comment
Classical
1824
"""
for c in comments:
print(c.text)
更改应出现在文件中(下面的 MediaInfo 输出):
'''
Format : MPEG Audio
File size : 153 KiB
Duration : 8 s 620 ms
Overall bit rate mode : Constant
Overall bit rate : 128 kb/s
Genre : Classical
Writing library : LAME3.90 (alpha)
Comment : My new comment
year : 1824
'''