You can use urllib2
to get image data of the image from URL and then use it in eyed3
.
import urllib2
response = urllib2.urlopen(your image url)
imagedata = response.read()
import eyed3
file = eyed3.load("song.mp3")
file.tag.images.set(3, imagedata, "image/jpeg", u "Description")
file.tag.save()
Use
mySong.tag.images.set(type_ = 3, img_data = None, mime_type = None, description = u "you can put a description here", img_url = u "https://upload.wikimedia.org/wikipedia/en/6/60/Recovery_Album_Cover.jpg")
The signature is as follows:
def set(self, type_, img_data, mime_type, description = u "", img_url = None): "" "Add an image of ``type_`` (a type constant from ImageFrame). The `` img_data`` is either bytes or `` None``.In the latter case `` img_url`` MUST be the URL to the image.In this case `` mime_type`` is ignored and "-->" is used to signal this as a link and not data (per the ID3 spec). "" "
You do not need to worry about that. If it annoys you, add the following line to your code. eyed3 still writes the tag without any issue., The Codeslinger Customize Follow Following Sign up Log in Copy shortlink Report this content View post in Reader Manage subscriptions Collapse this bar ,In March 2019, I wrote about using Python with the "pytaglib" library to read and modify audio files’ metadata. This solution worked nicely for what I needed at the time, but as I rewrote my WAV-to-MP3 conversion in Python, I found that it lacked support for adding cover art to the files. After a bit of research, I found eyed3. It also comes with a nice side-effect: it does not require installation of the Taglib C++ library.,For more details, visit the installation guide. Like my old pytaglib post, I will keep this one short and only show code samples for the most relevant tasks.
Installation is simple.
pip install eyeD3
Additionally, on Windows, you need this, too:
pip install python - magic - bin
Before you do anything, import the eyed3 library, of course.
import eyed3
If the file does not yet have any tags, you must create them before setting any metadata.
if not song.tag:
song.initTag()
Note that this erases existing tags, so only call that if you start from scratch. Now you are ready to set the individual tags or read them if you need them.
song.tag.artist = "Behemoth"
song.tag.album = "The Satanist"
song.tag.genre = "Black Metal"
song.tag.recording_date = 2014
song.tag.track_num = 4
song.tag.title = "Ora pro nobis Lucifer"
eyeD3 is a Python tool for working with audio files, specifically MP3 files containing ID3 metadata (i.e. song info).,With this command we’ve set the artist (-a/--artist), album (-A/--album), title (-t/--title), and track number (-n/--track-num) properties in the ID3 tag of the file. This is the standard interface that eyeD3 has always had in the past, therefore it is also the default plugin when no other is specified.,It provides a command-line tool (eyeD3) and a Python library (import eyed3) that can be used to write your own applications or plugins that are callable from the command-line tool.,Otherwise, if you want to live on the edge, you can pull down the source code from the Git repository at GitHub. The Installation page has details for how to access the source code.
$ eyeD3 - a Integrity - A "Humanity Is The Devil" - t "Hollow" - n 2 song.mp3
$ eyeD3 song.mp3 song.mp3[3.06 MB] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ID3 v2 .4: title: Hollow artist: Integrity album: Humanity Is The Devil album artist: None track: 2 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
import eyed3
audiofile = eyed3.load("song.mp3")
audiofile.tag.artist = "Token Entry"
audiofile.tag.album = "Free For All Comp LP"
audiofile.tag.album_artist = "Various Artists"
audiofile.tag.title = "The Edge"
audiofile.tag.track_num = 3
audiofile.tag.save()
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?,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:,Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.,Thanks for contributing an answer to Ask Ubuntu!
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~$
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()