python - 使用 Mutagen 编辑 .aiff 文件的标签数据,出现错误 "TypeError: not a Frame instance"和 "ID3NoHeaderError: doesn' t 以 ID3 标签开头”

标签 python id3 mutagen aiff

我正在尝试使用诱变剂将标签写入表 .aif 文件。到目前为止还没有取得太大成功...

从诱变文档中的代码我尝试:


from mutagen.aiff import AIFF

audio = AIFF(“example.aif”)
audio["title"] = u"An example"
audio.save()

这是我想要实现的基本目标,但是我得到以下结果:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_file.py", line 75, in __setitem__
    self.tags[key] = value
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/id3/_tags.py", line 343, in __setitem__
    raise TypeError("%r not a Frame instance" % tag)
TypeError: u'An example' not a Frame instance

无法理解框架实例,因此我寻找其他方法来执行此操作,例如下面的 ID3 类:



from mutagen.id3 import ID3

    tags = ID3()

tags.save("song.mp3")

不返回任何错误,但 .aif 文件返回已损坏。

所以我然后直接从 .aif 加载 ID3 文件 - 这失败了,因为不存在 ID3 标签......



from mutagen.id3 import ID3, TIT2

    audio = ID3("example.aif”)

    audio.add(TIT2(encoding=3, text=u"An example"))

    audio.save()

audio = ID3("example.aif") gives:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/id3/_file.py", line 77, in __init__
    super(ID3, self).__init__(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/id3/_tags.py", line 177, in __init__
    super(ID3Tags, self).__init__(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_util.py", line 533, in __init__
    super(DictProxy, self).__init__(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_tags.py", line 111, in __init__
    self.load(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_util.py", line 169, in wrapper
    return func(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_util.py", line 140, in wrapper
    return func(self, h, *args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/id3/_file.py", line 154, in load
    self._header = ID3Header(fileobj)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/_util.py", line 169, in wrapper
    return func(*args, **kwargs)
  File "/Users/ef/anaconda2/lib/python2.7/site-packages/mutagen/id3/_tags.py", line 66, in __init__
    raise ID3NoHeaderError("%r doesn't start with an ID3 tag" % fn)
mutagen.id3._util.ID3NoHeaderError: 'example.aif' doesn't start with an ID3 tag


最佳答案

当你这样做时:

audio["title"] = u"An example"

您正在为标签分配一个字符串。但是 Mutagen 需要一个文本框架(正如错误消息所表明的那样),其定义如下:

mutagen.id3.TextFrame(encoding=<Encoding.UTF16: 1>, text=[])

所以,做

audio["title"] = mutagen.id3.TextFrame(encoding=3, text=[u"An example"])

关于python - 使用 Mutagen 编辑 .aiff 文件的标签数据,出现错误 "TypeError: not a Frame instance"和 "ID3NoHeaderError: doesn' t 以 ID3 标签开头”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55632904/

相关文章:

ruby - 在 Ruby/Rails 中读取远程 MP3 文件的 ID3 标签?

python - 使用诱变剂为 MP4 文件设置自定义标签时出现问题

python - 使用 SQLite3 + Mutagen 优化 Python 代码

python - 使用 python 部分下载提取 MP3 URL 的 ID3 标签

python - 如何在 Pandas 列字符串中插入空格

python - 使用 ctypes 时释放内存

python - Numpy ndarray 乘法

python - 如何让新的 python 接受不带括号的打印?

python - Python 中的 ID3 标签 - Python 是执行此任务的错误语言吗?

audio - JAudioTagger删除轨道的前几秒