youpy-scissor 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +0 -8
  2. data/Rakefile +2 -1
  3. data/lib/scissor.rb +30 -9
  4. metadata +12 -2
data/README.rdoc CHANGED
@@ -13,14 +13,6 @@ supported file format:
13
13
 
14
14
  === Requirements
15
15
 
16
- * {ruby-mp3info}[http://ruby-mp3info.rubyforge.org/]
17
-
18
- gem install ruby-mp3info
19
-
20
- * {RiffLib}[http://rubyforge.org/projects/riff/]
21
-
22
- gem install riff
23
-
24
16
  * {FFmpeg}[http://ffmpeg.mplayerhq.hu/]
25
17
  * {Ecasound}[http://www.eca.cx/ecasound/] 2.5.0 or higher
26
18
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ DESCRIPTION = "utility to chop sound files"
17
17
  RUBYFORGE_PROJECT = "scissor"
18
18
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
19
19
  BIN_FILES = %w( )
20
- VERS = "0.0.12"
20
+ VERS = "0.0.13"
21
21
 
22
22
  REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
23
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
@@ -57,6 +57,7 @@ spec = Gem::Specification.new do |s|
57
57
  s.homepage = HOMEPATH
58
58
  s.test_files = Dir["test/test_*.rb"]
59
59
 
60
+ s.add_dependency('open4')
60
61
  s.add_dependency('ruby-mp3info')
61
62
  s.add_dependency('riff')
62
63
  #s.required_ruby_version = '>= 1.8.2'
data/lib/scissor.rb CHANGED
@@ -2,19 +2,23 @@ require 'mp3info'
2
2
  require 'digest/md5'
3
3
  require 'pathname'
4
4
  require 'riff/reader'
5
+ require 'open4'
6
+ require 'logger'
5
7
 
6
8
  class Scissor
7
9
  class Error < StandardError; end
8
- class CommandNotFound < Error; end
9
- class CommandFailed < Error; end
10
10
  class FileExists < Error; end
11
11
  class EmptyFragment < Error; end
12
12
  class OutOfDuration < Error; end
13
+ class CommandFailed < Error; end
13
14
 
14
15
  attr_reader :fragments
16
+ attr_accessor :logger
15
17
 
16
18
  def initialize(filename = nil)
17
19
  @fragments = []
20
+ @logger = Logger.new(STDOUT)
21
+ @logger.level = Logger::INFO
18
22
 
19
23
  if filename
20
24
  @fragments << Fragment.new(
@@ -164,6 +168,8 @@ class Scissor
164
168
  end
165
169
 
166
170
  def to_file(filename, options = {})
171
+ filename = Pathname.new(filename)
172
+
167
173
  if @fragments.empty?
168
174
  raise EmptyFragment
169
175
  end
@@ -189,16 +195,17 @@ class Scissor
189
195
  tmpdir = Pathname.new('/tmp/scissor-' + $$.to_s)
190
196
  tmpdir.mkpath
191
197
  tmpfile = tmpdir + 'tmp.wav'
192
- cmd = %w/ecasound -q/
198
+ cmd = %w/ecasound/
193
199
 
194
200
  begin
195
201
  @fragments.each_with_index do |fragment, index|
196
202
  if !index.zero? && (index % 80).zero?
197
203
  run_command(cmd.join(' '))
198
- cmd = %w/ecasound -q/
204
+ cmd = %w/ecasound/
199
205
  end
200
206
 
201
207
  fragment_tmpfile =
208
+ fragment.filename.extname.downcase == '.wav' ? fragment.filename :
202
209
  tmpdir + (Digest::MD5.hexdigest(fragment.filename) + '.wav')
203
210
 
204
211
  unless fragment_tmpfile.exist?
@@ -217,7 +224,14 @@ class Scissor
217
224
  end
218
225
 
219
226
  run_command(cmd.join(' '))
220
- run_command("ffmpeg -i \"#{tmpfile}\" \"#{filename}\"")
227
+
228
+ if filename.extname == '.wav'
229
+ open(filename, 'w') do |file|
230
+ file.write(tmpfile.read)
231
+ end
232
+ else
233
+ run_command("ffmpeg -i \"#{tmpfile}\" \"#{filename}\"")
234
+ end
221
235
  ensure
222
236
  tmpdir.rmtree
223
237
  end
@@ -229,15 +243,22 @@ class Scissor
229
243
 
230
244
  def which(command)
231
245
  run_command("which #{command}")
232
-
233
- rescue CommandFailed
234
- raise CommandNotFound.new("#{command}: not found")
235
246
  end
236
247
 
237
248
  def run_command(cmd)
238
- unless system(cmd)
249
+ @logger.debug("run_command: #{cmd}")
250
+
251
+ result = ''
252
+ status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
253
+ @logger.debug(stderr.read)
254
+ result = stdout.read
255
+ end
256
+
257
+ if status.exitstatus != 0
239
258
  raise CommandFailed.new(cmd)
240
259
  end
260
+
261
+ return result
241
262
  end
242
263
 
243
264
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youpy-scissor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-05 00:00:00 -07:00
12
+ date: 2009-04-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: open4
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: ruby-mp3info
17
27
  type: :runtime