Python - Add ID3 tags to mp3 file that has NO tags

杀马特。学长 韩版系。学妹 提交于 2019-12-06 19:44:23

问题


I get a lot of podcasts that have no ID3 tags in them. I've tried a number of tools that I could use to loop through directories and add title and artist info to the ID3 tags, but they fail. I've tried ID3, eyed3 and mutagen. Most of the time if a file has no ID3 tag these modules fail.

Can someone recommend a good ID3 tag editor library that will work through loops? What else do I need to know about editing/adding ID3 tags when they're 100% blank? It's getting frustrating trying library after library only to find that the problem remains.

Thank you.


回答1:


Mutagen handles this just fine:

>>> import mutagen
>>> from mutagen.easyid3 import EasyID3
>>> filePath = "8049.mp3"

>>> try:
>>>    meta = EasyID3(filePath)
>>> except mutagen.id3.ID3NoHeaderError:
>>>    meta = mutagen.File(filePath, easy=True)
>>>    meta.add_tags()
>>> meta
{}
>>> type(meta)
<class 'mutagen.easyid3.EasyID3'>
>>> meta['title'] = "This is a title"
>>> meta['artist'] = "Artist Name"
>>> meta['genre'] = "Space Funk"
>>> meta.save(filePath, v1=2)
>>> changed = EasyID3("8049.mp3")
>>> changed
{'genre': [u'Space Funk'], 'title': [u'This is a title'], 'artist': [u'Artist Name']}


来源:https://stackoverflow.com/questions/18369188/python-add-id3-tags-to-mp3-file-that-has-no-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!