How to add ID3 "cover art" by command line?

11,008

Solution 1

An excellent Python application that I routinely use to add cover art to mp3 files is the command line applicationeyeD3. This can be installed from a Terminal as follows:

sudo apt-get install eyed3

Here is an example of a command to add a cover image named cover.jpg to an mp3 file named test.mp3:

eyeD3 --add-image "cover.jpg:FRONT_COVER" test.mp3

See an example below of this at work on my own computer, adding a cover image to an mp3 otherwise empty of meta tags:

andrew@ilium~$ eyeD3 --add-image "cover.jpg:FRONT_COVER" test.mp3
test.mp3    [ 946.12 KB ]
-------------------------------------------------------------------------------
Adding image cover.jpg
Time: 01:00 MPEG1, Layer III    [ 128 kb/s @ 44100 Hz - Joint stereo ]
-------------------------------------------------------------------------------
ID3 v2.4:
title: 
artist: 
album: 
album artist: None
track:      
FRONT_COVER Image: [Size: 95788 bytes] [Type: image/jpeg]
Description: 

Writing ID3 version v2.4
-------------------------------------------------------------------------------
andrew@ilium~$ 

There are many other options for adding images although I have given the basic syntax above. Below are these other options:

  --add-image IMG_PATH:TYPE[:DESCRIPTION]
                        Add or replace an image. There may be more than one
                        image in a tag, as long as the DESCRIPTION values are
                        unique. The default DESCRIPTION is ''. If PATH begins
                        with 'http[s]://' then it is interpreted as a URL
                        instead of a file containing image data. The TYPE must
                        be one of the following: OTHER, ICON, OTHER_ICON,
                        FRONT_COVER, BACK_COVER, LEAFLET, MEDIA, LEAD_ARTIST,
                        ARTIST, CONDUCTOR, BAND, COMPOSER, LYRICIST,
                        RECORDING_LOCATION, DURING_RECORDING,
                        DURING_PERFORMANCE, VIDEO, BRIGHT_COLORED_FISH,
                        ILLUSTRATION, BAND_LOGO, PUBLISHER_LOGO.

References:

Solution 2

Here is a Python script that works for me. Run it with python script.py audiofile.mp3.

You will need mutagen; install it with sudo -H pip install mutagen.

from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
import sys
mp3file=sys.argv[1]
audio = MP3(mp3file, ID3=ID3)

try:
   audio.add_tags()
except error:
   pass

audio.tags.add(
   APIC(
      encoding=1,
      mime='image/png',
      type=3,
      desc=u'Cover',
      data=open('/path/to/artwork.png').read()
   )
)
audio.save()
Share:
11,008

Related videos on Youtube

Ollie Harridge
Author by

Ollie Harridge

C/C++ programmer, PostgreSQL programmer/DBA, System and Network administrator. There are a few things that cannot really be done. And all of them are well known and documented.

Updated on September 18, 2022

Comments

  • Ollie Harridge
    Ollie Harridge over 1 year

    I need to add ID3 cover art to some MP3 files. I need a command line tool (no GUI) but it seems that neither id3 nor id3v2 tools can do it. Any hint?

  • Ollie Harridge
    Ollie Harridge almost 8 years
    Thanks for the hint. But this basically equals to "write the program yourself".
  • Jos
    Jos almost 8 years
    I don't understand your comment. I have given you the program. What do you need to write yourself?
  • Ollie Harridge
    Ollie Harridge almost 8 years
    If you read my question not as personal but as a general one, your answer, while a really good one, sounds like "No way, unless you write a program to do so (or youse Jos')".
  • Ollie Harridge
    Ollie Harridge almost 8 years
    This is really new to me! So far I've only found GUI tools or some MP3 encoder like lame. Thanks.
  • Edward Falk
    Edward Falk about 4 years
    Seconded, eyeD3 is the way to go.