Class: Flacky::Mp3Convertor

Inherits:
Object
  • Object
show all
Defined in:
lib/flacky/mp3_convertor.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Mp3Convertor

Returns a new instance of Mp3Convertor.



7
8
9
10
# File 'lib/flacky/mp3_convertor.rb', line 7

def initialize(opts = {})
  @lame_opts = opts[:lame_opts]
  @dest_root = opts[:dest_root]
end

Instance Method Details

#convert_file!(file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flacky/mp3_convertor.rb', line 12

def convert_file!(file)
  dst = file.sub(/\.flac$/, ".mp3")
  if dest_root
    dst = File.join(dest_root, dst)
    FileUtils.mkdir_p File.dirname(dst)
  end

  cmd = %{flac -dcs "#{file}" | lame #{lame_opts}}
  tags.each { |lt, ft| cmd << %{ --#{lt} "#{tag(file, ft)}"} }
  cmd << %{ - "#{dst}"}

  elapsed = Benchmark.measure do ; %x{#{cmd}} ; end
  Response.new(dst, elapsed.real)
end