flac2mp3 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/History.txt +7 -2
- data/lib/flac2mp3.rb +39 -37
- data/lib/flac2mp3/version.rb +1 -1
- data/spec/flac2mp3_command_spec.rb +20 -20
- data/spec/flac2mp3_spec.rb +161 -161
- data/spec/metaflac2mp3_command_spec.rb +7 -7
- metadata +84 -103
- data/Manifest.txt +0 -22
- data/README.txt +0 -60
- data/Rakefile +0 -4
- data/config/hoe.rb +0 -80
- data/config/requirements.rb +0 -17
- data/log/debug.log +0 -0
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWJhM2U1ZThkNTUyZGQ3NGQ0YzU4ODY0YjU1ZTY5YmUyODBlNzBhNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjRhMzhmYTdlNTJhNGUyYzVlOWQzNGQ1YzUxYzA3MjFhY2UwMjlmNg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzRlOWFmMmVmMTk3YTM0NjY0ODk3M2NhZWY5ZTZmMDA0YTIwYWY3NWZjZWFm
|
10
|
+
MGMzOThiN2YxMjU0NTAzNzIwMjk3ZDIwMTY1NDNmN2RhZGQ0YTM5OWI3ZTJj
|
11
|
+
NTIwZDczMWQ0M2E2ZTM5NTQyZDZhMWI4ZDYxOTgxZDNlNzhlMGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmQ1Yjk0YzUxMDc3MjZjNmM5YWZlYTNkZDQ1YWRiYzNiZjc5YTA5NGQwNGE1
|
14
|
+
ODMwZTM3YWFhZTA1ZjYyNTZhYjZjZjQ1MzVkZWU5YzdmNTVhZDZhYmQ5NGE5
|
15
|
+
YzMzOTUzMWIwZjE1YjJkZjVhNDg2N2Y1MGFkMDgwOGRiODc5ZjA=
|
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.4.1 2013-04-20
|
2
|
+
|
3
|
+
* 1 tiny enhancement:
|
4
|
+
* Switched from iconv to built-in encoding
|
5
|
+
|
1
6
|
== 0.4.0 2009-09-22
|
2
7
|
|
3
8
|
* 1 enhancement:
|
@@ -22,7 +27,7 @@
|
|
22
27
|
* 2 enhancements:
|
23
28
|
* Now has a configuration file, ~/.flac2mp3, where options can be stored.
|
24
29
|
Options given on the command-line override any configuration options.
|
25
|
-
|
30
|
+
* Greatly refactored internals, though the command-line operation remains the same.
|
26
31
|
|
27
32
|
== 0.2.8 2008-07-21
|
28
33
|
|
@@ -43,7 +48,7 @@
|
|
43
48
|
|
44
49
|
* 1 bug fix:
|
45
50
|
* Composer now actually carried over from FLAC to MP3 tags, not just thought to be.
|
46
|
-
|
51
|
+
|
47
52
|
* 3 enhancements:
|
48
53
|
* Compilation flag carried over.
|
49
54
|
* Track total carried over in addition to track number.
|
data/lib/flac2mp3.rb
CHANGED
@@ -2,60 +2,62 @@ $:.unshift File.dirname(__FILE__)
|
|
2
2
|
require 'flacinfo'
|
3
3
|
require 'mp3info'
|
4
4
|
require 'yaml'
|
5
|
-
require 'iconv'
|
6
5
|
|
7
6
|
class Flac2mp3
|
8
7
|
def initialize(options = {})
|
9
8
|
load_config
|
10
9
|
set_options(options)
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
def convert(filename)
|
14
13
|
raise TypeError, "'#{filename}' is not a file" unless FileTest.file?(filename)
|
15
14
|
process_conversion(filename)
|
16
15
|
File.delete(filename) if delete?
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
def process_conversion(filename)
|
20
19
|
outfile = output_filename(filename)
|
21
20
|
convert_data(filename, outfile)
|
22
21
|
convert_metadata(filename, outfile)
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
def convert_data(filename, outfile)
|
26
25
|
system "#{flac_command(filename)} | #{mp3_command(outfile)}"
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
def flac_command(filename)
|
30
29
|
command = 'flac'
|
31
30
|
command << ' --silent' if silent?
|
32
|
-
|
31
|
+
|
33
32
|
"#{command} --stdout --decode #{safequote(filename)}"
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
def mp3_command(filename)
|
37
36
|
command = 'lame'
|
38
37
|
command << ' --silent' if silent?
|
39
|
-
|
38
|
+
|
40
39
|
"#{command} #{encoding} - #{safequote(filename)}"
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
def convert_metadata(filename, outfile)
|
44
43
|
set_mp3data(outfile, get_flacdata(filename))
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
def get_flacdata(filename)
|
48
|
-
|
47
|
+
hash = {}
|
48
|
+
|
49
|
+
FlacInfo.new(filename).tags.each do |(key, value)|
|
49
50
|
key = key.to_s.downcase.to_sym
|
50
51
|
value = value.to_i if value.respond_to?(:match) and value.match(/^\d+$/)
|
51
52
|
value = value.to_s if self.class.string_fields.include?(key)
|
52
|
-
value =
|
53
|
-
|
53
|
+
value = value.force_encoding('UTF-8') if value.is_a?(String)
|
54
|
+
|
54
55
|
hash[key] = value
|
55
|
-
hash
|
56
56
|
end
|
57
|
+
|
58
|
+
hash
|
57
59
|
end
|
58
|
-
|
60
|
+
|
59
61
|
def set_mp3data(filename, tags)
|
60
62
|
raise TypeError, "Tags must be a hash" unless tags.is_a?(Hash)
|
61
63
|
Mp3Info.open(filename) do |mp3|
|
@@ -65,56 +67,56 @@ class Flac2mp3
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
|
-
|
70
|
+
|
69
71
|
def load_config
|
70
72
|
@config = {}
|
71
73
|
yaml = YAML.load(File.read(File.expand_path('~/.flac2mp3'))) || {}
|
72
74
|
yaml.each { |k, v| @config[k.to_sym] = v }
|
73
75
|
rescue Errno::ENOENT
|
74
76
|
end
|
75
|
-
|
77
|
+
|
76
78
|
def set_options(options)
|
77
79
|
raise TypeError, 'options must be a hash' unless options.is_a?(Hash)
|
78
80
|
@options = config.merge(options)
|
79
81
|
end
|
80
|
-
|
82
|
+
|
81
83
|
def options
|
82
84
|
@options.dup
|
83
85
|
end
|
84
|
-
|
86
|
+
|
85
87
|
def config
|
86
88
|
@config.dup
|
87
89
|
end
|
88
|
-
|
90
|
+
|
89
91
|
def delete?
|
90
92
|
!!options[:delete]
|
91
93
|
end
|
92
|
-
|
94
|
+
|
93
95
|
def silent?
|
94
96
|
!!options[:silent]
|
95
97
|
end
|
96
|
-
|
98
|
+
|
97
99
|
def encoding
|
98
100
|
options[:encoding] || self.class.default_encoding
|
99
101
|
end
|
100
|
-
|
102
|
+
|
101
103
|
def output_filename(filename)
|
102
104
|
filename.chomp('.flac') + '.mp3'
|
103
105
|
end
|
104
|
-
|
106
|
+
|
105
107
|
def safequote(filename)
|
106
108
|
filename.gsub(/(\W)/, '\\\\\1')
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
class << self
|
110
112
|
def convert(filename, options = {})
|
111
113
|
new(options).convert(filename)
|
112
114
|
end
|
113
|
-
|
115
|
+
|
114
116
|
def convert_metadata(infile, outfile)
|
115
117
|
new.convert_metadata(infile, outfile)
|
116
118
|
end
|
117
|
-
|
119
|
+
|
118
120
|
def tag_mapping
|
119
121
|
{
|
120
122
|
:album => :album,
|
@@ -133,39 +135,39 @@ class Flac2mp3
|
|
133
135
|
:tag => :TIT1
|
134
136
|
}
|
135
137
|
end
|
136
|
-
|
138
|
+
|
137
139
|
def convert_tags(tags)
|
138
140
|
mp3_tags = {}
|
139
|
-
|
141
|
+
|
140
142
|
tags.each do |key, value|
|
141
143
|
next unless mp3tag = tag_mapping[key]
|
142
|
-
|
144
|
+
|
143
145
|
if format = tag_formats[mp3tag]
|
144
|
-
value = format.gsub(/:(\w+)/) do
|
146
|
+
value = format.gsub(/:(\w+)/) do
|
145
147
|
field = $1
|
146
148
|
tags[field.to_sym]
|
147
149
|
end
|
148
150
|
end
|
149
|
-
|
151
|
+
|
150
152
|
target = tag2_fields.include?(key) ? :tag2 : :tag
|
151
153
|
mp3_tags[mp3tag] = { :target => target, :value => value }
|
152
154
|
end
|
153
|
-
|
155
|
+
|
154
156
|
mp3_tags
|
155
157
|
end
|
156
|
-
|
158
|
+
|
157
159
|
def default_encoding
|
158
160
|
'--preset standard'
|
159
161
|
end
|
160
|
-
|
162
|
+
|
161
163
|
def string_fields
|
162
164
|
[:title, :description]
|
163
165
|
end
|
164
|
-
|
166
|
+
|
165
167
|
def tag2_fields
|
166
168
|
[:bpm, :composer, :compilation, :tracktotal, :tracknumber, :disctotal, :discnumber, :tag]
|
167
169
|
end
|
168
|
-
|
170
|
+
|
169
171
|
def tag_formats
|
170
172
|
{
|
171
173
|
:TRCK => ':tracknumber/:tracktotal',
|
data/lib/flac2mp3/version.rb
CHANGED
@@ -12,127 +12,127 @@ describe 'flac2mp3 command' do
|
|
12
12
|
before do
|
13
13
|
Flac2mp3.stub!(:convert)
|
14
14
|
Flac2mp3.stub!(:convert_metadata)
|
15
|
-
|
15
|
+
|
16
16
|
[:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
|
17
17
|
Object.send(:remove_const, const) if Object.const_defined?(const)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'should exist' do
|
22
22
|
lambda { run_command('blah') }.should.not.raise(Errno::ENOENT)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it 'should require a filename' do
|
26
26
|
self.should.receive(:puts) do |output|
|
27
27
|
output.should.match(/usage.+filename/i)
|
28
28
|
end
|
29
29
|
run_command
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it 'should pass the filename to Flac2mp3 for conversion' do
|
33
33
|
Flac2mp3.should.receive(:convert) do |filename, _|
|
34
34
|
filename.should == 'blah'
|
35
35
|
end
|
36
36
|
run_command('blah')
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it 'should pass on a true flac-deletion option if specified on the command line (using --delete)' do
|
40
40
|
Flac2mp3.should.receive(:convert) do |_, options|
|
41
41
|
options[:delete].should == true
|
42
42
|
end
|
43
43
|
run_command('blah', '--delete')
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it 'should pass on a false flac-deletion option if specified on the command line (using --no-delete)' do
|
47
47
|
Flac2mp3.should.receive(:convert) do |_, options|
|
48
48
|
options[:delete].should == false
|
49
49
|
end
|
50
50
|
run_command('blah', '--no-delete')
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it 'should pass on a true flac-deletion option if specified on the command line (using -d)' do
|
54
54
|
Flac2mp3.should.receive(:convert) do |_, options|
|
55
55
|
options[:delete].should == true
|
56
56
|
end
|
57
57
|
run_command('blah', '-d')
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it 'should not pass on any flac-deletion option if nothing specified on the command line' do
|
61
61
|
Flac2mp3.should.receive(:convert) do |_, options|
|
62
62
|
options.should.not.include(:delete)
|
63
63
|
end
|
64
64
|
run_command('blah')
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it 'should pass on a true silence option if specified on the command line (using --silent)' do
|
68
68
|
Flac2mp3.should.receive(:convert) do |_, options|
|
69
69
|
options[:silent].should == true
|
70
70
|
end
|
71
71
|
run_command('blah', '--silent')
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it 'should pass on a true silence option if specified on the command line (using -s)' do
|
75
75
|
Flac2mp3.should.receive(:convert) do |_, options|
|
76
76
|
options[:silent].should == true
|
77
77
|
end
|
78
78
|
run_command('blah', '-s')
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it 'should not pass on any silence option if nothing specified on the command line' do
|
82
82
|
Flac2mp3.should.receive(:convert) do |_, options|
|
83
83
|
options.should.not.include(:silent)
|
84
84
|
end
|
85
85
|
run_command('blah')
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it 'should pass on the encoding option specified on the command line' do
|
89
89
|
Flac2mp3.should.receive(:convert) do |_, options|
|
90
90
|
options[:encoding].should == '--preset fast standard'
|
91
91
|
end
|
92
92
|
run_command('blah', '--encoding', '--preset fast standard')
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it 'should pass on the encoding option specified in shorthand on the command line' do
|
96
96
|
Flac2mp3.should.receive(:convert) do |_, options|
|
97
97
|
options[:encoding].should == '--preset fast standard'
|
98
98
|
end
|
99
99
|
run_command('blah', '-e', '--preset fast standard')
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it 'should pass on no encoding option if none specified on the command line' do
|
103
103
|
Flac2mp3.should.receive(:convert) do |_, options|
|
104
104
|
options.should.not.include(:encoding)
|
105
105
|
end
|
106
106
|
run_command('blah')
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it 'should take a --meta option to convert metadata' do
|
110
110
|
lambda { run_command('--meta', 'blah.flac', 'something.mp3') }.should.not.raise(OptionParser::InvalidOption)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
describe 'when converting metadata' do
|
114
114
|
before do
|
115
115
|
@infile = 'blah.flac'
|
116
116
|
@outfile = 'something.mp3'
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it 'should require two filenames' do
|
120
120
|
self.should.receive(:puts) do |output|
|
121
121
|
output.should.match(/usage.+filename/i)
|
122
122
|
end
|
123
123
|
run_command('--meta', @infile)
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
it 'should pass the filenames to Flac2mp3 for metadata conversion' do
|
127
127
|
Flac2mp3.should.receive(:convert_metadata).with(@infile, @outfile)
|
128
128
|
run_command('--meta', @infile, @outfile)
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
it 'should not attempt to convert any files' do
|
132
132
|
Flac2mp3.should.receive(:convert).never
|
133
133
|
run_command('--meta', @infile, @outfile)
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
it 'should accept a shorthand -m option' do
|
137
137
|
Flac2mp3.should.receive(:convert_metadata).with(@infile, @outfile)
|
138
138
|
run_command('-m', @infile, @outfile)
|
data/spec/flac2mp3_spec.rb
CHANGED
@@ -4,49 +4,49 @@ describe Flac2mp3 do
|
|
4
4
|
before do
|
5
5
|
@flac2mp3 = Flac2mp3.new
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
describe 'when initialized' do
|
9
9
|
before do
|
10
10
|
@options = { :silent => true, :delete => false }
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it 'should accept options' do
|
14
14
|
lambda { Flac2mp3.new(@options) }.should.not.raise(ArgumentError)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'should not require options' do
|
18
18
|
lambda { Flac2mp3.new }.should.not.raise(ArgumentError)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
describe do
|
22
22
|
# unnamed describe block just to give a level of organization
|
23
23
|
# to this subclass-based initialize-behavior testing
|
24
24
|
before do
|
25
25
|
@subclass = Class.new(Flac2mp3) do
|
26
26
|
attr_reader :config_loaded, :options_set, :options
|
27
|
-
|
27
|
+
|
28
28
|
def load_config
|
29
29
|
@config_loaded = true
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def set_options(*args)
|
33
33
|
@options_set = true
|
34
34
|
@options = args
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it 'should load the configuration' do
|
40
40
|
obj = @subclass.new
|
41
41
|
obj.config_loaded.should == true
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it 'should set the options' do
|
45
45
|
obj = @subclass.new(@options)
|
46
46
|
obj.options_set.should == true
|
47
47
|
obj.options.should == [@options]
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
it 'should default to empty options' do
|
51
51
|
obj = @subclass.new
|
52
52
|
obj.options_set.should == true
|
@@ -54,251 +54,251 @@ describe Flac2mp3 do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it 'should load the configuration' do
|
59
59
|
@flac2mp3.should.respond_to(:load_config)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
describe 'loading the configuration' do
|
63
63
|
it 'should look for a config file' do
|
64
64
|
File.should.receive(:read).with(File.expand_path('~/.flac2mp3')).and_return('')
|
65
65
|
@flac2mp3.load_config
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
describe 'when a config file is found' do
|
69
69
|
before do
|
70
70
|
@config = { :silent => true, :delete => false }
|
71
71
|
@contents = @config.to_yaml
|
72
72
|
File.stub!(:read).and_return(@contents)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it 'should parse the file as YAML' do
|
76
76
|
YAML.should.receive(:load).with(@contents)
|
77
77
|
@flac2mp3.load_config
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it 'should store the config' do
|
81
81
|
@flac2mp3.load_config
|
82
82
|
@flac2mp3.config.should == @config
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it 'should convert string keys to symbols' do
|
86
86
|
File.stub!(:read).and_return({ 'silent' => true, 'delete' => false }.to_yaml)
|
87
87
|
@flac2mp3.load_config
|
88
88
|
@flac2mp3.config.should == @config
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
it 'should handle an empty file' do
|
92
92
|
File.stub!(:read).and_return('')
|
93
93
|
@flac2mp3.load_config
|
94
94
|
@flac2mp3.config.should == {}
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it 'should not allow changes to the config' do
|
98
98
|
@flac2mp3.load_config
|
99
99
|
@flac2mp3.config[:some_key] = 'some value'
|
100
100
|
@flac2mp3.config.should == @config
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
describe 'when no config file is found' do
|
105
105
|
before do
|
106
106
|
File.stub!(:read).and_raise(Errno::ENOENT)
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it 'should store an empty config' do
|
110
110
|
Flac2mp3.new.config.should == {}
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
it 'should set options' do
|
116
116
|
@flac2mp3.should.respond_to(:set_options)
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
describe 'setting options' do
|
120
120
|
before do
|
121
121
|
@options = { :silent => true, :delete => false }
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
it 'should accept options' do
|
125
125
|
lambda { @flac2mp3.set_options(:silent => true) }.should.not.raise(ArgumentError)
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
it 'should require options' do
|
129
129
|
lambda { @flac2mp3.set_options }.should.raise(ArgumentError)
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
it 'should accept a hash of options' do
|
133
133
|
lambda { @flac2mp3.set_options(:silent => true) }.should.not.raise(TypeError)
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
it 'should require a hash of options' do
|
137
137
|
lambda { @flac2mp3.set_options('silent') }.should.raise(TypeError)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
it 'should store the options' do
|
141
141
|
@flac2mp3.set_options(@options)
|
142
142
|
@flac2mp3.options.should == @options
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it 'should not allow changes to the options' do
|
146
146
|
@flac2mp3.set_options(@options.dup)
|
147
147
|
@flac2mp3.options[:some_key] = 'some value'
|
148
148
|
@flac2mp3.options.should == @options
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
describe 'querying options' do
|
153
153
|
before do
|
154
154
|
File.stub!(:read).and_return('')
|
155
155
|
@flac2mp3.load_config
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
it 'should indicate the original file should be deleted when a true option is given' do
|
159
159
|
@flac2mp3.set_options(:delete => true)
|
160
160
|
@flac2mp3.delete?.should == true
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
it 'should indicate the original file should not be deleted when a false option is given' do
|
164
164
|
@flac2mp3.set_options(:delete => false)
|
165
165
|
@flac2mp3.delete?.should == false
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
it 'should indicate the original file should not be deleted when no option is given' do
|
169
169
|
@flac2mp3.set_options({})
|
170
170
|
@flac2mp3.delete?.should == false
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
it 'should indicate the conversion should be silent when a true option is given' do
|
174
174
|
@flac2mp3.set_options(:silent => true)
|
175
175
|
@flac2mp3.silent?.should == true
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
it 'should indicate the conversion should not be silent when a false option is given' do
|
179
179
|
@flac2mp3.set_options(:silent => false)
|
180
180
|
@flac2mp3.silent?.should == false
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
it 'should indicate the conversion should not be silent when no option is given' do
|
184
184
|
@flac2mp3.set_options({})
|
185
185
|
@flac2mp3.silent?.should == false
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it 'should store the given encoding' do
|
189
189
|
encoding = '-VAWESOME'
|
190
190
|
@flac2mp3.set_options(:encoding => encoding)
|
191
191
|
@flac2mp3.encoding.should == encoding
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
it 'should default the encoding to --preset standard' do
|
195
195
|
@flac2mp3.set_options({})
|
196
196
|
@flac2mp3.encoding.should == '--preset standard'
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
it 'should use values from the configuration' do
|
200
200
|
config = {:silent => true}
|
201
201
|
File.stub!(:read).and_return(config.to_yaml)
|
202
202
|
Flac2mp3.new.silent?.should == true
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
it 'should override configuration values with options' do
|
206
206
|
config = {:silent => true}
|
207
207
|
File.stub!(:read).and_return(config.to_yaml)
|
208
208
|
Flac2mp3.new(:silent => false).silent?.should == false
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it 'should combine configuration and option values' do
|
212
212
|
config = {:silent => true}
|
213
213
|
File.stub!(:read).and_return(config.to_yaml)
|
214
214
|
flac2mp3 = Flac2mp3.new(:delete => true)
|
215
|
-
|
215
|
+
|
216
216
|
flac2mp3.silent?.should == true
|
217
217
|
flac2mp3.delete?.should == true
|
218
218
|
end
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
it 'should convert' do
|
222
222
|
@flac2mp3.should.respond_to(:convert)
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
describe 'when converting' do
|
226
226
|
before do
|
227
227
|
@filename = 'test.flac'
|
228
228
|
@flac2mp3.stub!(:process_conversion)
|
229
229
|
FileTest.stub!(:file?).and_return(true)
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
it 'should accept a filename' do
|
233
233
|
lambda { @flac2mp3.convert(@filename) }.should.not.raise(ArgumentError)
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
it 'should require a filename' do
|
237
237
|
lambda { @flac2mp3.convert }.should.raise(ArgumentError)
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
it 'should check if the filename belongs to a regular file' do
|
241
241
|
FileTest.should.receive(:file?).with(@filename).and_return(true)
|
242
242
|
@flac2mp3.convert(@filename)
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
describe 'when given a filename belonging to a regular file' do
|
246
246
|
before do
|
247
247
|
FileTest.stub!(:file?).and_return(true)
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
it 'should not error' do
|
251
251
|
lambda { @flac2mp3.convert(@filename) }.should.not.raise(TypeError)
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
it 'should process the conversion' do
|
255
255
|
@flac2mp3.should.receive(:process_conversion).with(@filename)
|
256
256
|
@flac2mp3.convert(@filename)
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
it 'should check if the original file should be deleted' do
|
260
260
|
@flac2mp3.should.receive(:delete?)
|
261
261
|
@flac2mp3.convert(@filename)
|
262
262
|
end
|
263
|
-
|
263
|
+
|
264
264
|
describe 'when the original file should be deleted' do
|
265
265
|
before do
|
266
266
|
@flac2mp3.stub!(:delete?).and_return(true)
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
it 'should delete the original file' do
|
270
270
|
File.should.receive(:delete).with(@filename)
|
271
271
|
@flac2mp3.convert(@filename)
|
272
272
|
end
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
describe 'when the original file should not be deleted' do
|
276
276
|
before do
|
277
277
|
@flac2mp3.stub!(:delete?).and_return(false)
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
it 'should not delete the original file' do
|
281
281
|
File.should.receive(:delete).never
|
282
282
|
@flac2mp3.convert(@filename)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
describe 'when given a filename not belonging to a regular file' do
|
288
288
|
before do
|
289
289
|
FileTest.stub!(:file?).and_return(false)
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it 'should error' do
|
293
293
|
lambda { @flac2mp3.convert(@filename) }.should.raise(TypeError)
|
294
294
|
end
|
295
295
|
end
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
it 'should process conversion' do
|
299
299
|
@flac2mp3.should.respond_to(:process_conversion)
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
describe 'when processing conversion' do
|
303
303
|
before do
|
304
304
|
@filename = 'test.flac'
|
@@ -307,35 +307,35 @@ describe Flac2mp3 do
|
|
307
307
|
@flac2mp3.stub!(:convert_data)
|
308
308
|
@flac2mp3.stub!(:convert_metadata)
|
309
309
|
end
|
310
|
-
|
310
|
+
|
311
311
|
it 'should accept a filename' do
|
312
312
|
lambda { @flac2mp3.process_conversion(@filename) }.should.not.raise(ArgumentError)
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
it 'should require a filename' do
|
316
316
|
lambda { @flac2mp3.process_conversion }.should.raise(ArgumentError)
|
317
317
|
end
|
318
|
-
|
318
|
+
|
319
319
|
it 'get the output filename from the given filename' do
|
320
320
|
@flac2mp3.should.receive(:output_filename).with(@filename)
|
321
321
|
@flac2mp3.process_conversion(@filename)
|
322
322
|
end
|
323
|
-
|
323
|
+
|
324
324
|
it 'should convert data' do
|
325
325
|
@flac2mp3.should.receive(:convert_data).with(@filename, @out_filename)
|
326
326
|
@flac2mp3.process_conversion(@filename)
|
327
327
|
end
|
328
|
-
|
328
|
+
|
329
329
|
it 'should convert metadata' do
|
330
330
|
@flac2mp3.should.receive(:convert_metadata).with(@filename, @out_filename)
|
331
331
|
@flac2mp3.process_conversion(@filename)
|
332
332
|
end
|
333
333
|
end
|
334
|
-
|
334
|
+
|
335
335
|
it 'should provide an output filename' do
|
336
336
|
@flac2mp3.should.respond_to(:output_filename)
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
describe 'providing an output filename' do
|
340
340
|
it 'should accept a filename' do
|
341
341
|
lambda { @flac2mp3.output_filename('blah.flac') }.should.not.raise(ArgumentError)
|
@@ -353,11 +353,11 @@ describe Flac2mp3 do
|
|
353
353
|
@flac2mp3.output_filename('blah').should == 'blah.mp3'
|
354
354
|
end
|
355
355
|
end
|
356
|
-
|
356
|
+
|
357
357
|
it 'should convert data' do
|
358
358
|
@flac2mp3.should.respond_to(:convert_data)
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
describe 'when converting data' do
|
362
362
|
before do
|
363
363
|
@filename = 'test.flac'
|
@@ -368,39 +368,39 @@ describe Flac2mp3 do
|
|
368
368
|
@flac2mp3.stub!(:mp3_command).and_return(@mp3_command)
|
369
369
|
@flac2mp3.stub!(:system)
|
370
370
|
end
|
371
|
-
|
371
|
+
|
372
372
|
it 'should accept a filename and an output filename' do
|
373
373
|
lambda { @flac2mp3.convert_data(@filename, @out_filename) }.should.not.raise(ArgumentError)
|
374
374
|
end
|
375
|
-
|
375
|
+
|
376
376
|
it 'should require an output filename' do
|
377
377
|
lambda { @flac2mp3.convert_data(@filename) }.should.raise(ArgumentError)
|
378
378
|
end
|
379
|
-
|
379
|
+
|
380
380
|
it 'should require a filename' do
|
381
381
|
lambda { @flac2mp3.convert_data }.should.raise(ArgumentError)
|
382
382
|
end
|
383
|
-
|
383
|
+
|
384
384
|
it 'should call the flac command with the given filename' do
|
385
385
|
@flac2mp3.should.receive(:flac_command).with(@filename)
|
386
386
|
@flac2mp3.convert_data(@filename, @out_filename)
|
387
387
|
end
|
388
|
-
|
388
|
+
|
389
389
|
it 'should call the mp3 command with the given output filename' do
|
390
390
|
@flac2mp3.should.receive(:mp3_command).with(@out_filename)
|
391
391
|
@flac2mp3.convert_data(@filename, @out_filename)
|
392
392
|
end
|
393
|
-
|
393
|
+
|
394
394
|
it 'should shell out to the system with the flac and mp3 commands' do
|
395
395
|
@flac2mp3.should.receive(:system).with("#{@flac_command} | #{@mp3_command}")
|
396
396
|
@flac2mp3.convert_data(@filename, @out_filename)
|
397
397
|
end
|
398
398
|
end
|
399
|
-
|
399
|
+
|
400
400
|
it 'should provide a flac command' do
|
401
401
|
@flac2mp3.should.respond_to(:flac_command)
|
402
402
|
end
|
403
|
-
|
403
|
+
|
404
404
|
describe 'when providing a flac command' do
|
405
405
|
before do
|
406
406
|
@filename = 'test.flac'
|
@@ -408,50 +408,50 @@ describe Flac2mp3 do
|
|
408
408
|
@flac2mp3.stub!(:safequote).and_return(@safe_filename)
|
409
409
|
@flac2mp3.stub!(:silent?)
|
410
410
|
end
|
411
|
-
|
411
|
+
|
412
412
|
it 'should accept a filename' do
|
413
413
|
lambda { @flac2mp3.flac_command(@filename) }.should.not.raise(ArgumentError)
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
it 'should require a filename' do
|
417
417
|
lambda { @flac2mp3.flac_command }.should.raise(ArgumentError)
|
418
418
|
end
|
419
|
-
|
419
|
+
|
420
420
|
it 'should safequote the filename' do
|
421
421
|
@flac2mp3.should.receive(:safequote).with(@filename)
|
422
422
|
@flac2mp3.flac_command(@filename)
|
423
423
|
end
|
424
|
-
|
424
|
+
|
425
425
|
it 'should check if the command should be silent' do
|
426
426
|
@flac2mp3.should.receive(:silent?)
|
427
427
|
@flac2mp3.flac_command(@filename)
|
428
428
|
end
|
429
|
-
|
429
|
+
|
430
430
|
describe 'when the command should be silent' do
|
431
431
|
before do
|
432
432
|
@flac2mp3.stub!(:silent?).and_return(true)
|
433
433
|
end
|
434
|
-
|
434
|
+
|
435
435
|
it 'should provide a flac shell command that will be silent' do
|
436
436
|
@flac2mp3.flac_command(@filename).should == "flac --silent --stdout --decode #{@safe_filename}"
|
437
437
|
end
|
438
438
|
end
|
439
|
-
|
439
|
+
|
440
440
|
describe 'when the command should not be silent' do
|
441
441
|
before do
|
442
442
|
@flac2mp3.stub!(:silent?).and_return(false)
|
443
443
|
end
|
444
|
-
|
444
|
+
|
445
445
|
it 'should provide a flac shell command that will not be silent' do
|
446
446
|
@flac2mp3.flac_command(@filename).should == "flac --stdout --decode #{@safe_filename}"
|
447
447
|
end
|
448
448
|
end
|
449
449
|
end
|
450
|
-
|
450
|
+
|
451
451
|
it 'should provide an mp3 command' do
|
452
452
|
@flac2mp3.should.respond_to(:mp3_command)
|
453
453
|
end
|
454
|
-
|
454
|
+
|
455
455
|
describe 'when providing an mp3 command' do
|
456
456
|
before do
|
457
457
|
@filename = 'test.mp3'
|
@@ -461,64 +461,64 @@ describe Flac2mp3 do
|
|
461
461
|
@encoding = '--VAWESOME'
|
462
462
|
@flac2mp3.stub!(:encoding).and_return(@encoding)
|
463
463
|
end
|
464
|
-
|
464
|
+
|
465
465
|
it 'should accept a filename' do
|
466
466
|
lambda { @flac2mp3.mp3_command(@filename) }.should.not.raise(ArgumentError)
|
467
467
|
end
|
468
|
-
|
468
|
+
|
469
469
|
it 'should require a filename' do
|
470
470
|
lambda { @flac2mp3.mp3_command }.should.raise(ArgumentError)
|
471
471
|
end
|
472
|
-
|
472
|
+
|
473
473
|
it 'should safequote the filename' do
|
474
474
|
@flac2mp3.should.receive(:safequote).with(@filename)
|
475
475
|
@flac2mp3.mp3_command(@filename)
|
476
476
|
end
|
477
|
-
|
477
|
+
|
478
478
|
it 'should check if the command should be silent' do
|
479
479
|
@flac2mp3.should.receive(:silent?)
|
480
480
|
@flac2mp3.mp3_command(@filename)
|
481
481
|
end
|
482
|
-
|
482
|
+
|
483
483
|
it 'should check the encoding to use' do
|
484
484
|
@flac2mp3.should.receive(:encoding)
|
485
485
|
@flac2mp3.mp3_command(@filename)
|
486
486
|
end
|
487
|
-
|
487
|
+
|
488
488
|
describe 'when the command should be silent' do
|
489
489
|
before do
|
490
490
|
@flac2mp3.stub!(:silent?).and_return(true)
|
491
491
|
end
|
492
|
-
|
492
|
+
|
493
493
|
it 'should provide an mp3 shell command that will be silent' do
|
494
494
|
@flac2mp3.mp3_command(@filename).should == "lame --silent #{@encoding} - #{@safe_filename}"
|
495
495
|
end
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
describe 'when the command should not be silent' do
|
499
499
|
before do
|
500
500
|
@flac2mp3.stub!(:silent?).and_return(false)
|
501
501
|
end
|
502
|
-
|
502
|
+
|
503
503
|
it 'should provide an mp3 shell command that will not be silent' do
|
504
504
|
@flac2mp3.mp3_command(@filename).should == "lame #{@encoding} - #{@safe_filename}"
|
505
505
|
end
|
506
506
|
end
|
507
507
|
end
|
508
|
-
|
508
|
+
|
509
509
|
it 'should quote filenames safely' do
|
510
510
|
@flac2mp3.should.respond_to(:safequote)
|
511
511
|
end
|
512
|
-
|
512
|
+
|
513
513
|
describe 'when quoting a filename safely' do
|
514
514
|
it 'should accept a filename' do
|
515
515
|
lambda { @flac2mp3.safequote('test.flac') }.should.not.raise(ArgumentError)
|
516
516
|
end
|
517
|
-
|
517
|
+
|
518
518
|
it 'should require a filename' do
|
519
519
|
lambda { @flac2mp3.safequote }.should.raise(ArgumentError)
|
520
520
|
end
|
521
|
-
|
521
|
+
|
522
522
|
it 'should leave alphanumeric characters alone' do
|
523
523
|
@flac2mp3.safequote('abc_123').should == 'abc_123'
|
524
524
|
end
|
@@ -527,11 +527,11 @@ describe Flac2mp3 do
|
|
527
527
|
@flac2mp3.safequote(%q[a-b"c 12'3]).should == %q[a\-b\"c\ 12\'3]
|
528
528
|
end
|
529
529
|
end
|
530
|
-
|
530
|
+
|
531
531
|
it 'should convert metadata' do
|
532
532
|
@flac2mp3.should.respond_to(:convert_metadata)
|
533
533
|
end
|
534
|
-
|
534
|
+
|
535
535
|
describe 'when converting metadata' do
|
536
536
|
before do
|
537
537
|
@filename = 'test.flac'
|
@@ -540,34 +540,34 @@ describe Flac2mp3 do
|
|
540
540
|
@flac2mp3.stub!(:get_flacdata).and_return(@flacdata)
|
541
541
|
@flac2mp3.stub!(:set_mp3data)
|
542
542
|
end
|
543
|
-
|
543
|
+
|
544
544
|
it 'should accept a filename and an output filename' do
|
545
545
|
lambda { @flac2mp3.convert_metadata(@filename, @out_filename) }.should.not.raise(ArgumentError)
|
546
546
|
end
|
547
|
-
|
547
|
+
|
548
548
|
it 'should require an output filename' do
|
549
549
|
lambda { @flac2mp3.convert_metadata(@filename) }.should.raise(ArgumentError)
|
550
550
|
end
|
551
|
-
|
551
|
+
|
552
552
|
it 'should require a filename' do
|
553
553
|
lambda { @flac2mp3.convert_metadata }.should.raise(ArgumentError)
|
554
554
|
end
|
555
|
-
|
555
|
+
|
556
556
|
it 'should get the flac metadata' do
|
557
557
|
@flac2mp3.should.receive(:get_flacdata).with(@filename)
|
558
558
|
@flac2mp3.convert_metadata(@filename, @out_filename)
|
559
559
|
end
|
560
|
-
|
560
|
+
|
561
561
|
it 'should set the mp3 metadata with the flac metadata' do
|
562
562
|
@flac2mp3.should.receive(:set_mp3data).with(@out_filename, @flacdata)
|
563
563
|
@flac2mp3.convert_metadata(@filename, @out_filename)
|
564
564
|
end
|
565
565
|
end
|
566
|
-
|
566
|
+
|
567
567
|
it 'should get flac metadata' do
|
568
568
|
@flac2mp3.should.respond_to(:get_flacdata)
|
569
569
|
end
|
570
|
-
|
570
|
+
|
571
571
|
describe 'when getting flac metadata' do
|
572
572
|
before do
|
573
573
|
@filename = 'test.flac'
|
@@ -575,15 +575,15 @@ describe Flac2mp3 do
|
|
575
575
|
@flacinfo = mock('flac info', :tags => @tags)
|
576
576
|
FlacInfo.stub!(:new).and_return(@flacinfo)
|
577
577
|
end
|
578
|
-
|
578
|
+
|
579
579
|
it 'should accept a filename' do
|
580
580
|
lambda { @flac2mp3.get_flacdata(@filename) }.should.not.raise(ArgumentError)
|
581
581
|
end
|
582
|
-
|
582
|
+
|
583
583
|
it 'should require a filename' do
|
584
584
|
lambda { @flac2mp3.get_flacdata }.should.raise(ArgumentError)
|
585
585
|
end
|
586
|
-
|
586
|
+
|
587
587
|
it 'should create a FlacInfo object' do
|
588
588
|
FlacInfo.should.receive(:new).with(@filename).and_return(@flacinfo)
|
589
589
|
@flac2mp3.get_flacdata(@filename)
|
@@ -593,7 +593,7 @@ describe Flac2mp3 do
|
|
593
593
|
@flacinfo.should.receive(:tags).and_return(@tags)
|
594
594
|
@flac2mp3.get_flacdata(@filename)
|
595
595
|
end
|
596
|
-
|
596
|
+
|
597
597
|
it 'should return a hash of the tag data' do
|
598
598
|
@tags[:artist] = 'blah'
|
599
599
|
@tags[:blah] = 'boo'
|
@@ -604,7 +604,7 @@ describe Flac2mp3 do
|
|
604
604
|
data[:blah].should == 'boo'
|
605
605
|
data[:comment].should == 'hey'
|
606
606
|
end
|
607
|
-
|
607
|
+
|
608
608
|
it 'should convert tags to symbols' do
|
609
609
|
@tags['artist'] = 'blah'
|
610
610
|
@tags['blah'] = 'boo'
|
@@ -619,7 +619,7 @@ describe Flac2mp3 do
|
|
619
619
|
data.should.not.include('blah')
|
620
620
|
data.should.not.include('comment')
|
621
621
|
end
|
622
|
-
|
622
|
+
|
623
623
|
it 'should convert tags to lowercase' do
|
624
624
|
@tags['Artist'] = 'blah'
|
625
625
|
@tags[:BLAH] = 'boo'
|
@@ -634,21 +634,21 @@ describe Flac2mp3 do
|
|
634
634
|
data.should.not.include(:BLAH)
|
635
635
|
data.should.not.include('cOmMeNt')
|
636
636
|
end
|
637
|
-
|
637
|
+
|
638
638
|
it 'should convert values consisting only of digits to actual numbers' do
|
639
639
|
@tags[:track] = '12'
|
640
640
|
|
641
641
|
data = @flac2mp3.get_flacdata(@filename)
|
642
642
|
data[:track].should == 12
|
643
643
|
end
|
644
|
-
|
644
|
+
|
645
645
|
it 'should leave numeric values as numbers' do
|
646
646
|
@tags[:track] = 12
|
647
|
-
|
647
|
+
|
648
648
|
data = @flac2mp3.get_flacdata(@filename)
|
649
649
|
data[:track].should == 12
|
650
650
|
end
|
651
|
-
|
651
|
+
|
652
652
|
it 'should leave numeric titles as strings' do
|
653
653
|
@tags[:title] = '45' # This was my first run-in with this problem, the opening track on Elvis Costello's /When I Was Cruel/
|
654
654
|
|
@@ -676,55 +676,55 @@ describe Flac2mp3 do
|
|
676
676
|
data = @flac2mp3.get_flacdata(@filename)
|
677
677
|
data[:description].should == '1938'
|
678
678
|
end
|
679
|
-
|
679
|
+
|
680
680
|
# iTunes wants ISO-8859-1, and I want my MP3s to display well in iTunes
|
681
|
-
it 'should
|
681
|
+
it 'should result in ISO-8859-1 titles' do
|
682
682
|
@tags[:title] = "L\303\251gende"
|
683
683
|
|
684
684
|
data = @flac2mp3.get_flacdata(@filename)
|
685
|
-
data[:title].should == "L\351gende"
|
685
|
+
data[:title].should == "L\351gende".force_encoding('ISO-8859-1')
|
686
686
|
end
|
687
|
-
|
688
|
-
it 'should
|
687
|
+
|
688
|
+
it 'should result in ISO-8859-1 titles even if the title key is not a simple downcased symbol' do
|
689
689
|
@tags['TITLE'] = "L\303\251gende"
|
690
690
|
|
691
691
|
data = @flac2mp3.get_flacdata(@filename)
|
692
|
-
data[:title].should == "L\351gende"
|
692
|
+
data[:title].should == "L\351gende".force_encoding('ISO-8859-1')
|
693
693
|
end
|
694
|
-
|
695
|
-
it 'should
|
694
|
+
|
695
|
+
it 'should result in ISO-8859-1 artist names' do
|
696
696
|
@tags[:artist] = "St\303\251phane Grappelli"
|
697
697
|
|
698
698
|
data = @flac2mp3.get_flacdata(@filename)
|
699
|
-
data[:artist].should == "St\351phane Grappelli"
|
699
|
+
data[:artist].should == "St\351phane Grappelli".force_encoding('ISO-8859-1')
|
700
700
|
end
|
701
|
-
|
702
|
-
it 'should
|
701
|
+
|
702
|
+
it 'should result in ISO-8859-1 artist names even if the artist key is not a simple downcased symbol' do
|
703
703
|
@tags['ARTIST'] = "St\303\251phane Grappelli"
|
704
704
|
|
705
705
|
data = @flac2mp3.get_flacdata(@filename)
|
706
|
-
data[:artist].should == "St\351phane Grappelli"
|
706
|
+
data[:artist].should == "St\351phane Grappelli".force_encoding('ISO-8859-1')
|
707
707
|
end
|
708
|
-
|
709
|
-
it 'should
|
708
|
+
|
709
|
+
it 'should result in ISO-8859-1 album titles' do
|
710
710
|
@tags[:album] = "Still on Top \342\200\224 The Greatest Hits"
|
711
711
|
|
712
712
|
data = @flac2mp3.get_flacdata(@filename)
|
713
|
-
data[:album].should == "Still on Top - The Greatest Hits" # not a strict conversion, but a transliteration
|
713
|
+
data[:album].should == "Still on Top - The Greatest Hits".force_encoding('ISO-8859-1') # not a strict conversion, but a transliteration
|
714
714
|
end
|
715
|
-
|
716
|
-
it 'should
|
715
|
+
|
716
|
+
it 'should result in ISO-8859-1 album titles even if the album key is not a simple downcased symbol' do
|
717
717
|
@tags['ALBUM'] = "Still on Top \342\200\224 The Greatest Hits"
|
718
718
|
|
719
719
|
data = @flac2mp3.get_flacdata(@filename)
|
720
|
-
data[:album].should == "Still on Top - The Greatest Hits" # not a strict conversion, but a transliteration
|
720
|
+
data[:album].should == "Still on Top - The Greatest Hits".force_encoding('ISO-8859-1') # not a strict conversion, but a transliteration
|
721
721
|
end
|
722
722
|
end
|
723
|
-
|
723
|
+
|
724
724
|
it 'should set mp3 metadata' do
|
725
725
|
@flac2mp3.should.respond_to(:set_mp3data)
|
726
726
|
end
|
727
|
-
|
727
|
+
|
728
728
|
describe 'when setting mp3 metadata' do
|
729
729
|
before do
|
730
730
|
@filename = 'test.mp3'
|
@@ -734,32 +734,32 @@ describe Flac2mp3 do
|
|
734
734
|
@mp3info = mock('mp3 info', :tag => @mp3tags, :tag2 => @mp3tags2)
|
735
735
|
Mp3Info.stub!(:open).and_yield(@mp3info)
|
736
736
|
end
|
737
|
-
|
737
|
+
|
738
738
|
it 'should accept a filename and tag data' do
|
739
739
|
lambda { @flac2mp3.set_mp3data(@filename, {}) }.should.not.raise(ArgumentError)
|
740
740
|
end
|
741
|
-
|
741
|
+
|
742
742
|
it 'should require tag data' do
|
743
743
|
lambda { @flac2mp3.set_mp3data(@filename) }.should.raise(ArgumentError)
|
744
744
|
end
|
745
|
-
|
745
|
+
|
746
746
|
it 'should require a filename' do
|
747
747
|
lambda { @flac2mp3.set_mp3data }.should.raise(ArgumentError)
|
748
748
|
end
|
749
|
-
|
749
|
+
|
750
750
|
it 'should accept a hash of tag data' do
|
751
751
|
lambda { @flac2mp3.set_mp3data(@filename, 'tag data') }.should.raise(TypeError)
|
752
752
|
end
|
753
|
-
|
753
|
+
|
754
754
|
it 'should require a hash of tag data' do
|
755
755
|
lambda { @flac2mp3.set_mp3data(@filename, {}) }.should.not.raise(TypeError)
|
756
756
|
end
|
757
|
-
|
757
|
+
|
758
758
|
it 'should use an Mp3Info object' do
|
759
759
|
Mp3Info.should.receive(:open).with(@filename)
|
760
760
|
@flac2mp3.set_mp3data(@filename, @tags)
|
761
761
|
end
|
762
|
-
|
762
|
+
|
763
763
|
it 'should set tags in the Mp3Info object' do
|
764
764
|
@tags[:album] = 'blah'
|
765
765
|
@tags[:artist] = 'boo'
|
@@ -820,7 +820,7 @@ describe Flac2mp3 do
|
|
820
820
|
|
821
821
|
@flac2mp3.set_mp3data(@filename, @tags)
|
822
822
|
end
|
823
|
-
|
823
|
+
|
824
824
|
it "should use tag2 for 'tag' ('grouping')" do
|
825
825
|
@tags[:tag] = 'one, two, three, oclock'
|
826
826
|
|
@@ -847,12 +847,12 @@ describe Flac2mp3 do
|
|
847
847
|
@flac2mp3.set_mp3data(@filename, @tags)
|
848
848
|
end
|
849
849
|
end
|
850
|
-
|
850
|
+
|
851
851
|
describe 'as a class' do
|
852
852
|
it 'should convert' do
|
853
853
|
Flac2mp3.should.respond_to(:convert)
|
854
854
|
end
|
855
|
-
|
855
|
+
|
856
856
|
describe 'when converting' do
|
857
857
|
before do
|
858
858
|
@filename = 'test.flac'
|
@@ -860,39 +860,39 @@ describe Flac2mp3 do
|
|
860
860
|
@flac2mp3 = mock('flac2mp3', :convert => nil)
|
861
861
|
Flac2mp3.stub!(:new).and_return(@flac2mp3)
|
862
862
|
end
|
863
|
-
|
863
|
+
|
864
864
|
it 'should accept a filename and a hash of options' do
|
865
865
|
lambda { Flac2mp3.convert(@filename, @options) }.should.not.raise(ArgumentError)
|
866
866
|
end
|
867
|
-
|
867
|
+
|
868
868
|
it 'should not require options' do
|
869
869
|
lambda { Flac2mp3.convert(@filename) }.should.not.raise(ArgumentError)
|
870
870
|
end
|
871
|
-
|
871
|
+
|
872
872
|
it 'should require a filename' do
|
873
873
|
lambda { Flac2mp3.convert }.should.raise(ArgumentError)
|
874
874
|
end
|
875
|
-
|
875
|
+
|
876
876
|
it 'should instantiate a new Flac2mp3 object' do
|
877
877
|
Flac2mp3.should.receive(:new).and_return(@flac2mp3)
|
878
878
|
Flac2mp3.convert(@filename)
|
879
879
|
end
|
880
|
-
|
880
|
+
|
881
881
|
it 'should pass the options when instantiating the Flac2mp3 object' do
|
882
882
|
Flac2mp3.should.receive(:new).with(@options).and_return(@flac2mp3)
|
883
883
|
Flac2mp3.convert(@filename, @options)
|
884
884
|
end
|
885
|
-
|
885
|
+
|
886
886
|
it 'should use the Flac2mp3 object to convert the given file' do
|
887
887
|
@flac2mp3.should.receive(:convert).with(@filename)
|
888
888
|
Flac2mp3.convert(@filename)
|
889
889
|
end
|
890
890
|
end
|
891
|
-
|
891
|
+
|
892
892
|
it 'should convert metadata' do
|
893
893
|
Flac2mp3.should.respond_to(:convert_metadata)
|
894
894
|
end
|
895
|
-
|
895
|
+
|
896
896
|
describe 'when converting metadata' do
|
897
897
|
before do
|
898
898
|
@infile = 'test.flac'
|
@@ -900,30 +900,30 @@ describe Flac2mp3 do
|
|
900
900
|
@flac2mp3 = mock('flac2mp3', :convert_metadata => nil)
|
901
901
|
Flac2mp3.stub!(:new).and_return(@flac2mp3)
|
902
902
|
end
|
903
|
-
|
903
|
+
|
904
904
|
it 'should accept two filenames' do
|
905
905
|
lambda { Flac2mp3.convert_metadata(@infile, @outfile) }.should.not.raise(ArgumentError)
|
906
906
|
end
|
907
|
-
|
907
|
+
|
908
908
|
it 'should require two filenames' do
|
909
909
|
lambda { Flac2mp3.convert_metadata(@infile) }.should.raise(ArgumentError)
|
910
910
|
end
|
911
|
-
|
911
|
+
|
912
912
|
it 'should instantiate a new Flac2mp3 object' do
|
913
913
|
Flac2mp3.should.receive(:new).and_return(@flac2mp3)
|
914
914
|
Flac2mp3.convert_metadata(@infile, @outfile)
|
915
915
|
end
|
916
|
-
|
916
|
+
|
917
917
|
it 'should use the Flac2mp3 object to convert the metadata between the given files' do
|
918
918
|
@flac2mp3.should.receive(:convert_metadata).with(@infile, @outfile)
|
919
919
|
Flac2mp3.convert_metadata(@infile, @outfile)
|
920
920
|
end
|
921
921
|
end
|
922
|
-
|
922
|
+
|
923
923
|
it 'should provide a tag mapping' do
|
924
924
|
Flac2mp3.should.respond_to(:tag_mapping)
|
925
925
|
end
|
926
|
-
|
926
|
+
|
927
927
|
describe 'providing a tag mapping' do
|
928
928
|
it 'should return a hash' do
|
929
929
|
Flac2mp3.tag_mapping.should.be.kind_of(Hash)
|
@@ -980,7 +980,7 @@ describe Flac2mp3 do
|
|
980
980
|
it "should map 'compilation' to 'TCMP'" do
|
981
981
|
Flac2mp3.tag_mapping[:compilation].should == :TCMP
|
982
982
|
end
|
983
|
-
|
983
|
+
|
984
984
|
it "should map 'tag' to 'TIT1'" do
|
985
985
|
Flac2mp3.tag_mapping[:tag].should == :TIT1
|
986
986
|
end
|