Command line tool for listing ID3 tags under Linux

24

9

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.

petersohn

Posted 2010-04-05T10:04:58.567

Reputation: 2 554

Answers

30

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)"
}]

user4358

Posted 2010-04-05T10:04:58.567

Reputation:

+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... – None – 2016-03-28T09:55:45.223

+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 – 2013-09-06T02:31:02.690

9

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

Ignacio Vazquez-Abrams

Posted 2010-04-05T10:04:58.567

Reputation: 100 516

1The man page says the following though: Only ID3 versions 1.0 and 1.1 are supported. – Calimo – 2018-01-11T08:24:55.430

5

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.

quack quixote

Posted 2010-04-05T10:04:58.567

Reputation: 37 382