Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 19 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! –  mikiemorales Sep 6 '13 at 2:31
add comment

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.