kastner-kompress 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/kompress.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "kompress"
3
- s.version = "0.0.3"
3
+ s.version = "0.0.4"
4
4
  s.date = "2008-09-14"
5
5
  s.summary = "Kompress - kompress videos and see progress"
6
6
  s.email = "kastner@gmail.com"
7
7
  s.homepage = "http://github.com/kastner/kompress.git"
8
8
  s.description = "Kompress - kompress videos and see progress"
9
9
  s.has_rdoc = false
10
- s.require_path = '.'
10
+ s.require_paths = ["lib"]
11
11
  s.authors = ["Erik Kastner"]
12
12
  s.files = ["kompress.gemspec", "lib/kompress", "lib/kompress/compress.rb",
13
13
  "lib/kompress/config.rb", "lib/kompress/exceptions.rb", "lib/kompress/job.rb",
data/lib/kompress/job.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Kompress
2
2
  class Job
3
- attr_accessor :options, :job_id, :input_file, :container_type, :start_time
3
+ attr_accessor :options, :job_id, :input_file, :container_type, :start_time, :thumb_type
4
4
  attr_accessor :state
5
5
 
6
6
  def self.from_file(file)
@@ -18,19 +18,20 @@ module Kompress
18
18
  job
19
19
  end
20
20
 
21
- def self.from_preset(preset, input_file, container_type = "mp4")
21
+ def self.from_preset(preset, input_file, container_type = "mp4", thumb_type = "jpg")
22
22
  config_preset = Kompress::Config.presets[preset]
23
23
  raise Kompress::NoConfigurationError unless config_preset
24
24
 
25
25
  job = new
26
- job.fill(preset, config_preset.command, input_file, container_type, config_preset.options)
26
+ job.fill(preset, config_preset.command, input_file, container_type, thumb_type, config_preset.options)
27
27
  job
28
28
  end
29
29
 
30
- def fill(name, command, input_file, container_type, options)
30
+ def fill(name, command, input_file, container_type, thumb_type, options)
31
31
  @start_time = Time.now
32
32
  @state = :pending
33
33
  @options, @input_file, @command = options, input_file, command
34
+ @thumb_type = thumb_type
34
35
  @container_type = container_type
35
36
  @job_id = Time.now.to_i.to_s + "-" + name.to_s
36
37
  end
@@ -44,6 +45,7 @@ module Kompress
44
45
  rpl = {}
45
46
  rpl[:job_id] = @job_id
46
47
  rpl[:container_type] = @container_type
48
+ rpl[:thumb_type] = @thumb_type
47
49
  rpl[:input_file] = @input_file
48
50
  rpl[:start_time] = @start_time
49
51
  rpl.merge(kc_replacements)
@@ -57,12 +59,20 @@ module Kompress
57
59
  substitute(options[:post_command], replacements)
58
60
  end
59
61
 
62
+ def file_type_regexp
63
+ /\.(mov|avi|mp4|flv|wmv|mpg|mpeg|mpg|divx)/i
64
+ end
65
+
60
66
  def temp_file
61
- input_file.gsub(/\.(mov|avi|mp4|flv|wmv)$/, ".tmp.#{container_type}")
67
+ input_file.gsub(file_type_regexp, ".tmp.#{container_type}")
62
68
  end
63
69
 
64
70
  def output_file
65
- input_file.gsub(/\.(mov|avi|mp4|flv|wmv)$/, ".#{container_type}")
71
+ input_file.gsub(file_type_regexp, ".#{container_type}")
72
+ end
73
+
74
+ def thumb_file
75
+ input_file.gsub(file_type_regexp, ".#{thumb_type}")
66
76
  end
67
77
 
68
78
  def substitute(string, subs)
@@ -93,7 +103,7 @@ module Kompress
93
103
  end
94
104
 
95
105
  def frame_rate
96
- @frame_rate ||= status_contents[@options[:frame_rate_regexp], 1].to_f
106
+ @frame_rate ||= status_contents[@options[:frame_rate_regexp], 1].to_f.ceil
97
107
  end
98
108
 
99
109
  def duration
@@ -109,7 +119,7 @@ module Kompress
109
119
  end
110
120
 
111
121
  def total_frames
112
- duration * frame_rate
122
+ (duration * frame_rate).to_i
113
123
  end
114
124
 
115
125
  def current_frame
@@ -125,7 +135,7 @@ module Kompress
125
135
  end
126
136
 
127
137
  def finalize
128
- system(post_command) if post_command
138
+ `#{post_command}` if post_command
129
139
  cleanup
130
140
  end
131
141
 
@@ -146,7 +156,7 @@ module Kompress
146
156
  @state = :running
147
157
  write_state_to_disk
148
158
  Thread.new do
149
- system command
159
+ `#{command}`
150
160
  end
151
161
 
152
162
  while (!File.exists?(status_file)); sleep 0.2; end
data/test/job_test.rb CHANGED
@@ -25,6 +25,18 @@ describe "Kompress::Job" do
25
25
  it "should set a status file" do
26
26
  @job.status_file.should == "/t/kompress-#{@job.job_id}"
27
27
  end
28
+
29
+ it "should have a thumb file" do
30
+ @job.input_file = "bob.mpg"
31
+ @job.thumb_file.should == "bob.jpg"
32
+ end
33
+
34
+ %w|mov wmv avi mp4 mpg mpeg MOV divx|.each do |type|
35
+ it "should replace .#{type} with .tmp.mp4" do
36
+ @job.input_file = "x.#{type}"
37
+ @job.temp_file.should == "x.tmp.mp4"
38
+ end
39
+ end
28
40
  end
29
41
 
30
42
  describe "A fake job" do
@@ -50,7 +62,8 @@ describe "A real job" do
50
62
  k.setting :qt_faststart => "/usr/bin/qt-faststart"
51
63
 
52
64
  k.preset :rad => {
53
- :command => %Q{:ffmpeg -y -i :input_file :temp_file 2>> :status_file ; echo done > :done_file},
65
+ :command => %Q{:ffmpeg -y -i :input_file :temp_file 640x:width 2>> :status_file ; echo done > :done_file},
66
+ :width => 480,
54
67
  :post_command => %Q{:qt_faststart :temp_file :output_file},
55
68
  :frame_rate_regexp => /0.0,,,,,Video,.*q=.*,([\d\.]+)$/,
56
69
  :duration_regexp => /Duration-(\d+)/,
@@ -69,7 +82,8 @@ describe "A real job" do
69
82
  end
70
83
 
71
84
  it "should know frame rate" do
72
- @job.frame_rate.should == 44.92
85
+ # @job.frame_rate.should == 44.92
86
+ @job.frame_rate.should == 45
73
87
  end
74
88
 
75
89
  it "should know duration" do
@@ -77,7 +91,7 @@ describe "A real job" do
77
91
  end
78
92
 
79
93
  it "should know total frames" do
80
- @job.total_frames.should == 269.52
94
+ @job.total_frames.should == 270
81
95
  end
82
96
 
83
97
  it "should know it's current frame #" do
@@ -88,6 +102,16 @@ describe "A real job" do
88
102
  it "should have a start time" do
89
103
  @job.start_time.should.be.kind_of Time
90
104
  end
105
+
106
+ it "should substitute fields without spaces" do
107
+ @job.command.should =~ /640x480/
108
+ end
109
+
110
+ it "should be changable" do
111
+ @job.options[:width] = 300
112
+ @job.command.should =~ /640x300/
113
+ @job.command.should.not =~ /640x480/
114
+ end
91
115
  end
92
116
 
93
117
  describe "A frozen job" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kastner-kompress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Kastner
@@ -42,7 +42,7 @@ rdoc_options:
42
42
  - --main
43
43
  - README.mkdn
44
44
  require_paths:
45
- - .
45
+ - lib
46
46
  required_ruby_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="