r2mp3 0.1.1 → 0.2.0
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/lib/r2mp3/base.rb +5 -0
- data/lib/r2mp3/converter.rb +124 -0
- data/lib/r2mp3/error.rb +21 -0
- data/lib/r2mp3/inspector.rb +39 -0
- data/lib/r2mp3/support.rb +16 -0
- data/lib/r2mp3/test_blah.rb +13 -0
- data/lib/r2mp3/tools/lame.rb +12 -0
- data/lib/r2mp3/tools/loader.rb +25 -0
- data/lib/r2mp3/tools/mplayer.rb +15 -0
- data/lib/r2mp3/version.rb +9 -0
- data/lib/r2mp3.rb +15 -266
- metadata +61 -60
- data/README +0 -25
- data/example/cli_converter.rb +0 -17
- data/example/example.mp3 +0 -0
- data/example/example1.rb +0 -22
- data/example/example1.wma +0 -0
- data/example/example2.rb +0 -18
- data/example/mp3_dir/example1.mp3 +0 -0
- data/example/mp3_dir/example2.mp3 +0 -0
- data/example/mp3_dir/example3.mp3 +0 -0
- data/example/mp3_dir/example4.mp3 +0 -0
- data/example/wma_dir/example1.wma +0 -0
- data/example/wma_dir/example2.wma +0 -0
- data/example/wma_dir/example3.wma +0 -0
- data/example/wma_dir/example4.wma +0 -0
- data/inspector/mp3inspector.rb +0 -90
data/lib/r2mp3/base.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
module R2mp3
|
2
|
+
class Converter
|
3
|
+
attr_reader :default_recipe, :output_path
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@input_file = options[:in]
|
7
|
+
@output_file = options[:out]
|
8
|
+
@wav_output = options[:wav].nil? ? "audiodump.wav" : options[:wav]
|
9
|
+
@mode = options[:mode]
|
10
|
+
@bitrate = options[:bitrate]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_mp3
|
14
|
+
return false unless convert_from_to(:file => @input_file, :from => audio_info.type, :to => :wav)
|
15
|
+
convert_from_to(:file => @input_file, :from => :wav, :to => :mp3)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_mp3!
|
19
|
+
raise ConverterError::DumpToWaveError unless convert_from_to(:file => @input_file, :from => audio_info.type, :to => :wav)
|
20
|
+
raise ConverterError::CovertToMp3Error unless convert_from_to(:file => @input_file, :from => :wav, :to => :mp3)
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_wav?
|
25
|
+
@wav
|
26
|
+
end
|
27
|
+
|
28
|
+
def is_mp3?
|
29
|
+
@mp3
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
#To Do: auto load tool for particular media type
|
35
|
+
def run_tool_with(options = {})
|
36
|
+
# p Module.nesting
|
37
|
+
recipe = options[:recipe]
|
38
|
+
message = options[:message]
|
39
|
+
unless recipe.nil? && message.nil?
|
40
|
+
tool = R2mp3::Tools::Loader.load(recipe)
|
41
|
+
tool.execute(message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def audio_info
|
46
|
+
Inspector.new(:file => @input_file)
|
47
|
+
end
|
48
|
+
|
49
|
+
def convert_from_to(options={})
|
50
|
+
message = "convert from #{options[:from]} to #{options[:to]}"
|
51
|
+
case options[:to]
|
52
|
+
when :wav
|
53
|
+
# @default_recipe = YAML.load_file(File.dirname(__FILE__) + "/../../recipes/to_wav.yaml")[:default] + " " + @input_file
|
54
|
+
return true if run_tool_with(:recipe => dump_to_wav, :message => message)
|
55
|
+
when :mp3
|
56
|
+
# @default_recipe = YAML::load_file(File.dirname(__FILE__) + "/../../recipes/to_mp3.yaml")[:default]
|
57
|
+
return true if run_tool_with(:recipe => wav_to_mp3, :message => message)
|
58
|
+
end
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def dump_to_wav
|
64
|
+
puts "dumping to wav...."
|
65
|
+
raise ConverterError::InputFileRequired unless File.exists?(@input_file)
|
66
|
+
%Q{mplayer #{wav_options} #{@input_file}}
|
67
|
+
end
|
68
|
+
|
69
|
+
def wav_options
|
70
|
+
# todo:
|
71
|
+
opts = {
|
72
|
+
:quiet => "",
|
73
|
+
:vo => "null",
|
74
|
+
:vc => "dummy",
|
75
|
+
:af => "volume=0,resample=44100:0:1",
|
76
|
+
:ao => "pcm:waveheader:file=#{@wav_output}"
|
77
|
+
}
|
78
|
+
options = " "
|
79
|
+
opts.each do |k,v|
|
80
|
+
options << "-#{k.to_s} #{v.to_s} "
|
81
|
+
end
|
82
|
+
options
|
83
|
+
end
|
84
|
+
|
85
|
+
def wav_to_mp3
|
86
|
+
puts "wav to mp3 conversion...."
|
87
|
+
raise ConverterError::DumpToWaveError unless File.exists?(@wav_output)
|
88
|
+
input = @wav_output
|
89
|
+
options = mp3_options
|
90
|
+
@output_path = @output_file
|
91
|
+
%Q{lame #{input} #{@output_file} #{options}}
|
92
|
+
end
|
93
|
+
|
94
|
+
#it just works, and shouldn't be here exactly.
|
95
|
+
#To do: move to lame
|
96
|
+
def mp3_options
|
97
|
+
# (j)oint, (s)imple, (f)orce, (d)dual-mono, (m)ono
|
98
|
+
mode = {
|
99
|
+
:stereo => "j",
|
100
|
+
:mono => "m",
|
101
|
+
:dual_mono => "d"
|
102
|
+
}
|
103
|
+
bitrates = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
|
104
|
+
opts = {
|
105
|
+
:V2 => "",
|
106
|
+
:_vbr_new => "",
|
107
|
+
:q0 => "",
|
108
|
+
:_lowpass => "19.7",
|
109
|
+
:m => "j"
|
110
|
+
}
|
111
|
+
opts[:m] = mode[@mode.to_sym] unless @mode.nil?
|
112
|
+
unless @bitrate.nil?
|
113
|
+
raise ConverterError::Mp3UnsupportBitrate unless bitrates.include?(@bitrate.to_i)
|
114
|
+
opts[:b] = @bitrate
|
115
|
+
end
|
116
|
+
options = " "
|
117
|
+
opts.each do |k,v|
|
118
|
+
options << "-#{k.to_s.gsub("_","-")} #{v.to_s} "
|
119
|
+
end
|
120
|
+
options
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/lib/r2mp3/error.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class ConverterError < RuntimeError
|
2
|
+
class InputFileRequired < ConverterError
|
3
|
+
end
|
4
|
+
class UnknownError < ConverterError
|
5
|
+
end
|
6
|
+
class DumpToWaveError < ConverterError
|
7
|
+
end
|
8
|
+
class Mp3UnsupportBitrate < ConverterError
|
9
|
+
end
|
10
|
+
class CovertToMp3Error < ConverterError
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class InspectorError < RuntimeError
|
15
|
+
class InputFileRequired < InspectorError
|
16
|
+
end
|
17
|
+
class InvalidInput < InspectorError
|
18
|
+
end
|
19
|
+
class UnknownError < InspectorError
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'mp3info'
|
2
|
+
module R2mp3
|
3
|
+
class Inspector
|
4
|
+
attr_reader :type, :header, :channel_mode, :length, :tag1, :tag, :vbr, :layer, :samplerate, :mpeg_version, :tag1_parsed, :filename, :bitrate
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@file = options[:file]
|
8
|
+
raise InspectorError::InputFileRequired if @file.nil?
|
9
|
+
@type = file_extension
|
10
|
+
info
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
# Naive
|
15
|
+
def file_extension
|
16
|
+
File.extname(@file).gsub(".","").to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def info
|
20
|
+
return nil unless @type.eql?(:mp3)
|
21
|
+
Mp3Info.open(@file) do |info|
|
22
|
+
@header = info.header
|
23
|
+
@channel_mode = info.channel_mode
|
24
|
+
@length = info.length
|
25
|
+
#@tag1 = info.tag1
|
26
|
+
@tag = info.tag
|
27
|
+
@vbr = info.vbr
|
28
|
+
@layer = info.layer
|
29
|
+
@samplerate = info.samplerate
|
30
|
+
@mpeg_version = info.mpeg_version
|
31
|
+
#@tag1_parsed = info.tag1_parsed
|
32
|
+
@filename = info.filename
|
33
|
+
@bitrate = info.bitrate
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Module
|
2
|
+
|
3
|
+
def constant(opts = {})
|
4
|
+
opts.each_pair do |k, v|
|
5
|
+
k = k.to_s.upcase
|
6
|
+
const_set(k, v) unless const_defined?(k)
|
7
|
+
end
|
8
|
+
|
9
|
+
# module_eval(<<-EVAL, __FILE__, __LINE__)
|
10
|
+
# def self.#{name.to_s.downcase}
|
11
|
+
# #{name.to_s}
|
12
|
+
# end
|
13
|
+
# EVAL
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module R2mp3
|
2
|
+
module Tools
|
3
|
+
class Loader
|
4
|
+
|
5
|
+
def self.load(recipe, options = {})
|
6
|
+
name = recipe.split.first
|
7
|
+
tool = "R2mp3::Tools::#{name.classify}".constantize.send(:new, recipe, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def initialize(recipe, options = {})
|
12
|
+
@recipe = recipe
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(message=nil)
|
16
|
+
run_command = "#{@recipe} 2>&1"
|
17
|
+
# puts "run command: #{run_command}"
|
18
|
+
# puts message unless message.nil?
|
19
|
+
@result = `#{run_command}`
|
20
|
+
return parse(@result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module R2mp3
|
2
|
+
module Tools
|
3
|
+
class Mplayer
|
4
|
+
constant :mplayer => 'mplayer'
|
5
|
+
include Loader::InstanceMethods
|
6
|
+
|
7
|
+
def parse(result)
|
8
|
+
return true unless result[/Audio stream found/].nil?
|
9
|
+
return true unless result[/file format detected/].nil?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/r2mp3.rb
CHANGED
@@ -1,273 +1,22 @@
|
|
1
|
-
# R2mp3 Library
|
2
|
-
# Exclusive to you by
|
3
|
-
# Warachet Samtalee (zdk@codegent.com)
|
4
|
-
|
5
1
|
require 'rubygems'
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
|
13
|
-
class Options < Hash
|
14
|
-
def initialize(arg)
|
15
|
-
begin
|
16
|
-
optstruct = OpenStruct.new
|
17
|
-
options = OptionParser.new do |opts|
|
18
|
-
opts.banner = "usage: #{__FILE__} [options]"
|
19
|
-
opts.on('-w','--wma-to-mp3','convert .wma to mp3 ')do
|
20
|
-
self[:wma] = true
|
21
|
-
end
|
22
|
-
opts.on('-a','--aac-to-mp3','convert .m4a to mp3')do
|
23
|
-
self[:aac] = true
|
24
|
-
end
|
25
|
-
opts.on('-r','--ra-to-mp3','convert .rm to mp3')do
|
26
|
-
self[:ra] = true
|
27
|
-
end
|
28
|
-
opts.on('-m','--mp3-to-mp3','convert mp3 to mp3')do
|
29
|
-
self[:mp3] = true
|
30
|
-
end
|
31
|
-
opts.on('-f','--file [filename]','file') do |f|
|
32
|
-
self[:file] = f
|
33
|
-
end
|
34
|
-
opts.on('-d','--dir [directoryname]','directory') do |d|
|
35
|
-
self[:dir] = d
|
36
|
-
end
|
37
|
-
opts.on('-b','--bitrate [kbps]','bitrate') do |b|
|
38
|
-
self[:bitrate] = b.to_i
|
39
|
-
end
|
40
|
-
opts.on_tail('-h','--help','help') do
|
41
|
-
puts opts
|
42
|
-
exit
|
43
|
-
end
|
44
|
-
raise "print help" if ARGV.size < 1
|
45
|
-
raise "choose wma or aac " if self[:wma] and self[:aac]
|
46
|
-
end.parse!(arg)
|
47
|
-
rescue OptionParser::InvalidOption, RuntimeError => e
|
48
|
-
puts e
|
49
|
-
puts "#{$0} -h or --help , for help"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class Converter
|
55
|
-
def initialize(opts={},&block)
|
56
|
-
$opts = opts
|
57
|
-
yield(opts) if block_given?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Mplayer
|
62
|
-
# Can be used to dump any audio file to wav
|
63
|
-
def self.dump_to_wav(input, output, opts={})
|
64
|
-
puts "dump to wav"
|
65
|
-
begin
|
66
|
-
platform = `uname -a`
|
67
|
-
binary = "#{%r{Linux} =~ platform}".empty?? "/Applications/mplayer":"mplayer"
|
68
|
-
FileUtils.rm("audiodump.wav") if File.exists? "audiodump.wav"
|
69
|
-
opts[:resample] ||= '44100'
|
70
|
-
args = ""
|
71
|
-
force_opt = {:vo => "null", :vc => "dummy", :af => "resample=#{opts[:resample]}", :ao => "pcm:waveheader"}
|
72
|
-
force_opt.each{|k,v| args << "-#{k.to_s} #{v} "}
|
73
|
-
cmd = "#{binary} #{args} #{input}"
|
74
|
-
success = system(cmd)
|
75
|
-
puts "Success? #{success}"
|
76
|
-
FileUtils.mv("audiodump.wav", output) if File.exists? "audiodump.wav"
|
77
|
-
success
|
78
|
-
rescue Errno::ENOENT => err
|
79
|
-
puts "No audiodump :" + err
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
class Convert
|
2
|
+
require 'base64'
|
3
|
+
require 'digest/sha1'
|
4
|
+
require 'time'
|
5
|
+
require 'date'
|
6
|
+
require 'yaml'
|
7
|
+
require 'active_support'
|
86
8
|
|
87
|
-
def self.mp3_to_wav(input, output=nil, opts={})
|
88
|
-
puts "mp3 to wav"
|
89
|
-
conversion(:mp3, :wav, input, output, opts) do | input, output, opts |
|
90
|
-
Mplayer.dump_to_wav(input, output, opts)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.mp3_to_mp3(input, output=nil, opts={})
|
95
|
-
puts "mp3 to mp3"
|
96
|
-
output ||= input.gsub(/\.rm$/,".mp3")
|
97
|
-
mp3_to_wav(input, 'temp.wav', opts) and wav_to_mp3('temp.wav', output, opts.merge({:delete_input=>true}))
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.ra_to_wav(input, output=nil, opts={})
|
101
|
-
conversion(:rm, :wav, input, output, opts) do | input, output, opts |
|
102
|
-
Mplayer.dump_to_wav(input, output, opts)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.ra_to_mp3(input, output=nil, opts={})
|
107
|
-
output ||= input.gsub(/\.rm$/,".mp3")
|
108
|
-
ra_to_wav(input, 'temp.wav', opts) and wav_to_mp3('temp.wav', output, opts.merge({:delete_input=>true}))
|
109
|
-
end
|
110
|
-
|
111
|
-
def self.aac_to_wav(input, output=nil, opts={})
|
112
|
-
conversion(:m4a, :wav, input, output, opts) do | input, output, opts |
|
113
|
-
Mplayer.dump_to_wav(input, output, opts)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.aac_to_mp3(input, output=nil, opts={})
|
118
|
-
output ||= input.gsub(/\.m4a$/,".mp3")
|
119
|
-
aac_to_wav(input, 'temp.wav', opts) and wav_to_mp3('temp.wav', output, opts.merge({:delete_input=>true}))
|
120
|
-
end
|
121
9
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
wma_to_wav(input, 'temp.wav', opts) and wav_to_mp3('temp.wav', output, opts.merge({:delete_input=>true}))
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.wma_to_wav(input, output=nil, opts={})
|
129
|
-
conversion(:wma, :wav, input, output, opts) do | input, output, opts |
|
130
|
-
Mplayer.dump_to_wav(input, output, opts)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.wav_to_mp3(input, output=nil, opts={})
|
135
|
-
puts "wav to mp3"
|
136
|
-
conversion(:wav, :mp3, input, output, opts) do | input, output, opts |
|
137
|
-
opts[:mode] ||= :stereo
|
138
|
-
opts[:bitrate] ||= 64
|
139
|
-
puts "bitrate = #{opts[:bitrate]}"
|
140
|
-
lame = LameAdapter.new
|
141
|
-
lame.input_file input
|
142
|
-
lame.output_file output
|
143
|
-
lame.mode opts[:mode]
|
144
|
-
lame.bitrate opts[:bitrate]
|
145
|
-
lame.convert!
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def self.conversion(input_format, output_format, input_file, output_file, opts={}, &block)
|
150
|
-
puts "...conversion"
|
151
|
-
input_format = input_format.to_s
|
152
|
-
output_format = output_format.to_s
|
153
|
-
input_regexp = /\.#{input_format}$/
|
154
|
-
return false unless File.exists? input_file and File.extname(input_file) =~ input_regexp
|
155
|
-
output_file ||= input_file.gsub(input_regexp,".#{output_format}")
|
156
|
-
success = yield(input_file, output_file, opts)
|
157
|
-
FileUtils.rm input_file if opts[:delete_input]
|
158
|
-
success and File.exists? output_file
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.wma_dir_to_mp3(dirname, opts = {})
|
162
|
-
Dir["#{dirname}/*.wma"].each do |name|
|
163
|
-
if !name[/[\s]+/].nil? then
|
164
|
-
new_name = name.gsub(" ","_").downcase
|
165
|
-
FileUtils.mv "#{name}", "#{new_name}", :force => true # no error
|
166
|
-
name = new_name
|
167
|
-
end
|
168
|
-
wma_to_mp3(name, nil, opts)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def self.wma_file_to_mp3(filename, opts = {})
|
173
|
-
wma_to_mp3(filename, nil, opts)
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.aac_dir_to_mp3(dirname, opts = {})
|
177
|
-
Dir["#{dirname}/*.m4a"].each do |name|
|
178
|
-
if !name[/[\s]+/].nil? then
|
179
|
-
new_name = name.gsub(" ","_").downcase
|
180
|
-
FileUtils.mv "#{name}", "#{new_name}", :force => true # no error
|
181
|
-
name = new_name
|
182
|
-
end
|
183
|
-
aac_to_mp3(name, nil, opts)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def self.aac_file_to_mp3(filename, opts = {})
|
188
|
-
aac_to_mp3(filename, nil, opts)
|
189
|
-
end
|
190
|
-
|
191
|
-
def self.ra_dir_to_mp3(dirname, opts = {})
|
192
|
-
Dir["#{dirname}/*.rm"].each do |name|
|
193
|
-
if !name[/[\s]+/].nil? then
|
194
|
-
new_name = name.gsub(" ","_").downcase
|
195
|
-
FileUtils.mv "#{name}", "#{new_name}", :force => true # no error
|
196
|
-
name = new_name
|
197
|
-
end
|
198
|
-
ra_to_mp3(name, nil, opts)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def self.ra_file_to_mp3(filename, opts = {})
|
203
|
-
ra_to_mp3(filename, nil, opts)
|
204
|
-
end
|
205
|
-
|
206
|
-
def self.mp3_dir_to_mp3(dirname, opts = {})
|
207
|
-
Dir["#{dirname}/*.mp3"].each do |name|
|
208
|
-
if !name[/[\s]+/].nil? then
|
209
|
-
new_name = name.gsub(" ","_").downcase
|
210
|
-
FileUtils.mv "#{name}", "#{new_name}", :force => true # no error
|
211
|
-
name = new_name
|
212
|
-
end
|
213
|
-
mp3_to_mp3(name, nil, opts)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def self.mp3_file_to_mp3(filename, opts = {})
|
218
|
-
mp3_to_mp3(filename, nil, opts)
|
219
|
-
end
|
220
|
-
|
221
|
-
end
|
10
|
+
$:.unshift(File.dirname(__FILE__))
|
11
|
+
require 'r2mp3/support'
|
12
|
+
require 'r2mp3/base'
|
222
13
|
|
14
|
+
libs = [ :error, :version, :converter, :inspector ]
|
15
|
+
#
|
16
|
+
libs.each { |l| require File.dirname(__FILE__) + "/#{R2mp3::Base::R2MP3}/#{l.to_s}" }
|
223
17
|
|
224
|
-
class Hash
|
225
|
-
|
226
|
-
def to_mp3
|
227
|
-
case $opts[:convert]
|
228
|
-
when :wma
|
229
|
-
unless $opts[:dir].nil? then
|
230
|
-
puts "convert all wma files in #{self[:dir]}"
|
231
|
-
Convert.wma_dir_to_mp3(self[:dir], self)
|
232
|
-
else
|
233
|
-
puts "(wma) convert #{self[:file]} to mp3"
|
234
|
-
Convert.wma_file_to_mp3(self[:file], self)
|
235
|
-
end
|
236
|
-
when :aac
|
237
|
-
unless $opts[:dir].nil? then
|
238
|
-
puts "convert all aac files in #{self[:dir]}"
|
239
|
-
Convert.aac_dir_to_mp3(self[:dir], self)
|
240
|
-
else
|
241
|
-
puts "(aac) convert #{self[:file]} to mp3"
|
242
|
-
Convert.aac_file_to_mp3(self[:file], self)
|
243
|
-
end
|
244
|
-
when :ra
|
245
|
-
unless $opts[:dir].nil? then
|
246
|
-
puts "convert all ra files in #{self[:dir]}"
|
247
|
-
Convert.ra_dir_to_mp3(self[:dir], self)
|
248
|
-
else
|
249
|
-
puts "(ra) convert #{self[:file]} to mp3"
|
250
|
-
Convert.ra_file_to_mp3(self[:file], self)
|
251
|
-
end
|
252
|
-
when :mp3
|
253
|
-
unless $opts[:dir].nil? then
|
254
|
-
puts "convert all mp3 files in #{self[:dir]}"
|
255
|
-
Convert.mp3_dir_to_mp3(self[:dir], self)
|
256
|
-
else
|
257
|
-
puts "(mp3) convert #{self[:file]} to mp3"
|
258
|
-
Convert.mp3_file_to_mp3(self[:file], self)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def bitrate kbps
|
264
|
-
self[:bitrate] = kbps
|
265
|
-
end
|
266
|
-
|
267
|
-
def mode m
|
268
|
-
self[:mode] = m
|
269
|
-
end
|
270
|
-
|
271
|
-
end
|
272
18
|
|
19
|
+
require 'r2mp3/tools/loader'
|
20
|
+
require 'r2mp3/tools/lame'
|
21
|
+
require 'r2mp3/tools/mplayer'
|
273
22
|
|
metadata
CHANGED
@@ -1,73 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: r2mp3
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-10-29 00:00:00 +07:00
|
8
|
-
summary: A library for converting any audio to MP3 (MPEG-1 Layer3)
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: zdk@codegent.com
|
12
|
-
homepage: ""
|
13
|
-
rubyforge_project:
|
14
|
-
description: This library intends to convert all available audio files on the planet to MP3
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.2.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Warachet Samtalee
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- example/rm_dir
|
35
|
-
- example/example1.wma
|
36
|
-
- example/mp3_dir
|
37
|
-
- example/example.mp3
|
38
|
-
- example/wma_dir
|
39
|
-
- example/aac_dir
|
40
|
-
- example/example1.rb
|
41
|
-
- example/example2.rb
|
42
|
-
- example/cli_converter.rb
|
43
|
-
- example/mp3_dir/example2.mp3
|
44
|
-
- example/mp3_dir/example3.mp3
|
45
|
-
- example/mp3_dir/example1.mp3
|
46
|
-
- example/mp3_dir/example4.mp3
|
47
|
-
- example/wma_dir/example1.wma
|
48
|
-
- example/wma_dir/example3.wma
|
49
|
-
- example/wma_dir/example4.wma
|
50
|
-
- example/wma_dir/example2.wma
|
51
|
-
- inspector/mp3inspector.rb
|
52
|
-
test_files: []
|
53
|
-
|
54
|
-
rdoc_options: []
|
55
|
-
|
56
|
-
extra_rdoc_files: []
|
57
|
-
|
58
|
-
executables: []
|
59
|
-
|
60
|
-
extensions: []
|
61
|
-
|
62
|
-
requirements: []
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
63
11
|
|
12
|
+
date: 2008-09-09 00:00:00 +07:00
|
13
|
+
default_executable:
|
64
14
|
dependencies:
|
65
15
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
16
|
+
name: ruby-mp3info
|
17
|
+
type: :runtime
|
67
18
|
version_requirement:
|
68
|
-
version_requirements: !ruby/object:Gem::
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
20
|
requirements:
|
70
|
-
- -
|
21
|
+
- - ~>
|
71
22
|
- !ruby/object:Gem::Version
|
72
|
-
version: 0.
|
23
|
+
version: 0.6.7
|
73
24
|
version:
|
25
|
+
description: This library intends to add ability to convert all audio files on the earth to mp3
|
26
|
+
email: nx2zdk@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/r2mp3
|
35
|
+
- lib/r2mp3/base.rb
|
36
|
+
- lib/r2mp3/converter.rb
|
37
|
+
- lib/r2mp3/error.rb
|
38
|
+
- lib/r2mp3/inspector.rb
|
39
|
+
- lib/r2mp3/support.rb
|
40
|
+
- lib/r2mp3/test_blah.rb
|
41
|
+
- lib/r2mp3/tools
|
42
|
+
- lib/r2mp3/tools/lame.rb
|
43
|
+
- lib/r2mp3/tools/loader.rb
|
44
|
+
- lib/r2mp3/tools/mplayer.rb
|
45
|
+
- lib/r2mp3/version.rb
|
46
|
+
- lib/r2mp3.rb
|
47
|
+
has_rdoc: false
|
48
|
+
homepage: http://ziddik.blogspot.com
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: r2mp3
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: A library for converting any audio files to mp3
|
73
|
+
test_files: []
|
74
|
+
|
data/README
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
R2mp3 library:
|
2
|
-
- Convert wma to mp3
|
3
|
-
- Convert aac to mp3
|
4
|
-
- Convert ra to mp3
|
5
|
-
|
6
|
-
Requirement:
|
7
|
-
lame_adapter (sudo gem install lame_adapter)
|
8
|
-
mplayer+lame (sudo apt-get install mplayer lame)
|
9
|
-
|
10
|
-
|
11
|
-
Change log:
|
12
|
-
15/10/2007 Pre-Alpha
|
13
|
-
- Should support simple convert to mp3
|
14
|
-
|
15
|
-
29/10/2007 Version 0.1.1
|
16
|
-
- Add bitrate setting
|
17
|
-
- Add mode setting
|
18
|
-
- Remove bitrate setting bug
|
19
|
-
- Change example
|
20
|
-
- Support MP3 to MP3
|
21
|
-
- MP3 inspector added based-on mp3-info
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
data/example/cli_converter.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
|
-
require 'r2mp3'
|
4
|
-
options = Options.new(ARGV)
|
5
|
-
|
6
|
-
options[:bitrate] ||= 64
|
7
|
-
|
8
|
-
Converter.new(:convert=>:wma,:file=>options[:file],:bitrate => options[:bitrate]){|f| f.to_mp3 } unless options[:wma].nil? or options[:file].nil?
|
9
|
-
Converter.new(:convert=>:wma,:dir=>options[:dir],:bitrate => options[:bitrate]){|d| d.to_mp3 } unless options[:wma].nil? or options[:dir].nil?
|
10
|
-
Converter.new(:convert=>:aac,:file=>options[:file],:bitrate => options[:bitrate]){|f| f.to_mp3 } unless options[:aac].nil? or options[:file].nil?
|
11
|
-
Converter.new(:convert=>:aac,:dir=>options[:dir],:bitrate => options[:bitrate]){|d| d.to_mp3 } unless options[:aac].nil? or options[:dir].nil?
|
12
|
-
Converter.new(:convert=>:ra,:file=>options[:file],:bitrate => options[:bitrate]){|f| f.to_mp3 } unless options[:ra].nil? or options[:file].nil?
|
13
|
-
Converter.new(:convert=>:ra,:dir=>options[:dir],:bitrate => options[:bitrate]){|d| d.to_mp3 } unless options[:ra].nil? or options[:dir].nil?
|
14
|
-
Converter.new(:convert=>:ra,:file=>options[:file],:bitrate => options[:bitrate]){|f| f.to_mp3 } unless options[:mp3].nil? or options[:file].nil?
|
15
|
-
Converter.new(:convert=>:ra,:dir=>options[:dir],:bitrate => options[:bitrate]){|d| d.to_mp3 } unless options[:mp3].nil? or options[:dir].nil?
|
16
|
-
|
17
|
-
|
data/example/example.mp3
DELETED
Binary file
|
data/example/example1.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#require 'rubygems'
|
3
|
-
require '../lib/r2mp3.rb'
|
4
|
-
|
5
|
-
wma_file = "example1.wma"
|
6
|
-
wma_dir = "wma_dir"
|
7
|
-
aac_file = "aac_example.m4a"
|
8
|
-
aac_dir = "aac_dir"
|
9
|
-
rm_file = "rm_example.rm"
|
10
|
-
rm_dir = "rm_dir"
|
11
|
-
|
12
|
-
Converter.new(:convert=>:wma,:file=>wma_file) do |f|
|
13
|
-
f.bitrate 128
|
14
|
-
f.to_mp3
|
15
|
-
end
|
16
|
-
|
17
|
-
Converter.new(:convert=>:wma,:dir=>wma_dir) do |d|
|
18
|
-
d.bitrate 128
|
19
|
-
d.to_mp3
|
20
|
-
end
|
21
|
-
|
22
|
-
|
data/example/example1.wma
DELETED
Binary file
|
data/example/example2.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#require 'rubygems'
|
3
|
-
require '../lib/r2mp3.rb'
|
4
|
-
|
5
|
-
mp3_file = "example.mp3"
|
6
|
-
mp3_dir = "mp3_dir"
|
7
|
-
|
8
|
-
Converter.new(:convert=>:mp3,:file=>mp3_file) do |f|
|
9
|
-
f.bitrate 160
|
10
|
-
f.to_mp3
|
11
|
-
end
|
12
|
-
|
13
|
-
Converter.new(:convert=>:mp3,:dir=>mp3_dir) do |d|
|
14
|
-
d.bitrate 160
|
15
|
-
d.to_mp3
|
16
|
-
end
|
17
|
-
|
18
|
-
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/inspector/mp3inspector.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#This script used for inspect the mp3 file
|
3
|
-
require 'rubygems'
|
4
|
-
require "base64"
|
5
|
-
require 'mp3info'
|
6
|
-
TEMP_FILE = File.join(File.dirname($0),"file.mp3")
|
7
|
-
|
8
|
-
class Mp3Tool
|
9
|
-
def self.setup
|
10
|
-
@valid_mp3 = Base64.decode64 <<EOF
|
11
|
-
//uQZAAAAAAAaQYAAAAAAA0gwAAAAAABpBwAAAAAADSDgAAATEFNRTMuOTNV
|
12
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
13
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
14
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
15
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
16
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
17
|
-
VVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuOTNVVVVVVVVVVVVVVVVVVVVVVVVV
|
18
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
19
|
-
VVVVVVV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|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
50
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
51
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
52
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
53
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
54
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
55
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
56
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
57
|
-
VVVVVVVVVVVVVVVVVVVVVVVVVQ==
|
58
|
-
EOF
|
59
|
-
@tag = {
|
60
|
-
"title" => "title",
|
61
|
-
"artist" => "artist",
|
62
|
-
"album" => "album",
|
63
|
-
"year" => 1921,
|
64
|
-
"comments" => "comments",
|
65
|
-
"genre" => 0,
|
66
|
-
"genre_s" => "Blues",
|
67
|
-
"tracknum" => 36
|
68
|
-
}
|
69
|
-
File.open(TEMP_FILE, "w") { |f| f.write(@valid_mp3) }
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.inspect
|
73
|
-
Mp3Info.open(TEMP_FILE) do |info|
|
74
|
-
puts "Inspecting...#{TEMP_FILE}"
|
75
|
-
puts "======Summary============"
|
76
|
-
puts "MPEG #{info.mpeg_version}"
|
77
|
-
puts "Layer #{info.layer}"
|
78
|
-
puts "VBR? #{info.vbr}"
|
79
|
-
puts "Bitrate #{info.bitrate} kbps"
|
80
|
-
puts "Mode: #{info.channel_mode}"
|
81
|
-
puts "Sample rate #{info.samplerate} Hz"
|
82
|
-
puts "Error protection? #{info.error_protection}"
|
83
|
-
puts "Length #{info.length}"
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
Mp3Tool.setup
|
90
|
-
Mp3Tool.inspect
|