Class: DragonflyAudio::Processors::AlbumArt

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_audio/processors/album_art.rb

Instance Method Summary collapse

Instance Method Details

#call(content, album_art_file) ⇒ Object

Raises:


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dragonfly_audio/processors/album_art.rb', line 9

def call(content, album_art_file)
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
  # raise UnsupportedFormat unless content.mime_type == 'audio/mpeg'

  tempfile = content.temp_object

  TagLib::MPEG::File.open(tempfile.path) do |file|
    tag = file.id3v2_tag
    album_art = TagLib::ID3v2::AttachedPictureFrame.new
    album_art.mime_type = Rack::Mime.mime_type(File.extname(album_art_file))
    album_art.description = "Cover"
    album_art.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
    album_art.picture = File.open(album_art_file, 'rb') { |f| f.read }
    tag.add_frame(album_art)
    file.save
  end

  content.update(tempfile)
end