Command line tool for listing ID3 tags under Linux

28,367

Solution 1

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

Solution 2

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

Solution 3

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:
28,367
petersohn
Author by

petersohn

Updated on September 17, 2022

Comments

  • petersohn
    petersohn over 1 year

    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.

  • mimoralea
    mimoralea over 10 years
    +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!
  • Sheryl
    Sheryl about 8 years
    +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...
  • Calimo
    Calimo over 6 years
    The man page says the following though: Only ID3 versions 1.0 and 1.1 are supported.