Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a script that manipulates ID3 tags of mp3 files. I need a tool that reads the tags and outputs it in a format in a machine-readable format. For example, if I want it to output only the title, then it outputs the title, nothing else. I tried different tools like id3 or eyeD3, but they can only be used to write tags or to output them in a human-readable format. Of course I could just filter that output through sed, but it seems unnecessarily complicated to me.

share|improve this question
up vote 26 down vote accepted

You could use the exiftool command from the libimage-exiftool-perl package which lets you read (and write) metadata from multimedia files, including mp3s. It can output to a variety of formats including key-value, json, xml and user-defined formats. You can choose to list only specified tags.

% exiftool -json 09\ -\ \(Tom\ Waits\)\ -\ Walk\ Away.mp3
  "SourceFile": "09 - (Tom Waits) - Walk Away.mp3",
  "ExifToolVersion": 7.82,
  "FileName": "09 - (Tom Waits) - Walk Away.mp3",
  "Directory": ".",
  "FileSize": "2.5 MB",
  "FileModifyDate": "2008:07:12 13:58:52+01:00",
  "FileType": "MP3",
  "MIMEType": "audio/mpeg",
  "MPEGAudioVersion": 1,
  "AudioLayer": 3,
  "AudioBitrate": 128000,
  "SampleRate": 44100,
  "ChannelMode": "Stereo",
  "MSStereo": "Off",
  "IntensityStereo": "Off",
  "Emphasis": "None",
  "ID3Size": 1678,
  "Title": "Walk Away",
  "Album": "Dead Man Walking",
  "Genre": "OST",
  "Track": 9,
  "Artist": "Tom Waits",
  "Year": "",
  "Comment": "",
  "Duration": "02:42 (approx)"
share|improve this answer
+1 "sudo port install p5.16-image-exiftool" - gets you going in a mac with MacPorts... Just "exiftool-5.16 /Volumes/MMED/music/Esperanza\ Spalding/Esperanza/02.\ I\ Know\ You\ Know.mp3" and you get all the metadata spit out! Thanks! – mimoralea Sep 6 '13 at 2:31
+1 I've just had the same need but for FLAC audio. Worked like a charm. Too bad the program name gives no hint as for the full extent of its possibilities... – Nasha Mar 28 at 9:55

id3info in id3lib outputs the ID3 tags in a format that's dead simple to machine-parse.

share|improve this answer

I would look into the Mutagen tagging library for Python, which includes a basic scriptable command-line tool, mid3v2. While mid3v2's output is primarily human-readable, the --list-raw option may be suitable by itself:

$ mid3v2 --list-raw 09_Walk\ Away.mp3
Raw IDv2 tag info for 09_Walk Away.mp3:
TDRC(encoding=3, text=[u'1996'])
TIT2(encoding=3, text=[u'Walk Away'])
TRCK(encoding=3, text=[u'9'])
TPE1(encoding=3, text=[u'Tom Waits'])
TALB(encoding=3, text=[u'Dead Man Walking'])
TCON(encoding=3, text=[u'Soundtrack'])

Note this tool only lists ID3 tags, not additional attributes of the MP3 file like exiftool. But if you wanted only a particular tag, a simple grep for the tagname will grab that for you:

$ mid3v2 --list-raw 09_Walk\ Away.mp3 | grep TIT2
TIT2(encoding=3, text=[u'Walk Away'])

If mid3v2 isn't enough for you by itself, and you're comfortable with Python, you could script your own tool to interface with the Mutagen library and read or manipulate the tags directly.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .