Accessing MP3 metadata with Python [closed]

Posted on

Question :

Accessing MP3 metadata with Python [closed]

How can I retrieve mp3 metadata in Python?

Asked By: akdom


Answer #1:

I used eyeD3 the other day with a lot of success. I found that it could add artwork to the ID3 tag which the other modules I looked at couldn’t. You’ll have to install using pip or download the tar and execute python install from the source folder.

Relevant examples from the website are below.

Reading the contents of an mp3 file containing either v1 or v2 tag info:

 import eyeD3
 tag = eyeD3.Tag()"/some/file.mp3")
 print tag.getArtist()
 print tag.getAlbum()
 print tag.getTitle()

Read an mp3 file (track length, bitrate, etc.) and access it’s tag:

if eyeD3.isMp3File(f):
     audioFile = eyeD3.Mp3AudioFile(f)
     tag = audioFile.getTag()

Specific tag versions can be selected:"/some/file.mp3", eyeD3.ID3_V2)"/some/file.mp3", eyeD3.ID3_V1)"/some/file.mp3", eyeD3.ID3_ANY_VERSION)  # The default.

Or you can iterate over the raw frames:

 tag = eyeD3.Tag()"/some/file.mp3")
 for frame in tag.frames:
    print frame

Once a tag is linked to a file it can be modified and saved:

 tag.setAlbum(u"Age of Quarrel")

If the tag linked in was v2 and you’d like to save it as v1:


Read in a tag and remove it from the file:"/some/file.mp3")

Add a new tag:

 tag = eyeD3.Tag()'/some/file.mp3')    # no tag in this file, link returned False
Answered By: Owen

Answer #2:

I’ve used mutagen to edit tags in media files before. The nice thing about mutagen is that it can handle other formats, such as mp4, FLAC etc. I’ve written several scripts with a lot of success using this API.

Answered By: jkp

Answer #3:

A problem with eyed3 is that it will throw NotImplementedError("Unable to write ID3 v2.2") for common MP3 files.

In my experience, the mutagen class EasyID3 works more reliably. Example:

from mutagen.easyid3 import EasyID3

audio = EasyID3("example.mp3")
audio['title'] = u"Example Title"
audio['artist'] = u"Me"
audio['album'] = u"My album"
audio['composer'] = u"" # clear

All other tags can be accessed this way and saved, which will serve most purposes. More information can be found in the Mutagen Tutorial.

Answered By: Chris Redford

Answer #4:

What you’re after is the ID3 module. It’s very simple and will give you exactly what you need. Just copy the file into your site-packages directory and you’ll be able to do something like the following:

from ID3 import *
  id3info = ID3('file.mp3')
  print id3info
  # Change the tags
  id3info['TITLE'] = "Green Eggs and Ham"
  id3info['ARTIST'] = "Dr. Seuss"
  for k, v in id3info.items():
    print k, ":", v
except InvalidTagError, message:
  print "Invalid ID3 tag:", message
Answered By: Harley Holcombe

Answer #5:

check this one out:

Usage example:

>>> import songdetails
>>> song = songdetails.scan("data/song.mp3")
>>> print song.duration

Saving changes:

>>> import songdetails
>>> song = songdetails.scan("data/commit.mp3")
>>> song.artist = "Great artist"
Answered By: Corey Goldberg

Answer #6:

Just additional information to you guys:

take a look at the section “MP3 stuff and Metadata editors” in the page of PythonInMusic.

Answered By: quabug

Answer #7:

I looked the above answers and found out that they are not good for my project because of licensing problems with GPL.

And I found out this: PyID3Lib, while that particular python binding release date is old, it uses the ID3Lib, which itself is up to date.

Notable to mention is that both are LGPL, and are good to go.

Answered By: Ciantic

Answer #8:

A simple example from the book Dive Into Python works ok for me, this is the download link, the example is Don’t know if it’s the best, but it can do the basic job.

The entire book is available online here.

Answered By: PabloG

Leave a Reply

Your email address will not be published.