Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

Is there a way to read the mp3 tags of a file from the shell? Something like: mp3tags MyFile.mp3 author should output the author-tag of an mp3-file.

share|improve this question
up vote 17 down vote accepted

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.

share|improve this answer
10  
Additional info: There are 4 different standards of mp3 tags id3v1, id3v2.2(obsolete), id3v2.3, id3v2.4 en.wikipedia.org/wiki/ID3. A file can have v1 and/or v2 tags (Yes v1 and v2 can coexist, but v2.x and v2.y cannot coexist). I believe v2.3 is the most widely used one. According to ibiblio.org/mp3info (See Todo) v2 tags are not supported by mp3info. You might want to look at id3v2 - It can edit/add v2 and display v1 and v2. If you don't like the way it displays the tags you can write a script that runs id3v2 and processes the output appropriately. – S Prasanth Dec 11 '12 at 8:04
    
@SPrasanth how to make it to display a specific tag. For example: only the artist of an mp3 file? – Gowtham Gopalakrishnan Apr 23 '14 at 11:10
    
@SPrasanth I got it. Thanks I'm using -R flag with grep to get the specified output. – Gowtham Gopalakrishnan Apr 23 '14 at 11:14

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)

share|improve this answer
1  
I tried this, and the command to use is eyeD3, with an uppercase D ;). But I found another tool, which better matches my needs, named mp3info. This can output mp3 tags without the need to use grep, which I prefer. – red_trumpet Dec 8 '12 at 13:29
    
eyeD3 works better for me because it works with id3v2, but @red_trumpet is right, the command should be eyeD3 not eyed3 – bmaupin May 29 '13 at 4:03

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:

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" | grep 'title'; }
getTitleInfo() { mp3info -p %t "$1"; }
getTitleId3()  { id3v2 -l "$1" | sed -nE 's/^TIT2 \([^)]*\): (.*)/\1/p'; }
getTitleExif() { exiftool -title -b "$1"; }

for prog in FF LL Eyed Info Id3 Exif; 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  | time / s
----------+----------
 exiftool |    54
 eyeD3    |    23
 ffprobe  |    45
 id3v2    |   4.4
 mp3info  |   1.2
 lltag    |    40

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

share|improve this answer

I prefer to use id3v2, just type id3v2 -l somefile.mp3. You can also see the id3v2 man page for more specific use.

share|improve this answer

Check out lltag if you are looking for a solution which supports more than just mp3/ID3.

Install it with:

sudo apt-get install lltag

to view all tags with it: (-S is for show)

lltag -S somefile.mp3

to view certain tags with it:

lltag --show-tags artist,album,title,number somefile.mp3
share|improve this answer

You can try exiftool(Read and write meta information in files).

"ExifTool is a platform-independent Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files. ExifTool supports many different metadata formats including EXIF, GPS, IPTC, XMP, JFIF, GeoTIFF, ICC Profile, Photoshop IRB, FlashPix, AFCP and ID3, as well as the maker notes of many digital cameras by Canon, Casio, FLIR, FujiFilm, GE, HP, JVC/Victor, Kodak, Leaf, Minolta/Konica-Minolta, Motorola, Nikon, Nintendo, Olympus/Epson, Panasonic/Leica, Pentax/Asahi, Phase One, Reconyx, Ricoh, Samsung, Sanyo, Sigma/Foveon and Sony." - ExifTool by Phil Harvey

Here is an example of the command:

exiftool test.mp3 
ExifTool Version Number         : 10.00
File Name                       : test.mp3
Directory                       : .
File Size                       : 8.2 MB
File Modification Date/Time     : 2016:03:02 21:44:58+01:00
File Access Date/Time           : 2016:04:06 21:34:01+02:00
File Inode Change Date/Time     : 2016:03:02 21:45:36+01:00
File Permissions                : rw-rw-r--
File Type                       : MP3
File Type Extension             : mp3
MIME Type                       : audio/mpeg
MPEG Audio Version              : 1
Audio Layer                     : 3
Sample Rate                     : 44100
Channel Mode                    : Stereo
MS Stereo                       : Off
Intensity Stereo                : Off
Copyright Flag                  : False
Original Media                  : False
Emphasis                        : None
VBR Frames                      : 9544
VBR Bytes                       : 8467680
ID3 Size                        : 115419
Band                            : Tech N9ne Collabos
Album                           : Strangeulation (Deluxe Edition)
Composer                        : Tech N9ne Collabos
Genre                           : Rap & Hip-Hop
Copyright                       : 2014 Strange Music, Inc
Title                           : American Horror Story (feat. Ces Cru)
Artist                          : Tech N9ne Collabos
Track                           : 10
Year                            : 2014
Comment                         : 
Lyrics                          : 
Private                         : (Binary data 8192 bytes, use -b option to extract)
Picture MIME Type               : image/jpeg
Picture Type                    : Front Cover
Picture Description             : 
Picture                         : (Binary data 104371 bytes, use -b option to extract)
Audio Bitrate                   : 272 kbps
Date/Time Original              : 2014
Duration                        : 0:04:09 (approx)
share|improve this answer

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.