Class: DragonflyAudio::Processors::Tag

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

Constant Summary collapse

PERMISSIBLE_PROPERTIES =
Analysers::AudioProperties::TAGS

Instance Method Summary collapse

Instance Method Details

#call(content, properties) ⇒ Object

Raises:


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

def call(content, properties)
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  # stringify keys
  properties = properties.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
  properties = properties.select { |key, _| PERMISSIBLE_PROPERTIES.include?(key) }

  tempfile = Dragonfly::TempObject.new(content.tempfile)

  TagLib::FileRef.open(tempfile.path) do |file|
    return if file.null?
    properties.each { |k, v| file.tag.send("#{k}=", v) }
    file.save
  end

  content.update(tempfile)
end