class Mkv2m4v::Command

Public Class Methods

new() click to toggle source
# File lib/mkv2m4v.rb, line 8
def initialize
  parse_options
end

Public Instance Methods

run() click to toggle source
# File lib/mkv2m4v.rb, line 12
def run
  if @options[:info]
    each_file(&:print_info)
  else
    each_file(&:transcode)
  end
end

Private Instance Methods

check_dependencies_and_exit() click to toggle source
# File lib/mkv2m4v.rb, line 51
def check_dependencies_and_exit
  results = []
  results << check_dependency("mediainfo",  "--Version", "media-info", :exit_status => 255)
  results << check_dependency("MP4Box",     "-version",  "gpac")
  results << check_dependency("mkvextract", "--version", "mkvtoolnix", :requirements => "version >= 6 required")
  results << check_dependency("ffmpeg",     "-version",  "ffmpeg --with-tools")
  exit results.count(false)
end
check_dependency(command, version_arg, brew_arg, options = {}) click to toggle source
# File lib/mkv2m4v.rb, line 60
def check_dependency(command, version_arg, brew_arg, options = {})
  requirements = options.delete(:requirements)
  exit_status  = options.delete(:exit_status)

  puts "Checking #{command}...".magenta
  success = system(command, version_arg) || $?.exitstatus == exit_status
  if success
    print "  ...Installed. ".green
    puts requirements.to_s.yellow.on_black
  else
    $stderr.puts "Missing #{command}. Please `brew install #{brew_arg}`".white.on_red
  end
  success
end
each_file() { |file| ... } click to toggle source
# File lib/mkv2m4v.rb, line 22
def each_file
  Mkv2m4v::File.each(@filenames, @options) do |file|
    yield file
  end
end
parse_languages() click to toggle source
# File lib/mkv2m4v.rb, line 46
def parse_languages
  @options[:languages] =
    @options[:lang].split(/\s*,\s*/).map { |lang| Iso639[lang] }.compact
end
parse_options() click to toggle source
# File lib/mkv2m4v.rb, line 28
def parse_options
  parser = Trollop::Parser.new do
    version Mkv2m4v::VersionDescription
    banner [Mkv2m4v::Description, Mkv2m4v::Usage].join("\n")
    opt :info,  "Print media info only"
    opt :lang,  "Preferred languages, comma separated", :type => :string, :default => "English"
    opt :dir,   "Destination directory (default: same dir as source mkv)", :type => :string
    opt :check, "Check dependencies"
  end
  @options = Trollop::with_standard_exception_handling(parser) { parser.parse ARGV }
  parse_languages
  @filenames = ARGV


  check_dependencies_and_exit if @options[:check]
  parser.educate if @filenames.empty?
end