youpy-scissor 0.0.2 → 0.0.3

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 +1 -1
  2. data/Rakefile +1 -1
  3. data/lib/scissor.rb +38 -11
  4. metadata +1 -1
data/README.rdoc CHANGED
@@ -30,7 +30,7 @@ utility to chop mp3 files
30
30
  ((foo.slice(10, 1) + bar.slice(2, 3)) * 4).to_file('slicefoobarloop.mp3')
31
31
 
32
32
  # split
33
- (Scissor.new('sequence.mp3') / 16).to_file('split.mp3')
33
+ (Scissor.new('sequence.mp3') / 16).first.to_file('split.mp3')
34
34
 
35
35
  == Copyright
36
36
 
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.2"
20
+ VERS = "0.0.3"
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,13 +6,12 @@ include FileUtils
6
6
  class Scissor
7
7
  class Error < StandardError; end
8
8
  class CommandNotFound < Error; end
9
+ class FileExists < Error; end
10
+ class EmptyFragment < Error; end
9
11
 
10
12
  attr_reader :fragments
11
13
 
12
14
  def initialize(filename = nil)
13
- which('ffmpeg')
14
- which('mp3wrap')
15
-
16
15
  @fragments = []
17
16
 
18
17
  if filename
@@ -96,13 +95,32 @@ class Scissor
96
95
  results = []
97
96
 
98
97
  count.times do |i|
99
- results << slice(i, splitted_duration)
98
+ results << slice(i * splitted_duration, splitted_duration)
100
99
  end
101
100
 
102
101
  results
103
102
  end
104
103
 
105
- def to_file(filename)
104
+ def to_file(filename, options = {})
105
+ if @fragments.empty?
106
+ raise EmptyFragment
107
+ end
108
+
109
+ which('ffmpeg')
110
+ which('mp3wrap')
111
+
112
+ options = {
113
+ :overwrite => false
114
+ }.merge(options)
115
+
116
+ if File.exists?(filename)
117
+ if options[:overwrite]
118
+ File.unlink(filename)
119
+ else
120
+ raise FileExists
121
+ end
122
+ end
123
+
106
124
  outfiles = []
107
125
  tmpdir = '/tmp/scissor-' + $$.to_s
108
126
  mkdir tmpdir
@@ -112,16 +130,25 @@ class Scissor
112
130
  outfile = tmpdir + '/' + index.to_s + '.mp3'
113
131
  outfiles << outfile
114
132
  cmd = "ffmpeg -i \"#{fragment.filename}\" -ss #{fragment.start} -t #{fragment.duration} #{outfile}"
133
+ puts cmd
115
134
  system cmd
116
135
  end
117
136
 
118
- # concat mp3 files
119
- cmd = "mp3wrap \"#{filename}\" #{outfiles.join(' ')}"
120
- system cmd
137
+ if outfiles.size == 1
138
+ mv outfiles.first, filename
139
+ else
140
+ # concat mp3 files
141
+ outfile = tmpdir + '/concat.mp3'
142
+ cmd = "mp3wrap \"#{outfile}\" #{outfiles.join(' ')}"
143
+ puts cmd
144
+ system cmd
121
145
 
122
- # fix duration and rename
123
- cmd = "ffmpeg -i \"#{filename.sub(/\.mp3$/, '_MP3WRAP.mp3')}\" -acodec copy \"#{filename}\""
124
- system cmd
146
+ # fix duration and rename
147
+ infile = tmpdir + '/concat_MP3WRAP.mp3'
148
+ cmd = "ffmpeg -i \"#{infile}\" -acodec copy \"#{filename}\""
149
+ puts cmd
150
+ system cmd
151
+ end
125
152
 
126
153
  rm_rf tmpdir
127
154
 
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy