How to read mp3 tags in shell?

You can also use ffprobe which is part of ffmpeg.

sudo apt-get install ffmpeg
ffprobe file.mp3

If you don't want other information, like track length and so on, you can combine the output with grep:

ffprobe file.mp3 2>&1 | grep -A90 'Metadata:'

Or in order to get only the author:

ffprobe -loglevel error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 file.mp3

You can select other tags by separating them with a comma, such as format_tags=title,album.


I wanted to search for a keyword in all mp3 files in a folder. The folder had 486 files, so it became interesting to know which of the solutions mentioned here is the fastest. Here is the loop I used:

# sudo apt-get install ffmpeg lltag eyed3 mp3info id3v2 libimage-exiftool-perl libid3-tools id3tool

keyword='fill_me_in'

getTitleFF()   { ffprobe "$1" 2>&1 | sed -E -n 's/^ *title *: (.*)/\1/p'; }
getTitleLL()   { lltag --show-tags title "$1" | sed -nE 's/^  TITLE=(.*)/\1/p'; }
getTitleEyed() { eyeD3 2>&1 "$1" | sed -n 's|\x1b\[[0-9;]*mtitle[^:]*: ||p'; }
getTitleInfo() { mp3info -p %t "$1"; }
getTitleId3()  { id3v2 -l "$1" | sed -nE 's/^(TIT2 \([^)]*\)|Title *): (.*)/\2/p'; }
getTitleExif() { exiftool -title -b "$1"; }
getTitleId3i() { id3info "$1" | sed -nE 's/^=== TIT2 \([^)]*\): //p'; }
getTitleTool() { id3tool "$1" | sed -n 's|^Song Title:\t||p'; }

for prog in FF LL Eyed Info Id3 Exif Id3i Tool; do
    echo "=== getTitle${prog} ==="
    time \
    for file in *.mp3; do 
        if "getTitle${prog}" "$file" | grep -q "$keyword"; then 
            echo "$file"
        fi
    done
done

Notes:

  • lltag and mp3info don't find a title, because the files I was using had ID3v2 tags, see the comment by @s-prasanth: How to read mp3 tags in shell?
  • eyeD3 is problematic to use programmatically, because it uses color codes (boldness).
  • eyeD3 and also id3v2 (but only for ID3 v1 tags) return the title and the artist on the same line, which further complicates things; therefore getTitleEyed and sometimes getTitleId3 return both the title and the artist, so please don't copy-paste those functions.
  • getTitleId3 will only work for ID3 v2 tags, because id3v2 has different formats for ID3v1- and ID3v2-tags, i.e.

    Title  :                                 Artist:    
    

    vs. ID3v2:

    TIT2 (Title/songname/content description): 
    
  • As the only program of these 5 eyeD3 prints a red warning for two of the files:

    Invalid mode/bitrate combination for layer II
    No ID3 v1.x/v2.x tag found!
    

    It seems like those two files have ID3v1 tags, because those two files are the only ones where lltag and mp3info can get a title. I'm wondering if this is a bug in eyeD3 as no other program mentioned here has a problem with these files ...

Results (real time):

 Program  | Version    | Time / s
----------+------------+-----------
 exiftool | 10.25      | 49.5 ± 0.5
 lltag    | 0.14.5     | 41   ± 1.0
 ffprobe  | 3.1.3-1+b3 | 33   ± 0.5
 eyeD3    | 0.6.18     | 24   ± 0.5
 id3info  | 3.8.3      | 4.2  ± 0.1
 id3v2    | 0.1.12     | 2.9  ± 0.1
 id3tool  | 1.2a       | 1.7  ± 0.1
 mp3info  | 0.8.5a     | 1.4  ± 0.1

Time-wise the winner here is id3tool (mp3info is faster, but doesn't work with ID3 v2). id3v2 is also quite fast, but the getTitleId3 function would need adjustment to also work with ID3v1-tags, which may at worst slow it down by factor 2.


Ok, I found a program by myself. It is called mp3info and installed by

sudo apt-get install mp3info

To get single mp3 tags from a file, one has to call

mp3info -p %a file.mp3

which gives the artist of the file. The %a means that one want to get the artist and there are some other keys for the other tags.


You can use eyed3. First, from a terminal, install:

sudo apt-get install eyed3

Then, run:

eyeD3 song.mp3

Combine that with grep to get specific tags in one line.

eyeD3 song.mp3 | grep artist

(to strip all mp3 tags, see HERE)