Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* add Scissor#replace

 * update rdoc
 * version 0.0.7
  • Loading branch information...
commit 0b5aae806b0a605650e876601ef9ca8c2501dd52 1 parent 5679a3b
@youpy authored
View
3  README.rdoc
@@ -38,6 +38,9 @@ utility to chop mp3 files
# split
(Scissor.new('sequence.mp3') / 16).first.to_file('split.mp3')
+ # replace first 10 seconds with 30 seconds of silence
+ foo.replace(0, 10, Scissor.silence(30)).to_file('replace.mp3')
+
== Copyright
Author:: youpy <youpy@buycheapviagraonlinenow.com>
View
2  Rakefile
@@ -17,7 +17,7 @@ DESCRIPTION = "utility to chop mp3 files"
RUBYFORGE_PROJECT = "scissor"
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
BIN_FILES = %w( )
-VERS = "0.0.6"
+VERS = "0.0.7"
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
View
BIN  data/silence.mp3
Binary file not shown
View
29 lib/scissor.rb
@@ -9,6 +9,7 @@ class CommandNotFound < Error; end
class CommandFailed < Error; end
class FileExists < Error; end
class EmptyFragment < Error; end
+ class OutOfDuration < Error; end
attr_reader :fragments
@@ -34,6 +35,10 @@ def duration
end
def slice(start, length)
+ if start + length > duration
+ raise OutOfDuration
+ end
+
new_mp3 = self.class.new
remain = length
@@ -124,6 +129,24 @@ def fill(filled_duration)
new_mp3
end
+ def replace(start, duration, replaced)
+ new_mp3 = self.class.new
+ offset = start + duration
+
+ if offset > self.duration
+ raise OutOfDuration
+ end
+
+ if start > 0
+ new_mp3 += slice(0, start)
+ end
+
+ new_mp3 += replaced
+ new_mp3 += slice(offset, self.duration - offset)
+
+ new_mp3
+ end
+
def to_file(filename, options = {})
if @fragments.empty?
raise EmptyFragment
@@ -186,7 +209,9 @@ def run_command(cmd)
class << self
def silence(duration)
- new(File.dirname(__FILE__) + '/../data/silence.mp3').fill(duration)
+ new(File.dirname(__FILE__) + '/../data/silence.mp3').
+ slice(0, 1).
+ fill(duration)
end
end
@@ -197,6 +222,8 @@ def initialize(filename, start, duration)
@filename = filename
@start = start
@duration = duration
+
+ freeze
end
end
end
View
6 scissor.gemspec
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = %q{scissor}
- s.version = "0.0.6"
+ s.version = "0.0.7"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["youpy"]
- s.date = %q{2009-04-04}
+ s.date = %q{2009-04-05}
s.description = %q{utility to chop mp3 files}
s.email = %q{youpy@buycheapviagraonlinenow.com}
s.extra_rdoc_files = ["README.rdoc", "ChangeLog"]
- s.files = ["README.rdoc", "ChangeLog", "Rakefile", "lib/scissor.rb"]
+ s.files = ["README.rdoc", "ChangeLog", "Rakefile", "lib/scissor.rb", "data/silence.mp3"]
s.has_rdoc = true
s.homepage = %q{http://scissor.rubyforge.org}
s.rdoc_options = ["--title", "scissor documentation", "--charset", "utf-8", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source", "--exclude", "^(examples|extras)/"]
View
26 spec/scissor_spec.rb
@@ -26,6 +26,12 @@
@mp3.slice(150, 20).duration.should eql(20)
end
+ it "should raise error if sliced range is out of duration" do
+ lambda {
+ @mp3.slice(0, 179)
+ }.should raise_error(Scissor::OutOfDuration)
+ end
+
it "should concatenate" do
new_mp3 = @mp3.slice(0, 120).concat(@mp3.slice(150, 20))
new_mp3.duration.should eql(140)
@@ -38,7 +44,7 @@
it "should concat silence" do
new_mp3 = @mp3.slice(0, 12).concat(Scissor.silence(3))
- new_mp3.duration.to_s.should eql('15.0')
+ new_mp3.duration.should eql(15)
end
it "should slice concatenated one" do
@@ -100,6 +106,24 @@
new_mp3.fragments[3].duration.should eql(1)
end
+ it "should replace" do
+ new_mp3 = @mp3.slice(0, 100).replace(60, 30, @mp3.slice(0, 60))
+ new_mp3.duration.should eql(130)
+ new_mp3.fragments.size.should eql(3)
+ new_mp3.fragments[0].start.should eql(0)
+ new_mp3.fragments[0].duration.should eql(60)
+ new_mp3.fragments[1].start.should eql(0)
+ new_mp3.fragments[1].duration.should eql(60)
+ new_mp3.fragments[2].start.should eql(90)
+ new_mp3.fragments[2].duration.should eql(10)
+ end
+
+ it "should raise error if replaced range is out of duration" do
+ lambda {
+ @mp3.slice(0, 100).replace(60, 41, @mp3.slice(0, 60))
+ }.should raise_error(Scissor::OutOfDuration)
+ end
+
it "should write to file and return new instance of Scissor" do
new_mp3 = @mp3.slice(0, 120) + @mp3.slice(150, 20)
result = new_mp3.to_file('/tmp/scissor-test/out.mp3')
Please sign in to comment.
Something went wrong with that request. Please try again.