scissor 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ DESCRIPTION = "utility to chop sound files"
18
18
  RUBYFORGE_PROJECT = "scissor"
19
19
  HOMEPATH = "http://github.com/youpy/scissor"
20
20
  BIN_FILES = %w( )
21
- VERS = "0.1.2"
21
+ VERS = "0.2.0"
22
22
 
23
23
  REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
24
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
@@ -62,6 +62,8 @@ spec = Gem::Specification.new do |s|
62
62
  s.add_dependency('ruby-mp3info')
63
63
  s.add_dependency('riff', '<= 0.3.0')
64
64
  s.add_dependency('tempdir')
65
+ s.add_dependency('streamio-ffmpeg')
66
+ s.add_development_dependency('fakeweb')
65
67
  #s.required_ruby_version = '>= 1.8.2'
66
68
 
67
69
  s.files = %w(README.rdoc ChangeLog Rakefile) +
data/lib/scissor/chunk.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'open-uri'
2
+ require 'tempfile'
3
+
1
4
  module Scissor
2
5
  class Chunk
3
6
  class Error < StandardError; end
@@ -17,6 +20,35 @@ module Scissor
17
20
  end
18
21
  end
19
22
 
23
+ def self.new_from_url(url)
24
+ file = nil
25
+ content_types = {
26
+ 'audio/wav' => 'wav',
27
+ 'audio/x-wav' => 'wav',
28
+ 'audio/wave' => 'wav',
29
+ 'audio/x-pn-wav' => 'wav',
30
+ 'audio/mpeg' => 'mp3',
31
+ 'audio/x-mpeg' => 'mp3',
32
+ 'audio/mp3' => 'mp3',
33
+ 'audio/x-mp3' => 'mp3',
34
+ 'audio/mpeg3' => 'mp3',
35
+ 'audio/x-mpeg3' => 'mp3',
36
+ 'audio/mpg' => 'mp3',
37
+ 'audio/x-mpg' => 'mp3',
38
+ 'audio/x-mpegaudio' => 'mp3',
39
+ }
40
+
41
+ open(url) do |f|
42
+ ext = content_types[f.content_type.downcase]
43
+
44
+ file = Tempfile.new(['audio', '.' + ext])
45
+ file.write(f.read)
46
+ file.flush
47
+ end
48
+
49
+ new(file.path)
50
+ end
51
+
20
52
  def add_fragment(fragment)
21
53
  @fragments << fragment
22
54
  end
@@ -2,6 +2,7 @@ require 'digest/md5'
2
2
  require 'pathname'
3
3
  require 'open4'
4
4
  require 'temp_dir'
5
+ require 'streamio-ffmpeg'
5
6
 
6
7
  module Scissor
7
8
  class Writer
@@ -17,7 +18,6 @@ module Scissor
17
18
  @tracks = []
18
19
 
19
20
  which('ecasound')
20
- which('ffmpeg')
21
21
  which('rubberband')
22
22
  end
23
23
 
@@ -40,7 +40,8 @@ module Scissor
40
40
  fragment_outfile = tmpdir + (Digest::MD5.hexdigest(fragment_filename.to_s) + '.wav')
41
41
 
42
42
  unless fragment_outfile.exist?
43
- run_command("ffmpeg -i \"#{fragment_filename}\" -ar 44100 \"#{fragment_outfile}\"")
43
+ movie = FFMPEG::Movie.new(fragment_filename.to_s)
44
+ movie.transcode(fragment_outfile.to_s, :audio_sample_rate => 44100)
44
45
  end
45
46
 
46
47
  cmd << "-a:#{index} -o:#{outfile} -y:#{position}"
@@ -115,7 +116,8 @@ module Scissor
115
116
 
116
117
  mix_files(tmpfiles, final_tmpfile = tmpdir + 'tmp.wav')
117
118
 
118
- run_command("ffmpeg -ab #{options[:bitrate]} -i \"#{final_tmpfile}\" -ar 44100 \"#{full_filename}\"")
119
+ movie = FFMPEG::Movie.new(final_tmpfile.to_s)
120
+ movie.transcode(full_filename.to_s, :audio_sample_rate => 44100, :audio_bitrate => options[:bitrate])
119
121
  end
120
122
  end
121
123
 
data/lib/scissor.rb CHANGED
@@ -5,8 +5,12 @@ require 'scissor/sound_file'
5
5
  require 'scissor/sequence'
6
6
  require 'scissor/writer'
7
7
 
8
- def Scissor(*args)
9
- Scissor::Chunk.new(*args)
8
+ def Scissor(filename_or_url = nil)
9
+ if filename_or_url && filename_or_url =~ /^http/
10
+ Scissor::Chunk.new_from_url(filename_or_url)
11
+ else
12
+ Scissor::Chunk.new(filename_or_url)
13
+ end
10
14
  end
11
15
 
12
16
  require 'logger'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - youpy
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-31 00:00:00 +09:00
17
+ date: 2011-12-02 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,30 @@ dependencies:
69
69
  version: "0"
70
70
  type: :runtime
71
71
  version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: streamio-ffmpeg
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :runtime
83
+ version_requirements: *id005
84
+ - !ruby/object:Gem::Dependency
85
+ name: fakeweb
86
+ prerelease: false
87
+ requirement: &id006 !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ type: :development
95
+ version_requirements: *id006
72
96
  description: utility to chop sound files
73
97
  email: youpy@buycheapviagraonlinenow.com
74
98
  executables: []