使用 EasyID3 编写 ID3 标签

Writing ID3 tags using EasyID3

我正在编写一个使用诱变剂更新 .mp3 文件中的元数据信息的脚本。
评论标签好像有问题

到目前为止,这是我的代码

import  mutagen
from mutagen.easyid3 import EasyID3

path = 'song.mp3'
try:
    tag = EasyID3(path)
except:
    tag = mutagen.File(path, easy=True)
    tag.add_tags()

tag['genre'] = 'mygenre'
tag['artist'] = 'myartist'
tag['title'] = 'mytitle'
tag['date'] = '1000'
tag['album'] = 'myalbum'
tag['albumartist'] = 'myalbumartist'
tag['tracknumber'] = 'mytracknumber'
tag['discnumber'] = 'mydiscnumber'
tag.save(v2_version=3)

这对我来说很好,但是当我添加

tag['comment'] = 'mycomment'

我收到以下错误

mutagen.easyid3.EasyID3KeyError: "'comment' is not a valid key"
>>> import pprint
>>> from mutagen.easyid3 import EasyID3
>>> print EasyID3.valid_keys.keys()
>>> pprint.pprint(EasyID3.valid_keys.keys())
['albumartistsort',
 'musicbrainz_albumstatus',
 'lyricist',
 'musicbrainz_workid',
 'releasecountry',
 'date',
 'albumartist',
 'musicbrainz_albumartistid',
 'composer',
 'catalognumber',
 'encodedby',
 'tracknumber',
 'musicbrainz_albumid',
 'album',
 'asin',
 'musicbrainz_artistid',
 'mood',
 'copyright',
 'author',
 'media',
 'performer',
 'length',
 'acoustid_fingerprint',
 'version',
 'artistsort',
 'titlesort',
 'discsubtitle',
 'website',
 'musicip_fingerprint',
 'conductor',
 'musicbrainz_releasegroupid',
 'compilation',
 'barcode',
 'performer:*',
 'composersort',
 'musicbrainz_discid',
 'musicbrainz_albumtype',
 'genre',
 'isrc',
 'discnumber',
 'musicbrainz_trmid',
 'acoustid_id',
 'replaygain_*_gain',
 'musicip_puid',
 'originaldate',
 'language',
 'artist',
 'title',
 'bpm',
 'musicbrainz_trackid',
 'arranger',
 'albumsort',
 'replaygain_*_peak',
 'organization',
 'musicbrainz_releasetrackid']

似乎 comment 确实不是有效密钥。不怕,好像是you can define your own! Combining that with this document,好像我们需要的frameid就叫COMM。因此,添加一个 EasyID3.RegisterTextKey('comment', 'COMM') 应该(可能)让你做你需要的。 :)