youpy-scissor 0.0.7 → 0.0.8
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/README.rdoc +3 -2
- data/Rakefile +1 -1
- data/lib/scissor.rb +36 -28
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -3,14 +3,15 @@
|
|
3
3
|
== Description
|
4
4
|
utility to chop mp3 files
|
5
5
|
|
6
|
-
==
|
6
|
+
== Requirements
|
7
7
|
|
8
|
-
=== Requirements
|
9
8
|
* {ruby-mp3info}[http://ruby-mp3info.rubyforge.org/]
|
10
9
|
* {FFmpeg}[http://ffmpeg.mplayerhq.hu/]
|
11
10
|
* {Ecasound}[http://www.eca.cx/ecasound/]
|
12
11
|
* {mpg123}[http://www.mpg123.de/]
|
13
12
|
|
13
|
+
== Installation
|
14
|
+
|
14
15
|
=== Archive Installation
|
15
16
|
|
16
17
|
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.
|
20
|
+
VERS = "0.0.8"
|
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
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'mp3info'
|
2
|
-
require '
|
3
|
-
|
4
|
-
include FileUtils
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'pathname'
|
5
4
|
|
6
5
|
class Scissor
|
7
6
|
class Error < StandardError; end
|
@@ -18,7 +17,7 @@ class Scissor
|
|
18
17
|
|
19
18
|
if filename
|
20
19
|
@fragments << Fragment.new(
|
21
|
-
filename,
|
20
|
+
Pathname.new(filename),
|
22
21
|
0,
|
23
22
|
Mp3Info.new(filename).length)
|
24
23
|
end
|
@@ -39,7 +38,7 @@ class Scissor
|
|
39
38
|
raise OutOfDuration
|
40
39
|
end
|
41
40
|
|
42
|
-
|
41
|
+
new_instance = self.class.new
|
43
42
|
remain = length
|
44
43
|
|
45
44
|
@fragments.each do |fragment|
|
@@ -50,7 +49,7 @@ class Scissor
|
|
50
49
|
end
|
51
50
|
|
52
51
|
if (start + remain) <= fragment.duration
|
53
|
-
|
52
|
+
new_instance.add_fragment(Fragment.new(
|
54
53
|
fragment.filename,
|
55
54
|
fragment.start + start,
|
56
55
|
remain))
|
@@ -58,7 +57,7 @@ class Scissor
|
|
58
57
|
break
|
59
58
|
else
|
60
59
|
remain = remain - (fragment.duration - start)
|
61
|
-
|
60
|
+
new_instance.add_fragment(Fragment.new(
|
62
61
|
fragment.filename,
|
63
62
|
fragment.start + start,
|
64
63
|
fragment.duration - start))
|
@@ -67,7 +66,7 @@ class Scissor
|
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
70
|
-
|
69
|
+
new_instance
|
71
70
|
end
|
72
71
|
|
73
72
|
def concat(other)
|
@@ -113,24 +112,24 @@ class Scissor
|
|
113
112
|
end
|
114
113
|
|
115
114
|
remain = filled_duration
|
116
|
-
|
115
|
+
new_instance = self.class.new
|
117
116
|
|
118
|
-
while filled_duration >
|
117
|
+
while filled_duration > new_instance.duration
|
119
118
|
if remain < duration
|
120
119
|
added = slice(0, remain)
|
121
120
|
else
|
122
121
|
added = self
|
123
122
|
end
|
124
123
|
|
125
|
-
|
124
|
+
new_instance += added
|
126
125
|
remain -= added.duration
|
127
126
|
end
|
128
127
|
|
129
|
-
|
128
|
+
new_instance
|
130
129
|
end
|
131
130
|
|
132
131
|
def replace(start, duration, replaced)
|
133
|
-
|
132
|
+
new_instance = self.class.new
|
134
133
|
offset = start + duration
|
135
134
|
|
136
135
|
if offset > self.duration
|
@@ -138,13 +137,13 @@ class Scissor
|
|
138
137
|
end
|
139
138
|
|
140
139
|
if start > 0
|
141
|
-
|
140
|
+
new_instance += slice(0, start)
|
142
141
|
end
|
143
142
|
|
144
|
-
|
145
|
-
|
143
|
+
new_instance += replaced
|
144
|
+
new_instance += slice(offset, self.duration - offset)
|
146
145
|
|
147
|
-
|
146
|
+
new_instance
|
148
147
|
end
|
149
148
|
|
150
149
|
def to_file(filename, options = {})
|
@@ -160,35 +159,44 @@ class Scissor
|
|
160
159
|
:overwrite => false
|
161
160
|
}.merge(options)
|
162
161
|
|
163
|
-
|
162
|
+
filename = Pathname.new(filename)
|
163
|
+
|
164
|
+
if filename.exist?
|
164
165
|
if options[:overwrite]
|
165
|
-
|
166
|
+
filename.unlink
|
166
167
|
else
|
167
168
|
raise FileExists
|
168
169
|
end
|
169
170
|
end
|
170
171
|
|
171
172
|
position = 0.0
|
172
|
-
|
173
|
+
tmpdir = Pathname.new('/tmp/scissor-' + $$.to_s)
|
174
|
+
tmpdir.mkpath
|
175
|
+
tmpfile = tmpdir + 'tmp.wav'
|
173
176
|
cmd = %w/ecasound/
|
174
177
|
|
175
178
|
begin
|
176
179
|
@fragments.each_with_index do |fragment, index|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
+
fragment_tmpfile =
|
181
|
+
tmpdir + (Digest::MD5.hexdigest(fragment.filename) + '.wav')
|
182
|
+
|
183
|
+
unless fragment_tmpfile.exist?
|
184
|
+
run_command("ffmpeg -i \"#{fragment.filename}\" \"#{fragment_tmpfile}\"")
|
180
185
|
end
|
181
186
|
|
182
|
-
cmd <<
|
187
|
+
cmd <<
|
188
|
+
"-a:#{index} " +
|
189
|
+
"-i:select,#{fragment.start},#{fragment.duration},\"#{fragment_tmpfile}\" " +
|
190
|
+
"-o #{tmpfile} " +
|
191
|
+
"-y:#{position}"
|
192
|
+
|
183
193
|
position += fragment.duration
|
184
194
|
end
|
185
195
|
|
186
196
|
run_command(cmd.join(' '))
|
187
|
-
|
188
|
-
cmd = "ffmpeg -i \"#{tmpfile}\" \"#{filename}\""
|
189
|
-
run_command(cmd)
|
197
|
+
run_command("ffmpeg -i \"#{tmpfile}\" \"#{filename}\"")
|
190
198
|
ensure
|
191
|
-
|
199
|
+
tmpdir.rmtree
|
192
200
|
end
|
193
201
|
|
194
202
|
self.class.new(filename)
|