编辑音频文件元数据的简单接口
music-tag的Python项目详细描述
音乐标签
music tag是一个使用接口编辑音频元数据的库 这不依赖于基础文件格式。换句话说,编辑 MP3文件不应该和flac,m4a,…这个图书馆是 只是在mutagen上面的一层, 做所有的重担。
格式
以下文件格式正在进行测试。
aac
aiff
dsf
flac
m4a
mp3
ogg
opus
wav
wv
按键
使用具有以下键的类似字典的接口可以获得元数据。
键不区分大小写,可以包含任意空格、“-”和“\
角色。换句话说,Album Artist
,album-artist
,和
album_artist
都是albumartist
的同义词。此外,disk
与disc
同义。
album
albumartist
artist
artwork
comment
compilation
composer
discnumber
genre
lyrics
totaldiscs
totaltracks
tracknumber
tracktitle
year
示例
阅读标签
importmusic_tagf=music_tag.load_file("music-tag/sample/440Hz.m4a")# dict access returns a MetadataItemtitle_item=f['title']# MetadataItems keep track of multi-valued keystitle_item.values# -> ['440Hz']# A single value can be extractedtitle_item.first# -> '440Hz'title_item.value# -> '440Hz'# MetadataItems can also be cast to a stringstr(title_item)# -> '440Hz'
设置标签
# tags can be set as if the file were a dictionaryf['title']='440Hz'# additional values can be appended to the tagsf.append_tag('title','subtitle')title_item.values# -> ['440Hz', 'subtitle']title_item.first# -> '440Hz'title_item.value# -> '440Hz, subtitle'str(title_item)# -> '440Hz, subtitle'
移除标签
delf['title']f.remove_tag('title')
专辑作品
相册艺术品包装在一个对象中,该对象跟踪 与图像关联的额外元数据。注意一些相册艺术功能 需要枕头(现代皮尔)图书馆。
# get artworkart=f['artwork']# Note: `art` is a MetadataItem. Use ``art.value`` if there is# only one image embeded in the file. This will raise a# ValueError if there is more than one image. You can also# use ``art.first``, or iterate through ``art.values``.art.first.mime# -> 'image/jpeg'art.first.width# -> 1280art.first.height# -> 1280art.first.depth# -> 24art.first.data# -> b'... raw image data ...'# set artworkwithopen('music_tag/test/sample/imgA.jpg','rb')asimg_in:f['artwork']=img_in.read()withopen('music_tag/test/sample/imgB.jpg','rb')asimg_in:f.append_tag('artwork',img_in.read())# Make a thumbnail (requires Pillow)art.first.thumbnail([64,64])# -> pillow imageart.first.raw_thumbnail([64,64])# -> b'... raw thumbnail data ...'
保存标签
# finally, you can bounce the edits to diskf.save()