class StripAudio::Stripper

Public Class Methods

new(options) click to toggle source
# File lib/strip_audio/stripper.rb, line 9
def initialize options
  @@options.merge(options)

  doctor
end

Public Instance Methods

strip(video_file) click to toggle source
# File lib/strip_audio/stripper.rb, line 15
def strip video_file

  begin
    audio_file_exists?( video_file )
  rescue AudioFileAlreadyExists => e
    puts e.message
    exit
  end

  o = `ffmpeg -i '#{video_file}' -ab #{@@options[:bitrate]} -ac 2 -ar 44100 -vn '#{audio_file(video_file)}' 2>&1`
  begin
    command_output o
  rescue InvalidSourceFile => e
    puts e.message
  end
end

Private Instance Methods

audio_file(video_file) click to toggle source
# File lib/strip_audio/stripper.rb, line 58
def audio_file video_file
  "#{File.basename(video_file, ".*")}.#{@@options[:format]}"
end
audio_file_exists?(video_file) click to toggle source
# File lib/strip_audio/stripper.rb, line 52
def audio_file_exists? video_file
  if File.file?( audio_file(video_file) )
    raise AudioFileAlreadyExists, "#{audio_file(video_file)} already exists. Perhaps you stripped the file already?"
  end
end
command_output(output) click to toggle source
# File lib/strip_audio/stripper.rb, line 34
def command_output output
  case output
  when /Invalid data found/
    raise InvalidSourceFile, "Source file doesn't seem to be valid."
  end

end
doctor() click to toggle source
# File lib/strip_audio/stripper.rb, line 42
def doctor
  ffmpeg_exists?
end
ffmpeg_exists?() click to toggle source
# File lib/strip_audio/stripper.rb, line 46
def ffmpeg_exists?
  if `which ffmpeg` == ""
    raise FfmpegMissing, "ffmpeg is missing, please install and try again."  
  end
end