youpy-scissor 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +3 -0
  2. data/Rakefile +2 -2
  3. data/data/silence.mp3 +0 -0
  4. data/lib/scissor.rb +56 -1
  5. metadata +3 -2
data/README.rdoc CHANGED
@@ -38,6 +38,9 @@ utility to chop mp3 files
38
38
  # split
39
39
  (Scissor.new('sequence.mp3') / 16).first.to_file('split.mp3')
40
40
 
41
+ # replace first 10 seconds with 30 seconds of silence
42
+ foo.replace(0, 10, Scissor.silence(30)).to_file('replace.mp3')
43
+
41
44
  == Copyright
42
45
 
43
46
  Author:: youpy <youpy@buycheapviagraonlinenow.com>
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.6"
20
+ VERS = "0.0.7"
21
21
 
22
22
  REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
23
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
@@ -61,7 +61,7 @@ spec = Gem::Specification.new do |s|
61
61
  #s.required_ruby_version = '>= 1.8.2'
62
62
 
63
63
  s.files = %w(README.rdoc ChangeLog Rakefile) +
64
- Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
64
+ Dir.glob("{bin,doc,test,lib,data,templates,generator,extras,website,script}/**/*") +
65
65
  Dir.glob("ext/**/*.{h,c,rb}") +
66
66
  Dir.glob("examples/**/*.rb") +
67
67
  Dir.glob("tools/*.rb")
data/data/silence.mp3 ADDED
Binary file
data/lib/scissor.rb CHANGED
@@ -9,6 +9,7 @@ class Scissor
9
9
  class CommandFailed < Error; end
10
10
  class FileExists < Error; end
11
11
  class EmptyFragment < Error; end
12
+ class OutOfDuration < Error; end
12
13
 
13
14
  attr_reader :fragments
14
15
 
@@ -34,7 +35,11 @@ class Scissor
34
35
  end
35
36
 
36
37
  def slice(start, length)
37
- new_mp3 = self.class.new()
38
+ if start + length > duration
39
+ raise OutOfDuration
40
+ end
41
+
42
+ new_mp3 = self.class.new
38
43
  remain = length
39
44
 
40
45
  @fragments.each do |fragment|
@@ -102,6 +107,46 @@ class Scissor
102
107
 
103
108
  alias / split
104
109
 
110
+ def fill(filled_duration)
111
+ if @fragments.empty?
112
+ raise EmptyFragment
113
+ end
114
+
115
+ remain = filled_duration
116
+ new_mp3 = self.class.new
117
+
118
+ while filled_duration > new_mp3.duration
119
+ if remain < duration
120
+ added = slice(0, remain)
121
+ else
122
+ added = self
123
+ end
124
+
125
+ new_mp3 += added
126
+ remain -= added.duration
127
+ end
128
+
129
+ new_mp3
130
+ end
131
+
132
+ def replace(start, duration, replaced)
133
+ new_mp3 = self.class.new
134
+ offset = start + duration
135
+
136
+ if offset > self.duration
137
+ raise OutOfDuration
138
+ end
139
+
140
+ if start > 0
141
+ new_mp3 += slice(0, start)
142
+ end
143
+
144
+ new_mp3 += replaced
145
+ new_mp3 += slice(offset, self.duration - offset)
146
+
147
+ new_mp3
148
+ end
149
+
105
150
  def to_file(filename, options = {})
106
151
  if @fragments.empty?
107
152
  raise EmptyFragment
@@ -162,6 +207,14 @@ class Scissor
162
207
  end
163
208
  end
164
209
 
210
+ class << self
211
+ def silence(duration)
212
+ new(File.dirname(__FILE__) + '/../data/silence.mp3').
213
+ slice(0, 1).
214
+ fill(duration)
215
+ end
216
+ end
217
+
165
218
  class Fragment
166
219
  attr_reader :filename, :start, :duration
167
220
 
@@ -169,6 +222,8 @@ class Scissor
169
222
  @filename = filename
170
223
  @start = start
171
224
  @duration = duration
225
+
226
+ freeze
172
227
  end
173
228
  end
174
229
  end
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-04 00:00:00 -07:00
12
+ date: 2009-04-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,6 +36,7 @@ files:
36
36
  - ChangeLog
37
37
  - Rakefile
38
38
  - lib/scissor.rb
39
+ - data/silence.mp3
39
40
  has_rdoc: true
40
41
  homepage: http://scissor.rubyforge.org
41
42
  post_install_message: