rtaglib 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +14 -4
- data/README.txt +20 -20
- data/Rakefile +58 -5
- data/ext/{extconf.rb → tagfile/extconf.rb} +1 -1
- data/ext/{rtaglib.c → tagfile/tagfile.c} +90 -41
- data/ext/taglib/extconf.rb +6 -0
- data/ext/taglib/taglib.cxx +17115 -0
- data/swig/Rakefile +33 -0
- data/swig/extconf.rb +6 -0
- data/swig/taglib.i +817 -0
- data/swig/test.rb +266 -0
- data/test/data/440Hz-5sec.flac +0 -0
- data/test/data/440Hz-5sec.mp3 +0 -0
- data/test/data/440Hz-5sec.mpc +0 -0
- data/test/data/440Hz-5sec.ogg +0 -0
- data/test/data/440Hz-5sec.wv +0 -0
- data/test/test_read.rb +12 -11
- data/test/test_taglib.rb +266 -0
- data/test/test_write.rb +41 -7
- metadata +70 -50
- data/ext/Makefile +0 -149
- data/test/data/saw.mp3 +0 -0
data/swig/test.rb
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
if File.exists? File.dirname(__FILE__)+"/taglib.so"
|
3
|
+
require File.dirname(__FILE__)+'/taglib'
|
4
|
+
BASE_DATA=File.dirname(__FILE__)+"/../test/data/"
|
5
|
+
else
|
6
|
+
require File.dirname(__FILE__)+'/../ext/taglib/taglib'
|
7
|
+
BASE_DATA=File.dirname(__FILE__)+"/data/"
|
8
|
+
end
|
9
|
+
require 'fileutils'
|
10
|
+
require 'test/unit'
|
11
|
+
class RtaglibReadTestCase < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@data_dir=BASE_DATA
|
14
|
+
@temp_dir="/tmp/rtaglib"
|
15
|
+
FileUtils.mkdir(@temp_dir) if !File.exists? @temp_dir
|
16
|
+
|
17
|
+
end
|
18
|
+
def teardown
|
19
|
+
Dir.glob(@temp_dir+"/*").each{|f|
|
20
|
+
FileUtils.rm(f)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
def get_copy(original)
|
24
|
+
original=~/.*\.(.+)/
|
25
|
+
ext=$1
|
26
|
+
copy=@temp_dir+"/test_"+sprintf("%06d",rand(10000))+"."+ext
|
27
|
+
FileUtils.copy(original, copy)
|
28
|
+
copy
|
29
|
+
end
|
30
|
+
# Taglib::File test for
|
31
|
+
# - writable?
|
32
|
+
# - open?
|
33
|
+
# - valid?
|
34
|
+
# - seek (with 1 and 2 arguments)
|
35
|
+
# - readBlock
|
36
|
+
# - find (with 1 and 2 arguments)
|
37
|
+
# - lenght
|
38
|
+
def test_file
|
39
|
+
mp3=@data_dir+"440Hz-5sec.mp3"
|
40
|
+
copy=get_copy(mp3)
|
41
|
+
file=Taglib::MPEG_File.new(mp3)
|
42
|
+
assert(file.writable?)
|
43
|
+
assert(file.open?)
|
44
|
+
assert(file.valid?)
|
45
|
+
file.seek(0);
|
46
|
+
expected=sprintf("%c%c%c%c%c%c%c%c%c%c",0x49,0x44,0x33,0x04,0x00,0x80, 0x00,0x00,0x07,0x76)
|
47
|
+
assert_equal(expected,file.readBlock(10))
|
48
|
+
expected=sprintf("%c%c%c%c%c%c%c%c%c%c",0x54,0x49,0x54,0x32,0x00,0x00, 0x00,0x10,0x00,0x00)
|
49
|
+
assert_equal(expected,file.readBlock(10))
|
50
|
+
|
51
|
+
file.seek(-6, Taglib::File::End)
|
52
|
+
expected=sprintf("%c%c%c%c%c%c",0x77,0x61,0x72,0x00,0x01,0x47)
|
53
|
+
assert_equal(expected,file.readBlock(6))
|
54
|
+
|
55
|
+
needle=sprintf("%c%c%c%c%c",0x20,0xF1,0x8A,0xE6,0x63)
|
56
|
+
assert_equal(0x40D,file.find1(needle))
|
57
|
+
needle=sprintf("%c%c%c%c%c",0x22,0x22,0x22,0xE6,0x63)
|
58
|
+
assert_equal(-1,file.find2(needle,0))
|
59
|
+
assert_equal(0x7B46,file.length())
|
60
|
+
|
61
|
+
end
|
62
|
+
# Taglib::FileRef test for
|
63
|
+
# - ::defaultFileExtensions()
|
64
|
+
# - length
|
65
|
+
# - save
|
66
|
+
# - tag: getters and setters for title, artist, album, year, track, genre, comment
|
67
|
+
# - audioproperties: bitrate,channels,sampleRate and channels
|
68
|
+
# - isNull (null?)
|
69
|
+
def test_fileref
|
70
|
+
|
71
|
+
assert_equal(%w{ogg flac oga mp3 mpc wv spx tta}, Taglib::FileRef.defaultFileExtensions())
|
72
|
+
bitrate={'flac'=>168,'wv'=>235,'mp3'=>48,'mpc'=>41,'ogg'=>80}
|
73
|
+
channels={'flac'=>1,'wv'=>1,'mp3'=>1,'mpc'=>2,'ogg'=>1}
|
74
|
+
|
75
|
+
Dir.glob(@data_dir+"/*").each{|f|
|
76
|
+
fr=Taglib::FileRef.new(f)
|
77
|
+
f=~/.+\.(.+)/
|
78
|
+
ext=$1
|
79
|
+
|
80
|
+
assert_equal(5,fr.audioProperties.length, "Error on file #{f}")
|
81
|
+
assert_equal(bitrate[ext],fr.audioProperties.bitrate, "Error on file #{f}")
|
82
|
+
assert_equal(44100,fr.audioProperties.sampleRate, "Error on file #{f}")
|
83
|
+
assert_equal(channels[ext],fr.audioProperties.channels, "Error on file #{f}")
|
84
|
+
|
85
|
+
assert_equal("440Hz Sine Wave",fr.tag().title,"Error on file #{f}")
|
86
|
+
assert_equal("Dr. Lex",fr.tag().artist,"Error on file #{f}")
|
87
|
+
assert_equal("http://www.dr-lex.be/",fr.tag().album,"Error on file #{f}")
|
88
|
+
assert_equal(2008,fr.tag().year,"Error on file #{f}")
|
89
|
+
assert_equal(1,fr.tag().track,"Error on file #{f}")
|
90
|
+
assert_equal("Lo-Fi",fr.tag().genre, "Error on file #{f}")
|
91
|
+
assert_equal("http://www.dr-lex.be/software/testsounds.html", fr.tag().comment,"Error on file #{f}")
|
92
|
+
assert(!fr.null?)
|
93
|
+
}
|
94
|
+
mp3=@data_dir+"440Hz-5sec.mp3"
|
95
|
+
copy=get_copy(mp3)
|
96
|
+
fr2=Taglib::FileRef.new(copy)
|
97
|
+
fr2.tag().title="new title";
|
98
|
+
fr2.tag().artist="new artist";
|
99
|
+
fr2.tag().album="new album";
|
100
|
+
fr2.tag().year=2000;
|
101
|
+
fr2.tag().track=10;
|
102
|
+
fr2.tag().genre="Rock";
|
103
|
+
fr2.tag().comment="new comment";
|
104
|
+
|
105
|
+
fr2.save()
|
106
|
+
copy2=get_copy(copy)
|
107
|
+
fr2.tag().title="sfsd"
|
108
|
+
fr2.save()
|
109
|
+
fr3=Taglib::FileRef.new(copy2)
|
110
|
+
assert_equal("new title",fr3.tag.title)
|
111
|
+
assert_equal("new artist",fr3.tag.artist)
|
112
|
+
assert_equal("new album",fr3.tag.album)
|
113
|
+
assert_equal(2000,fr3.tag.year)
|
114
|
+
assert_equal(10,fr3.tag.track)
|
115
|
+
assert_equal("Rock",fr3.tag.genre)
|
116
|
+
assert_equal("new comment",fr3.tag.comment)
|
117
|
+
|
118
|
+
end
|
119
|
+
def test_flac
|
120
|
+
original=@data_dir+"440Hz-5sec.flac"
|
121
|
+
copy_xiph=get_copy(original)
|
122
|
+
copy_id1=get_copy(original)
|
123
|
+
copy_id2=get_copy(original)
|
124
|
+
flac_xiph=Taglib::FLAC_File.new(copy_xiph,true)
|
125
|
+
flac_id1=Taglib::FLAC_File.new(copy_id1,true)
|
126
|
+
flac_id2=Taglib::FLAC_File.new(copy_id2,true)
|
127
|
+
|
128
|
+
# file
|
129
|
+
assert_equal(34,flac_xiph.streamInfoData.length)
|
130
|
+
assert_equal(105299, flac_xiph.streamLength)
|
131
|
+
# audioproperties
|
132
|
+
ap=flac_xiph.audioProperties
|
133
|
+
assert_equal(5,ap.length)
|
134
|
+
assert_equal(168,ap.bitrate)
|
135
|
+
assert_equal(44100,ap.sampleRate)
|
136
|
+
assert_equal(1,ap.channels)
|
137
|
+
assert_equal(16,ap.sampleWidth)
|
138
|
+
# comments
|
139
|
+
xiph=flac_xiph.xiphComment()
|
140
|
+
xiph.setTitle("xiph")
|
141
|
+
flac_xiph.save()
|
142
|
+
assert_equal("xiph",flac_xiph.tag().title)
|
143
|
+
assert_nil(flac_xiph.ID3v1Tag())
|
144
|
+
assert_nil(flac_xiph.ID3v2Tag())
|
145
|
+
|
146
|
+
id1=flac_id1.ID3v1Tag(true)
|
147
|
+
|
148
|
+
id1.setTitle("id1")
|
149
|
+
flac_id1.save()
|
150
|
+
assert_equal("id1",id1.title)
|
151
|
+
|
152
|
+
assert_not_nil(flac_id1.xiphComment())
|
153
|
+
assert_nil(flac_id1.ID3v2Tag())
|
154
|
+
|
155
|
+
|
156
|
+
id2=flac_id2.ID3v2Tag(true)
|
157
|
+
id2.setTitle("id2")
|
158
|
+
flac_id2.save()
|
159
|
+
assert_equal("id2",id2.title)
|
160
|
+
|
161
|
+
assert_not_nil(flac_id2.xiphComment())
|
162
|
+
assert_nil(flac_id2.ID3v1Tag())
|
163
|
+
end
|
164
|
+
#
|
165
|
+
def test_mpeg
|
166
|
+
original=@data_dir+"440Hz-5sec.mp3"
|
167
|
+
copy=get_copy(original)
|
168
|
+
mp3=Taglib::MPEG_File.new(copy)
|
169
|
+
%w{tag ID3v1Tag ID3v2Tag}.each {|f|
|
170
|
+
assert_equal("440Hz Sine Wave",mp3.send(f).title)
|
171
|
+
}
|
172
|
+
# file
|
173
|
+
# strip only id3v1
|
174
|
+
mp3.strip(Taglib::MPEG_File::ID3v1)
|
175
|
+
assert_nil(mp3.ID3v1Tag)
|
176
|
+
assert_not_nil(mp3.ID3v2Tag)
|
177
|
+
copy=get_copy(original)
|
178
|
+
mp3=Taglib::MPEG_File.new(copy)
|
179
|
+
# strip all
|
180
|
+
mp3.strip()
|
181
|
+
assert_nil(mp3.ID3v1Tag)
|
182
|
+
assert_nil(mp3.ID3v2Tag)
|
183
|
+
|
184
|
+
# properties
|
185
|
+
|
186
|
+
assert_equal(0,mp3.audioProperties.version)
|
187
|
+
assert_equal(3,mp3.audioProperties.layer)
|
188
|
+
assert(!mp3.audioProperties.protectionEnabled)
|
189
|
+
assert_equal(Taglib::MPEG_Header::SingleChannel, mp3.audioProperties.channelMode)
|
190
|
+
assert(!mp3.audioProperties.isCopyrighted)
|
191
|
+
assert(mp3.audioProperties.isOriginal)
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
end
|
196
|
+
# BAD: strip doesn't work
|
197
|
+
def _test_mpc
|
198
|
+
original=@data_dir+"440Hz-5sec.mpc"
|
199
|
+
copy=get_copy(original)
|
200
|
+
fr=Taglib::FileRef.new(copy)
|
201
|
+
fr.tag.title="440Hz Sine Wave"
|
202
|
+
fr.save
|
203
|
+
mpc=Taglib::MPEG_File.new(copy)
|
204
|
+
%w{tag APETag}.each {|f|
|
205
|
+
assert_equal("440Hz Sine Wave",mpc.send(f).title, "#{f} tag")
|
206
|
+
}
|
207
|
+
# file
|
208
|
+
# strip only id3v1
|
209
|
+
mpc.strip(Taglib::MPC_File::ID3v1)
|
210
|
+
mpc.save
|
211
|
+
mpc1=Taglib::MPEG_File.new(copy)
|
212
|
+
|
213
|
+
# assert_nil(mpc1.ID3v1Tag)
|
214
|
+
assert_not_nil(mpc1.APETag)
|
215
|
+
copy=get_copy(original)
|
216
|
+
mpc=Taglib::MPC_File.new(copy)
|
217
|
+
# strip all
|
218
|
+
mpc.strip()
|
219
|
+
mpc.save
|
220
|
+
mpc1=Taglib::MPEG_File.new(copy)
|
221
|
+
|
222
|
+
# assert_nil(mpc1.ID3v1Tag)
|
223
|
+
assert_nil(mpc1.APETag)
|
224
|
+
|
225
|
+
# properties
|
226
|
+
|
227
|
+
assert_equal(0,mp3.audioProperties.version)
|
228
|
+
assert_equal(3,mp3.audioProperties.layer)
|
229
|
+
assert(!mp3.audioProperties.protectionEnabled)
|
230
|
+
assert_equal(Taglib::MPEG_Header::SingleChannel, mp3.audioProperties.channelMode)
|
231
|
+
assert(!mp3.audioProperties.isCopyrighted)
|
232
|
+
assert(mp3.audioProperties.isOriginal)
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
def test_fieldmap
|
241
|
+
fl=Taglib::FieldListMap.new()
|
242
|
+
fl.insert("key",["val1","val2"])
|
243
|
+
assert_equal(["val1","val2"],fl["key"])
|
244
|
+
assert_nil(fl["2"])
|
245
|
+
fl.insert("key2",["val3","val4"])
|
246
|
+
assert_equal({'key'=>["val1","val2"],"key2"=>["val3","val4"]}, fl.hash)
|
247
|
+
assert_equal(fl.size,fl.length)
|
248
|
+
end
|
249
|
+
def test_xiph_comment
|
250
|
+
original=@data_dir+"440Hz-5sec.flac"
|
251
|
+
copy_xiph=get_copy(original)
|
252
|
+
flac_xiph=Taglib::FLAC_File.new(copy_xiph,true)
|
253
|
+
xc=flac_xiph.xiphComment
|
254
|
+
fl=xc.fieldListMap
|
255
|
+
fl.hash.each {|k,v|
|
256
|
+
xc.removeField(k)
|
257
|
+
}
|
258
|
+
assert(xc.empty?)
|
259
|
+
xc.setTitle("T")
|
260
|
+
xc.setArtist("A")
|
261
|
+
xc.addField("c","C1",false)
|
262
|
+
xc.addField("c","C2",false)
|
263
|
+
expected={"TITLE"=>["T"],"ARTIST"=>["A"],"C"=>["C1","C2"]}
|
264
|
+
assert_equal(expected,fl.hash)
|
265
|
+
end
|
266
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test_read.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require File.dirname(__FILE__)+'/../ext/tagfile/tagfile'
|
4
4
|
require 'test/unit'
|
5
|
-
class
|
5
|
+
class RTagFileReadTestCase < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
|
7
|
+
|
8
|
+
@file=::TagFile::File.new(File.dirname(__FILE__)+"/data/440Hz-5sec.mp3")
|
8
9
|
end
|
9
10
|
def test_title()
|
10
|
-
assert_equal("
|
11
|
+
assert_equal("440Hz Sine Wave",@file.title)
|
11
12
|
end
|
12
13
|
def test_artist()
|
13
|
-
assert_equal("
|
14
|
+
assert_equal("Dr. Lex",@file.artist)
|
14
15
|
end
|
15
16
|
def test_album()
|
16
|
-
assert_equal("
|
17
|
+
assert_equal("http://www.dr-lex.be/",@file.album)
|
17
18
|
end
|
18
19
|
def test_genre()
|
19
20
|
assert_equal("Lo-Fi",@file.genre)
|
@@ -22,22 +23,22 @@ class RtaglibTestCase < Test::Unit::TestCase
|
|
22
23
|
assert_equal(1,@file.track)
|
23
24
|
end
|
24
25
|
def test_year()
|
25
|
-
assert_equal(
|
26
|
+
assert_equal(2008,@file.year)
|
26
27
|
end
|
27
28
|
def test_comment()
|
28
|
-
assert_equal("
|
29
|
+
assert_equal("http://www.dr-lex.be/software/testsounds.html",@file.comment)
|
29
30
|
end
|
30
31
|
def test_length()
|
31
|
-
assert_equal(
|
32
|
+
assert_equal(5, @file.length)
|
32
33
|
end
|
33
34
|
def test_bitrate()
|
34
|
-
assert_equal(
|
35
|
+
assert_equal(48, @file.bitrate)
|
35
36
|
end
|
36
37
|
def test_samplerate()
|
37
38
|
assert_equal(44100,@file.samplerate)
|
38
39
|
end
|
39
40
|
def test_channels()
|
40
|
-
assert_equal(
|
41
|
+
assert_equal(1,@file.channels)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
data/test/test_taglib.rb
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
if File.exists? File.dirname(__FILE__)+"/taglib.so"
|
3
|
+
require File.dirname(__FILE__)+'/taglib'
|
4
|
+
BASE_DATA=File.dirname(__FILE__)+"/../test/data/"
|
5
|
+
else
|
6
|
+
require File.dirname(__FILE__)+'/../ext/taglib/taglib'
|
7
|
+
BASE_DATA=File.dirname(__FILE__)+"/data/"
|
8
|
+
end
|
9
|
+
require 'fileutils'
|
10
|
+
require 'test/unit'
|
11
|
+
class RtaglibReadTestCase < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@data_dir=BASE_DATA
|
14
|
+
@temp_dir="/tmp/rtaglib"
|
15
|
+
FileUtils.mkdir(@temp_dir) if !File.exists? @temp_dir
|
16
|
+
|
17
|
+
end
|
18
|
+
def teardown
|
19
|
+
Dir.glob(@temp_dir+"/*").each{|f|
|
20
|
+
FileUtils.rm(f)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
def get_copy(original)
|
24
|
+
original=~/.*\.(.+)/
|
25
|
+
ext=$1
|
26
|
+
copy=@temp_dir+"/test_"+sprintf("%06d",rand(10000))+"."+ext
|
27
|
+
FileUtils.copy(original, copy)
|
28
|
+
copy
|
29
|
+
end
|
30
|
+
# Taglib::File test for
|
31
|
+
# - writable?
|
32
|
+
# - open?
|
33
|
+
# - valid?
|
34
|
+
# - seek (with 1 and 2 arguments)
|
35
|
+
# - readBlock
|
36
|
+
# - find (with 1 and 2 arguments)
|
37
|
+
# - lenght
|
38
|
+
def test_file
|
39
|
+
mp3=@data_dir+"440Hz-5sec.mp3"
|
40
|
+
copy=get_copy(mp3)
|
41
|
+
file=Taglib::MPEG_File.new(mp3)
|
42
|
+
assert(file.writable?)
|
43
|
+
assert(file.open?)
|
44
|
+
assert(file.valid?)
|
45
|
+
file.seek(0);
|
46
|
+
expected=sprintf("%c%c%c%c%c%c%c%c%c%c",0x49,0x44,0x33,0x04,0x00,0x80, 0x00,0x00,0x07,0x76)
|
47
|
+
assert_equal(expected,file.readBlock(10))
|
48
|
+
expected=sprintf("%c%c%c%c%c%c%c%c%c%c",0x54,0x49,0x54,0x32,0x00,0x00, 0x00,0x10,0x00,0x00)
|
49
|
+
assert_equal(expected,file.readBlock(10))
|
50
|
+
|
51
|
+
file.seek(-6, Taglib::File::End)
|
52
|
+
expected=sprintf("%c%c%c%c%c%c",0x77,0x61,0x72,0x00,0x01,0x47)
|
53
|
+
assert_equal(expected,file.readBlock(6))
|
54
|
+
|
55
|
+
needle=sprintf("%c%c%c%c%c",0x20,0xF1,0x8A,0xE6,0x63)
|
56
|
+
assert_equal(0x40D,file.find1(needle))
|
57
|
+
needle=sprintf("%c%c%c%c%c",0x22,0x22,0x22,0xE6,0x63)
|
58
|
+
assert_equal(-1,file.find2(needle,0))
|
59
|
+
assert_equal(0x7B46,file.length())
|
60
|
+
|
61
|
+
end
|
62
|
+
# Taglib::FileRef test for
|
63
|
+
# - ::defaultFileExtensions()
|
64
|
+
# - length
|
65
|
+
# - save
|
66
|
+
# - tag: getters and setters for title, artist, album, year, track, genre, comment
|
67
|
+
# - audioproperties: bitrate,channels,sampleRate and channels
|
68
|
+
# - isNull (null?)
|
69
|
+
def test_fileref
|
70
|
+
|
71
|
+
assert_equal(%w{ogg flac oga mp3 mpc wv spx tta}, Taglib::FileRef.defaultFileExtensions())
|
72
|
+
bitrate={'flac'=>168,'wv'=>235,'mp3'=>48,'mpc'=>41,'ogg'=>80}
|
73
|
+
channels={'flac'=>1,'wv'=>1,'mp3'=>1,'mpc'=>2,'ogg'=>1}
|
74
|
+
|
75
|
+
Dir.glob(@data_dir+"/*").each{|f|
|
76
|
+
fr=Taglib::FileRef.new(f)
|
77
|
+
f=~/.+\.(.+)/
|
78
|
+
ext=$1
|
79
|
+
|
80
|
+
assert_equal(5,fr.audioProperties.length, "Error on file #{f}")
|
81
|
+
assert_equal(bitrate[ext],fr.audioProperties.bitrate, "Error on file #{f}")
|
82
|
+
assert_equal(44100,fr.audioProperties.sampleRate, "Error on file #{f}")
|
83
|
+
assert_equal(channels[ext],fr.audioProperties.channels, "Error on file #{f}")
|
84
|
+
|
85
|
+
assert_equal("440Hz Sine Wave",fr.tag().title,"Error on file #{f}")
|
86
|
+
assert_equal("Dr. Lex",fr.tag().artist,"Error on file #{f}")
|
87
|
+
assert_equal("http://www.dr-lex.be/",fr.tag().album,"Error on file #{f}")
|
88
|
+
assert_equal(2008,fr.tag().year,"Error on file #{f}")
|
89
|
+
assert_equal(1,fr.tag().track,"Error on file #{f}")
|
90
|
+
assert_equal("Lo-Fi",fr.tag().genre, "Error on file #{f}")
|
91
|
+
assert_equal("http://www.dr-lex.be/software/testsounds.html", fr.tag().comment,"Error on file #{f}")
|
92
|
+
assert(!fr.null?)
|
93
|
+
}
|
94
|
+
mp3=@data_dir+"440Hz-5sec.mp3"
|
95
|
+
copy=get_copy(mp3)
|
96
|
+
fr2=Taglib::FileRef.new(copy)
|
97
|
+
fr2.tag().title="new title";
|
98
|
+
fr2.tag().artist="new artist";
|
99
|
+
fr2.tag().album="new album";
|
100
|
+
fr2.tag().year=2000;
|
101
|
+
fr2.tag().track=10;
|
102
|
+
fr2.tag().genre="Rock";
|
103
|
+
fr2.tag().comment="new comment";
|
104
|
+
|
105
|
+
fr2.save()
|
106
|
+
copy2=get_copy(copy)
|
107
|
+
fr2.tag().title="sfsd"
|
108
|
+
fr2.save()
|
109
|
+
fr3=Taglib::FileRef.new(copy2)
|
110
|
+
assert_equal("new title",fr3.tag.title)
|
111
|
+
assert_equal("new artist",fr3.tag.artist)
|
112
|
+
assert_equal("new album",fr3.tag.album)
|
113
|
+
assert_equal(2000,fr3.tag.year)
|
114
|
+
assert_equal(10,fr3.tag.track)
|
115
|
+
assert_equal("Rock",fr3.tag.genre)
|
116
|
+
assert_equal("new comment",fr3.tag.comment)
|
117
|
+
|
118
|
+
end
|
119
|
+
def test_flac
|
120
|
+
original=@data_dir+"440Hz-5sec.flac"
|
121
|
+
copy_xiph=get_copy(original)
|
122
|
+
copy_id1=get_copy(original)
|
123
|
+
copy_id2=get_copy(original)
|
124
|
+
flac_xiph=Taglib::FLAC_File.new(copy_xiph,true)
|
125
|
+
flac_id1=Taglib::FLAC_File.new(copy_id1,true)
|
126
|
+
flac_id2=Taglib::FLAC_File.new(copy_id2,true)
|
127
|
+
|
128
|
+
# file
|
129
|
+
assert_equal(34,flac_xiph.streamInfoData.length)
|
130
|
+
assert_equal(105299, flac_xiph.streamLength)
|
131
|
+
# audioproperties
|
132
|
+
ap=flac_xiph.audioProperties
|
133
|
+
assert_equal(5,ap.length)
|
134
|
+
assert_equal(168,ap.bitrate)
|
135
|
+
assert_equal(44100,ap.sampleRate)
|
136
|
+
assert_equal(1,ap.channels)
|
137
|
+
assert_equal(16,ap.sampleWidth)
|
138
|
+
# comments
|
139
|
+
xiph=flac_xiph.xiphComment()
|
140
|
+
xiph.setTitle("xiph")
|
141
|
+
flac_xiph.save()
|
142
|
+
assert_equal("xiph",flac_xiph.tag().title)
|
143
|
+
assert_nil(flac_xiph.ID3v1Tag())
|
144
|
+
assert_nil(flac_xiph.ID3v2Tag())
|
145
|
+
|
146
|
+
id1=flac_id1.ID3v1Tag(true)
|
147
|
+
|
148
|
+
id1.setTitle("id1")
|
149
|
+
flac_id1.save()
|
150
|
+
assert_equal("id1",id1.title)
|
151
|
+
|
152
|
+
assert_not_nil(flac_id1.xiphComment())
|
153
|
+
assert_nil(flac_id1.ID3v2Tag())
|
154
|
+
|
155
|
+
|
156
|
+
id2=flac_id2.ID3v2Tag(true)
|
157
|
+
id2.setTitle("id2")
|
158
|
+
flac_id2.save()
|
159
|
+
assert_equal("id2",id2.title)
|
160
|
+
|
161
|
+
assert_not_nil(flac_id2.xiphComment())
|
162
|
+
assert_nil(flac_id2.ID3v1Tag())
|
163
|
+
end
|
164
|
+
#
|
165
|
+
def test_mpeg
|
166
|
+
original=@data_dir+"440Hz-5sec.mp3"
|
167
|
+
copy=get_copy(original)
|
168
|
+
mp3=Taglib::MPEG_File.new(copy)
|
169
|
+
%w{tag ID3v1Tag ID3v2Tag}.each {|f|
|
170
|
+
assert_equal("440Hz Sine Wave",mp3.send(f).title)
|
171
|
+
}
|
172
|
+
# file
|
173
|
+
# strip only id3v1
|
174
|
+
mp3.strip(Taglib::MPEG_File::ID3v1)
|
175
|
+
assert_nil(mp3.ID3v1Tag)
|
176
|
+
assert_not_nil(mp3.ID3v2Tag)
|
177
|
+
copy=get_copy(original)
|
178
|
+
mp3=Taglib::MPEG_File.new(copy)
|
179
|
+
# strip all
|
180
|
+
mp3.strip()
|
181
|
+
assert_nil(mp3.ID3v1Tag)
|
182
|
+
assert_nil(mp3.ID3v2Tag)
|
183
|
+
|
184
|
+
# properties
|
185
|
+
|
186
|
+
assert_equal(0,mp3.audioProperties.version)
|
187
|
+
assert_equal(3,mp3.audioProperties.layer)
|
188
|
+
assert(!mp3.audioProperties.protectionEnabled)
|
189
|
+
assert_equal(Taglib::MPEG_Header::SingleChannel, mp3.audioProperties.channelMode)
|
190
|
+
assert(!mp3.audioProperties.isCopyrighted)
|
191
|
+
assert(mp3.audioProperties.isOriginal)
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
end
|
196
|
+
# BAD: strip doesn't work
|
197
|
+
def _test_mpc
|
198
|
+
original=@data_dir+"440Hz-5sec.mpc"
|
199
|
+
copy=get_copy(original)
|
200
|
+
fr=Taglib::FileRef.new(copy)
|
201
|
+
fr.tag.title="440Hz Sine Wave"
|
202
|
+
fr.save
|
203
|
+
mpc=Taglib::MPEG_File.new(copy)
|
204
|
+
%w{tag APETag}.each {|f|
|
205
|
+
assert_equal("440Hz Sine Wave",mpc.send(f).title, "#{f} tag")
|
206
|
+
}
|
207
|
+
# file
|
208
|
+
# strip only id3v1
|
209
|
+
mpc.strip(Taglib::MPC_File::ID3v1)
|
210
|
+
mpc.save
|
211
|
+
mpc1=Taglib::MPEG_File.new(copy)
|
212
|
+
|
213
|
+
# assert_nil(mpc1.ID3v1Tag)
|
214
|
+
assert_not_nil(mpc1.APETag)
|
215
|
+
copy=get_copy(original)
|
216
|
+
mpc=Taglib::MPC_File.new(copy)
|
217
|
+
# strip all
|
218
|
+
mpc.strip()
|
219
|
+
mpc.save
|
220
|
+
mpc1=Taglib::MPEG_File.new(copy)
|
221
|
+
|
222
|
+
# assert_nil(mpc1.ID3v1Tag)
|
223
|
+
assert_nil(mpc1.APETag)
|
224
|
+
|
225
|
+
# properties
|
226
|
+
|
227
|
+
assert_equal(0,mp3.audioProperties.version)
|
228
|
+
assert_equal(3,mp3.audioProperties.layer)
|
229
|
+
assert(!mp3.audioProperties.protectionEnabled)
|
230
|
+
assert_equal(Taglib::MPEG_Header::SingleChannel, mp3.audioProperties.channelMode)
|
231
|
+
assert(!mp3.audioProperties.isCopyrighted)
|
232
|
+
assert(mp3.audioProperties.isOriginal)
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
def test_fieldmap
|
241
|
+
fl=Taglib::FieldListMap.new()
|
242
|
+
fl.insert("key",["val1","val2"])
|
243
|
+
assert_equal(["val1","val2"],fl["key"])
|
244
|
+
assert_nil(fl["2"])
|
245
|
+
fl.insert("key2",["val3","val4"])
|
246
|
+
assert_equal({'key'=>["val1","val2"],"key2"=>["val3","val4"]}, fl.hash)
|
247
|
+
assert_equal(fl.size,fl.length)
|
248
|
+
end
|
249
|
+
def test_xiph_comment
|
250
|
+
original=@data_dir+"440Hz-5sec.flac"
|
251
|
+
copy_xiph=get_copy(original)
|
252
|
+
flac_xiph=Taglib::FLAC_File.new(copy_xiph,true)
|
253
|
+
xc=flac_xiph.xiphComment
|
254
|
+
fl=xc.fieldListMap
|
255
|
+
fl.hash.each {|k,v|
|
256
|
+
xc.removeField(k)
|
257
|
+
}
|
258
|
+
assert(xc.empty?)
|
259
|
+
xc.setTitle("T")
|
260
|
+
xc.setArtist("A")
|
261
|
+
xc.addField("c","C1",false)
|
262
|
+
xc.addField("c","C2",false)
|
263
|
+
expected={"TITLE"=>["T"],"ARTIST"=>["A"],"C"=>["C1","C2"]}
|
264
|
+
assert_equal(expected,fl.hash)
|
265
|
+
end
|
266
|
+
end
|