Class: HandBrake

Inherits:
CLIChef::Cookbook show all
Defined in:
lib/cli_chef/apps/hand_brake.rb

Instance Method Summary collapse

Methods inherited from CLIChef::Cookbook

#execute, #execute!, ingredient, #menu, method_missing, #prepare, #prepare_args, prototype, #ready?, respond_to_missing?, #run, #run!

Instance Method Details

#encode(input, output, opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cli_chef/apps/hand_brake.rb', line 17

def encode(input, output, opts = {})
  run(opts.merge(input: input, output: output)) do |line, stream, job|
    job.task_count  = line.scan(/(?<=of )\d+/).first.to_i
    job.task        = line.scan(/\d+(?= of)/).first.to_i
    job.fps         = line.scan(/\d+\.\d+(?= fps)/).first.to_f
    job.average_fps = line.scan(/(?<=avg )\d+\.\d+(?= fps)/).first.to_f
    job.eta         = line.scan(/(?<=ETA ).*?(?=\))/).first.parse_duration rescue nil
    percent         = line.scan(/\d+\.\d+(?= %)/).first.to_f
    if line.include?('Encode done!')
      percent = 100.0
    elsif job.task_count > 2 && percent > 0
      percent /= job.task_count
      percent += 50 * job.task
    end
    job.percent = percent unless percent < job.percent.to_i
  end
end

#helpObject



9
10
11
# File 'lib/cli_chef/apps/hand_brake.rb', line 9

def help
  run!(help: nil).body
end

#versionObject



13
14
15
# File 'lib/cli_chef/apps/hand_brake.rb', line 13

def version
  run!(version: nil).body.scan(/(?<=HandBrake\s)\d+\.\d+\.\d+/i).first
end