Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

id3

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.

like image 374
Tensigh Avatar asked Aug 21 '13 23:08

Tensigh


People also ask

Do I need ID3 tags?

ID3 tags are a critical component of audio files, particularly MP3s. In simple terms, ID3 tags are the metadata for an audio file to make sure they are displayed correctly in computer software such as a DAW, a DJ streaming software, or a music streaming app like Apple Music.

How do I get rid of ID3 tags?

Simply select the track, or tracks, that you wish to remove ID3 tags for, then right click them in the Music Tag file list. On the menu that appears, click the "Remove Tags" option. You'll be presented with a box wish asks you to confirm that you would like to remove the tags, and that the operation is irreversible.

Where are ID3 tags stored?

ID3 tags are metadata stored within MP3 files that contains information such as; the title of the podcast or episode, the artist, and an image artwork for the episode. There are two versions of the ID3 tags. ID3v1 contains only basic, text-only, information and it's placed at the end of the audio file.


1 Answers

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']}
like image 60
bgporter Avatar answered Nov 15 '22 22:11

bgporter