youpy-scissor 0.0.5 → 0.0.6

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 +6 -0
  2. data/Rakefile +1 -1
  3. data/lib/scissor.rb +35 -31
  4. metadata +1 -1
data/README.rdoc CHANGED
@@ -5,6 +5,12 @@ utility to chop mp3 files
5
5
 
6
6
  == Installation
7
7
 
8
+ === Requirements
9
+ * {ruby-mp3info}[http://ruby-mp3info.rubyforge.org/]
10
+ * {FFmpeg}[http://ffmpeg.mplayerhq.hu/]
11
+ * {Ecasound}[http://www.eca.cx/ecasound/]
12
+ * {mpg123}[http://www.mpg123.de/]
13
+
8
14
  === Archive Installation
9
15
 
10
16
  rake install
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ DESCRIPTION = "utility to chop mp3 files"
17
17
  RUBYFORGE_PROJECT = "scissor"
18
18
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
19
19
  BIN_FILES = %w( )
20
- VERS = "0.0.5"
20
+ VERS = "0.0.6"
21
21
 
22
22
  REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
23
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
data/lib/scissor.rb CHANGED
@@ -6,6 +6,7 @@ include FileUtils
6
6
  class Scissor
7
7
  class Error < StandardError; end
8
8
  class CommandNotFound < Error; end
9
+ class CommandFailed < Error; end
9
10
  class FileExists < Error; end
10
11
  class EmptyFragment < Error; end
11
12
 
@@ -64,12 +65,6 @@ class Scissor
64
65
  new_mp3
65
66
  end
66
67
 
67
- def which(command)
68
- result = `which #{command}`
69
- $?.exitstatus == 0 ? result.chomp :
70
- (raise CommandNotFound.new(command + ' not found'))
71
- end
72
-
73
68
  def concat(other)
74
69
  other.fragments.each do |fragment|
75
70
  add_fragment(fragment)
@@ -112,8 +107,9 @@ class Scissor
112
107
  raise EmptyFragment
113
108
  end
114
109
 
110
+ which('ecasound')
115
111
  which('ffmpeg')
116
- which('mp3wrap')
112
+ which('mpg123')
117
113
 
118
114
  options = {
119
115
  :overwrite => false
@@ -127,37 +123,45 @@ class Scissor
127
123
  end
128
124
  end
129
125
 
130
- outfiles = []
131
- tmpdir = '/tmp/scissor-' + $$.to_s
132
- mkdir tmpdir
126
+ position = 0.0
127
+ tmpfile = '/tmp/scissor-' + $$.to_s + '.wav'
128
+ cmd = %w/ecasound/
133
129
 
134
- # slice mp3 files
135
- @fragments.each_with_index do |fragment, index|
136
- outfile = tmpdir + '/' + index.to_s + '.mp3'
137
- outfiles << outfile
138
- cmd = "ffmpeg -i \"#{fragment.filename}\" -ss #{fragment.start} -t #{fragment.duration} #{outfile}"
139
- system cmd
140
- end
130
+ begin
131
+ @fragments.each_with_index do |fragment, index|
132
+ if !index.zero? && (index % 80).zero?
133
+ run_command(cmd.join(' '))
134
+ cmd = %w/ecasound/
135
+ end
141
136
 
142
- if outfiles.size == 1
143
- mv outfiles.first, filename
144
- else
145
- # concat mp3 files
146
- outfile = tmpdir + '/concat.mp3'
147
- cmd = "mp3wrap \"#{outfile}\" #{outfiles.join(' ')}"
148
- system cmd
149
-
150
- # fix duration and rename
151
- infile = tmpdir + '/concat_MP3WRAP.mp3'
152
- cmd = "ffmpeg -i \"#{infile}\" -acodec copy \"#{filename}\""
153
- system cmd
154
- end
137
+ cmd << "-a:#{index} -i \"#{fragment.filename}\" -y:#{fragment.start} -t:#{fragment.duration} -o #{tmpfile} -y:#{position}"
138
+ position += fragment.duration
139
+ end
155
140
 
156
- rm_rf tmpdir
141
+ run_command(cmd.join(' '))
142
+
143
+ cmd = "ffmpeg -i \"#{tmpfile}\" \"#{filename}\""
144
+ run_command(cmd)
145
+ ensure
146
+ rm tmpfile
147
+ end
157
148
 
158
149
  self.class.new(filename)
159
150
  end
160
151
 
152
+ def which(command)
153
+ run_command("which #{command}")
154
+
155
+ rescue CommandFailed
156
+ raise CommandNotFound.new("#{command}: not found")
157
+ end
158
+
159
+ def run_command(cmd)
160
+ unless system(cmd)
161
+ raise CommandFailed.new(cmd)
162
+ end
163
+ end
164
+
161
165
  class Fragment
162
166
  attr_reader :filename, :start, :duration
163
167
 
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy