hb-runner 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/hb-info ADDED
@@ -0,0 +1,23 @@
1
+ #! /usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'open4'
4
+
5
+ if ARGV.empty?
6
+ puts
7
+ puts 'Usage: hb-info PATH_TO_VIDEO'
8
+ puts 'Provide the path to your input file, and it will be scanned with the HandBrakeCLI.'
9
+ puts
10
+ puts 'The HandBrakeCLI executable should be in your path.'
11
+ 3.times { puts }
12
+ else
13
+ source = File.expand_path(ARGV.first)
14
+
15
+ command = "HandBrakeCLI --title 0 --input #{ source.inspect }"
16
+ error = ''
17
+
18
+ Open4.spawn command, :stderr => error
19
+
20
+ puts error
21
+ error
22
+ end
23
+
data/bin/hb-runner CHANGED
@@ -3,20 +3,19 @@ require File.dirname(__FILE__) + '/../lib/hb-runner'
3
3
 
4
4
  if ARGV.empty?
5
5
  puts
6
- puts 'Usage: hb-runner PATH OPTIONS_FILE_NAME QUEUE_FILE_NAME'
6
+ puts 'Usage: hb-runner OPTIONS_FILE_NAME QUEUE_FILE_NAME'
7
7
  puts 'the path sets the base path for both files. Both the OPTIONS and QUEUE files are expected in that path.'
8
8
  puts
9
9
  puts 'Also, the HandBrakeCLI executable should be in your path.'
10
10
  3.times { puts }
11
11
  else
12
- path, options_file, queue_file = ARGV
12
+ config_filename, queue_filename = ARGV
13
13
 
14
14
  path ||= File.expand_path File.dirname(__FILE__)
15
15
  options_file ||= 'hb_config.yml'
16
16
  queue_file ||= 'hb_queue.yml'
17
17
 
18
- options = HBConfig.new :path => path, :file => options_file
19
- queue = HBQueue.new :path => path, :file => queue_file, :options => options
20
-
18
+ options = HBConfig.new :file => config_filename
19
+ queue = HBQueue.new :file => queue_filename, :options => options
21
20
  queue.run
22
21
  end
@@ -2,20 +2,35 @@
2
2
  # and can return it as a properly formatted string
3
3
  #
4
4
  class HBConfig < YAMLConfig
5
-
6
5
  attr_accessor :options
7
6
 
8
7
  def read
9
- if data['video'].keys.include?('x264opts')
10
- data['video']['x264opts'] = data['video']['x264opts'].map {|k,v| "#{k}=#{v}"}.join(':')
8
+ @data ||= open(filename) { |f| YAML.load f }
9
+
10
+ if @data['video'].keys.include?('x264opts')
11
+ @data['video']['x264opts'] = @data['video']['x264opts'].map {|k,v| "#{k}=#{v}"}.join(':')
11
12
  end
12
13
 
13
- @options = data
14
+ loose_anamorphic = @data['video'].delete 'loose-anamorphic'
15
+ @anamorphic_options = if loose_anamorphic and loose_anamorphic == true
16
+ ' -loose-anamorphic'
17
+ elsif loose_anamorphic
18
+ " -loosePixelratio=#{ loose_anamorphic }"
19
+ else
20
+ ''
21
+ end
22
+
23
+ @options = @data
14
24
  self.to_s
15
25
  end
16
26
 
27
+
17
28
  def to_s
18
- @options.map {|o| o.last.map { |k,v| "--#{k} #{v.inspect}" }.join(' ') }.join.gsub('true', '')
29
+ @options.map do |o|
30
+ o.last.map do |k,v|
31
+ "--#{k} #{v.inspect}"
32
+ end.join(' ')
33
+ end.join(' ').gsub('true', '') + @anamorphic_options
19
34
  end
20
35
 
21
36
  end
@@ -4,30 +4,37 @@
4
4
  class HBQueue < YAMLConfig
5
5
  attr_accessor :queue
6
6
 
7
+ def executable
8
+ '/Volumes/Scratch/hb/HandBrakeCLI'
9
+ end
10
+
7
11
  def read
8
- @queue = data
9
- "#{@queue.size} item(s) in the queue."
12
+ @queue ||= open(filename) { |f| YAML.load f }
13
+ puts "#{queue.size} item(s) in the queue."
10
14
  end
11
15
 
12
16
  def run
13
- queue.each do |item|
17
+ queue.each do |q|
18
+ q['input'] = File.expand_path(q['input']) if q['input']
19
+ q['output'] = File.expand_path(q['output']) if q['output']
20
+
21
+ markers = q.delete 'markers'
22
+ marker_options = if markers and markers == true
23
+ ' --markers'
24
+ else
25
+ " --markers=#{ markers }"
26
+ end
14
27
 
15
- item_options = {
16
- :input => File.expand_path(File.join(path, item['input'])),
17
- :output => File.expand_path(File.join(path, item['output'])),
18
- :chapters => item['chapters']
19
- }.map {|k,v| "--#{k} #{v.inspect}" }.join(' ')
28
+ item_options = q.map { |k,v| "--#{k} #{v.inspect}" }.join(' ').gsub('true', '') + marker_options
20
29
 
21
- execute "HandBrakeCLI #{item_options} #{@options}"
30
+ execute "#{executable} #{item_options} #{@options}"
22
31
  end
23
32
  end
24
33
 
25
34
  private
26
35
 
27
36
  def execute command
28
- 5.times { puts }
29
- puts 'Starting!'
30
- puts
37
+ puts "\nExecuting:\n\n#{ command }\n\n"
31
38
 
32
39
  IO.popen(command) do |output|
33
40
  begin
@@ -37,7 +44,7 @@ private
37
44
  end
38
45
  end
39
46
 
40
- 5.times { puts }
47
+ 10.times { puts }
41
48
  end
42
49
 
43
50
  end
@@ -4,23 +4,14 @@ require 'yaml'
4
4
  # for both HBQueue and HBConfig
5
5
  #
6
6
  class YAMLConfig
7
- attr_accessor :path, :file
7
+ attr_accessor :file
8
8
 
9
- def initialize options = {}
9
+ def initialize options = {}
10
10
  options.each { |k,v| instance_variable_set "@#{k}", v }
11
- read
11
+ read if @file
12
12
  end
13
13
 
14
- def filename() File.join path, file end
15
-
16
- def data
17
- unless File.exist?(filename)
18
- puts "Unable to open #{self.class.name} file #{filename}!"
19
- Process.exit
20
- end
21
-
22
- open(filename) { |f| YAML.load f }
23
- end
14
+ def filename() File.expand_path file end
24
15
 
25
16
  def read() raise 'Override!' end
26
17
  def to_s() raise 'Override!' end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hb-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-05 00:00:00 -07:00
12
+ date: 2010-01-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -17,6 +17,7 @@ description:
17
17
  email:
18
18
  executables:
19
19
  - hb-runner
20
+ - hb-info
20
21
  extensions: []
21
22
 
22
23
  extra_rdoc_files: