youpy-scissor 0.0.10 → 0.0.11
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 +20 -5
- data/Rakefile +3 -2
- data/lib/scissor.rb +33 -3
- metadata +13 -3
data/README.rdoc
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
= Scissor
|
2
2
|
|
3
3
|
== Description
|
4
|
-
|
4
|
+
|
5
|
+
utility to chop sound files
|
6
|
+
|
7
|
+
supported file format:
|
8
|
+
|
9
|
+
* mp3
|
10
|
+
* wav
|
11
|
+
|
12
|
+
== Installation
|
5
13
|
|
6
14
|
== Requirements
|
7
15
|
|
8
16
|
* {ruby-mp3info}[http://ruby-mp3info.rubyforge.org/]
|
9
|
-
* {FFmpeg}[http://ffmpeg.mplayerhq.hu/]
|
10
|
-
* {Ecasound}[http://www.eca.cx/ecasound/]
|
11
17
|
|
12
|
-
|
18
|
+
gem install ruby-mp3info
|
19
|
+
|
20
|
+
* {RiffLib}[http://rubyforge.org/projects/riff/]
|
21
|
+
|
22
|
+
gem install riff
|
23
|
+
|
24
|
+
* {FFmpeg}[http://ffmpeg.mplayerhq.hu/]
|
25
|
+
* {Ecasound}[http://www.eca.cx/ecasound/] 2.5.0 or higher
|
13
26
|
|
14
27
|
=== Archive Installation
|
15
28
|
|
@@ -21,10 +34,12 @@ utility to chop mp3 files
|
|
21
34
|
|
22
35
|
== Features/Problems
|
23
36
|
|
37
|
+
* When you concatenate two or more files, format(sample rate, bit rate, ...) mismatch causes unexpected changes to output file.
|
38
|
+
|
24
39
|
== Synopsis
|
25
40
|
|
26
41
|
foo = Scissor.new('foo.mp3')
|
27
|
-
bar = Scissor.new('bar.
|
42
|
+
bar = Scissor.new('bar.wav')
|
28
43
|
|
29
44
|
# concat
|
30
45
|
(foo + bar).to_file('foobar.mp3')
|
data/Rakefile
CHANGED
@@ -13,11 +13,11 @@ include FileUtils
|
|
13
13
|
NAME = "scissor"
|
14
14
|
AUTHOR = "youpy"
|
15
15
|
EMAIL = "youpy@buycheapviagraonlinenow.com"
|
16
|
-
DESCRIPTION = "utility to chop
|
16
|
+
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.
|
20
|
+
VERS = "0.0.11"
|
21
21
|
|
22
22
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
23
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
@@ -58,6 +58,7 @@ spec = Gem::Specification.new do |s|
|
|
58
58
|
s.test_files = Dir["test/test_*.rb"]
|
59
59
|
|
60
60
|
s.add_dependency('ruby-mp3info')
|
61
|
+
s.add_dependency('riff')
|
61
62
|
#s.required_ruby_version = '>= 1.8.2'
|
62
63
|
|
63
64
|
s.files = %w(README.rdoc ChangeLog Rakefile) +
|
data/lib/scissor.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'mp3info'
|
2
2
|
require 'digest/md5'
|
3
3
|
require 'pathname'
|
4
|
+
require 'riff/reader'
|
4
5
|
|
5
6
|
class Scissor
|
6
7
|
class Error < StandardError; end
|
@@ -19,7 +20,7 @@ class Scissor
|
|
19
20
|
@fragments << Fragment.new(
|
20
21
|
Pathname.new(filename),
|
21
22
|
0,
|
22
|
-
|
23
|
+
SoundFile.new(filename).length)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -188,13 +189,13 @@ class Scissor
|
|
188
189
|
tmpdir = Pathname.new('/tmp/scissor-' + $$.to_s)
|
189
190
|
tmpdir.mkpath
|
190
191
|
tmpfile = tmpdir + 'tmp.wav'
|
191
|
-
cmd = %w/ecasound/
|
192
|
+
cmd = %w/ecasound -q/
|
192
193
|
|
193
194
|
begin
|
194
195
|
@fragments.each_with_index do |fragment, index|
|
195
196
|
if !index.zero? && (index % 80).zero?
|
196
197
|
run_command(cmd.join(' '))
|
197
|
-
cmd = %w/ecasound/
|
198
|
+
cmd = %w/ecasound -q/
|
198
199
|
end
|
199
200
|
|
200
201
|
fragment_tmpfile =
|
@@ -245,6 +246,35 @@ class Scissor
|
|
245
246
|
end
|
246
247
|
end
|
247
248
|
|
249
|
+
class SoundFile
|
250
|
+
SUPPORTED_FORMAT = %w/mp3 wav/
|
251
|
+
|
252
|
+
class Error < StandardError; end
|
253
|
+
class UnknownFormat < Error; end
|
254
|
+
|
255
|
+
def initialize(filename)
|
256
|
+
@filename = Pathname.new(filename)
|
257
|
+
@ext = @filename.extname.sub(/^\./, '').downcase
|
258
|
+
|
259
|
+
unless SUPPORTED_FORMAT.include?(@ext)
|
260
|
+
raise UnknownFormat
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def length
|
265
|
+
case @ext
|
266
|
+
when 'mp3'
|
267
|
+
Mp3Info.new(@filename).length
|
268
|
+
when 'wav'
|
269
|
+
riff = Riff::Reader.open(@filename ,"r")
|
270
|
+
data = riff.root_chunk['data']
|
271
|
+
fmt = riff.root_chunk['fmt ']
|
272
|
+
|
273
|
+
data.length / fmt.body.unpack('s2i2')[3].to_f
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
248
278
|
class Fragment
|
249
279
|
attr_reader :filename, :start, :duration
|
250
280
|
|
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.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youpy
|
@@ -22,7 +22,17 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: riff
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: utility to chop sound files
|
26
36
|
email: youpy@buycheapviagraonlinenow.com
|
27
37
|
executables: []
|
28
38
|
|
@@ -73,6 +83,6 @@ rubyforge_project: scissor
|
|
73
83
|
rubygems_version: 1.2.0
|
74
84
|
signing_key:
|
75
85
|
specification_version: 2
|
76
|
-
summary: utility to chop
|
86
|
+
summary: utility to chop sound files
|
77
87
|
test_files: []
|
78
88
|
|