Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby-mp3info album artwork

Tags:

ruby

mp3

I have this gem working such that I can change the id3 data for a given song. However I need to also be able to add album artwork to the song. I have the artwork at a given URL. How do I go about this?

Mp3Info.open(file.path) do |mp3|
  mp3.tag.title  = title
  mp3.tag.artist = artist
end
like image 377
Mike Silvis Avatar asked May 22 '26 06:05

Mike Silvis


1 Answers

It seems ruby-mp3info only supports text frames at the moment, see here: https://github.com/moumar/ruby-mp3info/blob/v0.7.1/lib/mp3info/id3v2.rb#L319

Using taglib-ruby, it would work like this:

require 'taglib'
require 'open-uri'

picture_data = open(picture_url).read

TagLib::MPEG::File.open(file.path) do |file|
  tag = file.id3v2_tag

  pic = TagLib::ID3v2::AttachedPictureFrame.new
  pic.picture = picture_data
  pic.mime_type = "image/jpeg"
  pic.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover

  tag.add_frame(pic)
  file.save
end
like image 52
robinst Avatar answered May 23 '26 20:05

robinst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!