taglib-ruby 1.1.0 → 1.1.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/Guardfile +4 -2
- data/README.md +55 -35
- data/Rakefile +5 -5
- data/docs/taglib/aiff.rb +0 -3
- data/docs/taglib/base.rb +0 -4
- data/docs/taglib/flac.rb +1 -3
- data/docs/taglib/id3v2.rb +1 -1
- data/docs/taglib/mp4.rb +2 -4
- data/docs/taglib/mpeg.rb +0 -1
- data/docs/taglib/ogg.rb +0 -4
- data/docs/taglib/vorbis.rb +0 -1
- data/docs/taglib/wav.rb +0 -4
- data/ext/extconf_common.rb +24 -28
- data/ext/taglib_aiff/extconf.rb +2 -0
- data/ext/taglib_aiff/taglib_aiff_wrap.cxx +217 -178
- data/ext/taglib_base/extconf.rb +2 -0
- data/ext/taglib_base/includes.i +1 -0
- data/ext/taglib_base/taglib_base_wrap.cxx +233 -191
- data/ext/taglib_flac/extconf.rb +2 -0
- data/ext/taglib_flac/taglib_flac_wrap.cxx +228 -189
- data/ext/taglib_flac_picture/extconf.rb +2 -0
- data/ext/taglib_flac_picture/taglib_flac_picture_wrap.cxx +210 -168
- data/ext/taglib_id3v1/extconf.rb +2 -0
- data/ext/taglib_id3v1/taglib_id3v1_wrap.cxx +223 -182
- data/ext/taglib_id3v2/extconf.rb +2 -0
- data/ext/taglib_id3v2/taglib_id3v2_wrap.cxx +429 -407
- data/ext/taglib_mp4/extconf.rb +2 -0
- data/ext/taglib_mp4/taglib_mp4_wrap.cxx +295 -260
- data/ext/taglib_mpeg/extconf.rb +2 -0
- data/ext/taglib_mpeg/taglib_mpeg_wrap.cxx +243 -206
- data/ext/taglib_ogg/extconf.rb +2 -0
- data/ext/taglib_ogg/taglib_ogg_wrap.cxx +214 -171
- data/ext/taglib_vorbis/extconf.rb +2 -0
- data/ext/taglib_vorbis/taglib_vorbis_wrap.cxx +217 -178
- data/ext/taglib_wav/extconf.rb +2 -0
- data/ext/taglib_wav/taglib_wav_wrap.cxx +217 -178
- data/lib/taglib/aiff.rb +2 -0
- data/lib/taglib/base.rb +3 -1
- data/lib/taglib/flac.rb +2 -0
- data/lib/taglib/id3v1.rb +2 -0
- data/lib/taglib/id3v2.rb +2 -0
- data/lib/taglib/mp4.rb +10 -13
- data/lib/taglib/mpeg.rb +2 -0
- data/lib/taglib/ogg.rb +2 -0
- data/lib/taglib/version.rb +3 -1
- data/lib/taglib/vorbis.rb +2 -0
- data/lib/taglib/wav.rb +2 -1
- data/lib/taglib.rb +4 -3
- data/taglib-ruby.gemspec +164 -163
- data/tasks/docs_coverage.rake +10 -8
- data/tasks/ext.rake +26 -25
- data/tasks/gemspec_check.rake +6 -4
- data/tasks/swig.rake +10 -11
- data/test/aiff_examples_test.rb +8 -13
- data/test/aiff_file_test.rb +29 -29
- data/test/aiff_file_write_test.rb +19 -20
- data/test/base_test.rb +4 -2
- data/test/data/add-relative-volume.cpp +7 -3
- data/test/data/flac-create.cpp +15 -5
- data/test/data/get_picture_data.cpp +5 -1
- data/test/data/id3v1-create.cpp +6 -3
- data/test/data/mp4-create.cpp +12 -4
- data/test/data/vorbis-create.cpp +12 -5
- data/test/data/wav-create.cpp +18 -3
- data/test/file_test.rb +7 -5
- data/test/fileref_open_test.rb +12 -10
- data/test/fileref_properties_test.rb +6 -4
- data/test/fileref_write_test.rb +14 -13
- data/test/flac_file_test.rb +32 -27
- data/test/flac_file_write_test.rb +17 -18
- data/test/flac_picture_memory_test.rb +13 -17
- data/test/helper.rb +3 -1
- data/test/id3v1_genres_test.rb +14 -12
- data/test/id3v1_tag_test.rb +7 -5
- data/test/id3v2_frames_test.rb +34 -34
- data/test/id3v2_header_test.rb +14 -13
- data/test/id3v2_memory_test.rb +21 -20
- data/test/id3v2_relative_volume_test.rb +11 -9
- data/test/id3v2_tag_test.rb +16 -14
- data/test/id3v2_unicode_test.rb +12 -10
- data/test/id3v2_unknown_frames_test.rb +7 -5
- data/test/id3v2_write_test.rb +28 -29
- data/test/mp4_file_test.rb +27 -26
- data/test/mp4_file_write_test.rb +12 -13
- data/test/mp4_items_test.rb +78 -79
- data/test/mpeg_file_test.rb +32 -30
- data/test/tag_test.rb +5 -3
- data/test/unicode_filename_test.rb +7 -7
- data/test/vorbis_file_test.rb +14 -12
- data/test/vorbis_tag_test.rb +46 -44
- data/test/wav_examples_test.rb +8 -16
- data/test/wav_file_test.rb +29 -29
- data/test/wav_file_write_test.rb +22 -23
- metadata +19 -18
data/test/id3v2_frames_test.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2Frames < Test::Unit::TestCase
|
|
@@ -9,28 +11,28 @@ class TestID3v2Frames < Test::Unit::TestCase
|
|
|
9
11
|
# itself would still be reachable. The reason is because
|
|
10
12
|
# TagLib::MPEG::File owns the TagLib::ID3v2::Tag and automatically
|
|
11
13
|
# deletes it in its destructor.
|
|
12
|
-
@file = TagLib::MPEG::File.new(
|
|
13
|
-
|
|
14
|
+
@file = TagLib::MPEG::File.new('test/data/sample.mp3', read_properties)
|
|
15
|
+
_picture_file = File.open('test/data/globe_east_540.jpg', 'rb') do |f|
|
|
14
16
|
@picture_data = f.read
|
|
15
17
|
end
|
|
16
18
|
@tag = @file.id3v2_tag
|
|
17
19
|
@frames = @tag.frame_list
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
should
|
|
22
|
+
should 'be complete' do
|
|
21
23
|
assert_not_nil @frames
|
|
22
24
|
assert_equal 11, @frames.size
|
|
23
25
|
frame = @frames.first
|
|
24
|
-
assert_equal
|
|
26
|
+
assert_equal 'Dummy Title', frame.to_string
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
should
|
|
28
|
-
ids = @frames.collect
|
|
29
|
-
assert_equal [
|
|
30
|
-
|
|
29
|
+
should 'be enumerable' do
|
|
30
|
+
ids = @frames.collect(&:frame_id)
|
|
31
|
+
assert_equal %w[TIT2 TPE1 TALB TRCK TDRC
|
|
32
|
+
COMM COMM TCON TXXX COMM APIC], ids
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
should
|
|
35
|
+
should 'be automatically converted' do
|
|
34
36
|
apic = @tag.frame_list('APIC').first
|
|
35
37
|
comm = @tag.frame_list('COMM').first
|
|
36
38
|
tit2 = @tag.frame_list('TIT2').first
|
|
@@ -41,53 +43,51 @@ class TestID3v2Frames < Test::Unit::TestCase
|
|
|
41
43
|
assert_equal TagLib::ID3v2::UserTextIdentificationFrame, txxx.class
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
should
|
|
46
|
+
should 'not fail for nil String' do
|
|
45
47
|
assert_equal [], @tag.frame_list(nil)
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
should
|
|
50
|
+
should 'be removable' do
|
|
49
51
|
assert_equal 11, @tag.frame_list.size
|
|
50
52
|
tit2 = @tag.frame_list('TIT2').first
|
|
51
53
|
@tag.remove_frame(tit2)
|
|
52
54
|
assert_equal 10, @tag.frame_list.size
|
|
53
55
|
begin
|
|
54
56
|
tit2.to_string
|
|
55
|
-
flunk(
|
|
56
|
-
rescue => e
|
|
57
|
-
assert_equal
|
|
57
|
+
flunk('Should have raised ObjectPreviouslyDeleted.')
|
|
58
|
+
rescue StandardError => e
|
|
59
|
+
assert_equal 'ObjectPreviouslyDeleted', e.class.to_s
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
61
|
-
should
|
|
63
|
+
should 'be removable by ID' do
|
|
62
64
|
frames = @tag.frame_list
|
|
63
65
|
@tag.remove_frames('COMM')
|
|
64
66
|
tit2 = frames.find { |f| f.frame_id == 'TIT2' }
|
|
65
67
|
# Other frames should still be accessible
|
|
66
|
-
assert_equal
|
|
68
|
+
assert_equal 'Dummy Title', tit2.to_s
|
|
67
69
|
end
|
|
68
70
|
|
|
69
|
-
context
|
|
71
|
+
context 'APIC frame' do
|
|
70
72
|
setup do
|
|
71
73
|
@apic = @tag.frame_list('APIC').first
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
should
|
|
76
|
+
should 'have a type' do
|
|
75
77
|
assert_equal TagLib::ID3v2::AttachedPictureFrame::FrontCover, @apic.type
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
should
|
|
79
|
-
assert_equal
|
|
80
|
+
should 'have a description' do
|
|
81
|
+
assert_equal 'Blue Marble', @apic.description
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
should
|
|
83
|
-
assert_equal
|
|
84
|
+
should 'have a mime type' do
|
|
85
|
+
assert_equal 'image/jpeg', @apic.mime_type
|
|
84
86
|
end
|
|
85
87
|
|
|
86
|
-
should
|
|
87
|
-
assert_equal
|
|
88
|
-
if HAVE_ENCODING
|
|
89
|
-
assert_equal @picture_data.encoding, @apic.picture.encoding
|
|
90
|
-
end
|
|
88
|
+
should 'have picture bytes' do
|
|
89
|
+
assert_equal 61_649, @apic.picture.size
|
|
90
|
+
assert_equal @picture_data.encoding, @apic.picture.encoding if HAVE_ENCODING
|
|
91
91
|
assert_equal @picture_data, @apic.picture
|
|
92
92
|
end
|
|
93
93
|
end
|
|
@@ -156,22 +156,22 @@ class TestID3v2Frames < Test::Unit::TestCase
|
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
context
|
|
159
|
+
context 'TXXX frame' do
|
|
160
160
|
setup do
|
|
161
161
|
@txxx_frame = @tag.frame_list('TXXX').first
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
should
|
|
164
|
+
should 'exist' do
|
|
165
165
|
assert_not_nil @txxx_frame
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
-
should
|
|
169
|
-
expected =
|
|
170
|
-
|
|
168
|
+
should 'have to_s' do
|
|
169
|
+
expected = /\[MusicBrainz Album Id\].* 992dc19a-5631-40f5-b252-fbfedbc328a9/
|
|
170
|
+
assert_match expected, @txxx_frame.to_string
|
|
171
171
|
end
|
|
172
172
|
|
|
173
|
-
should
|
|
174
|
-
assert_equal [
|
|
173
|
+
should 'have field_list' do
|
|
174
|
+
assert_equal ['MusicBrainz Album Id', '992dc19a-5631-40f5-b252-fbfedbc328a9'], @txxx_frame.field_list
|
|
175
175
|
end
|
|
176
176
|
end
|
|
177
177
|
|
data/test/id3v2_header_test.rb
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2Header < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The sample.mp3 file' do
|
|
5
7
|
setup do
|
|
6
8
|
read_properties = false
|
|
7
|
-
@file = TagLib::MPEG::File.new(
|
|
9
|
+
@file = TagLib::MPEG::File.new('test/data/sample.mp3', read_properties)
|
|
8
10
|
@tag = @file.id3v2_tag
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
should
|
|
13
|
+
should 'have a ID3v2 header' do
|
|
12
14
|
assert_not_nil @tag.header
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
context
|
|
17
|
+
context 'header' do
|
|
16
18
|
setup do
|
|
17
19
|
@header = @tag.header
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
should
|
|
22
|
+
should 'have a major version' do
|
|
21
23
|
assert_equal 3, @header.major_version
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
should
|
|
26
|
+
should 'have a revision number' do
|
|
25
27
|
assert_equal 0, @header.revision_number
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
should
|
|
29
|
-
assert_equal
|
|
30
|
+
should 'have a tag size' do
|
|
31
|
+
assert_equal 63_478, @header.tag_size
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
should
|
|
34
|
+
should 'not have a footer' do
|
|
33
35
|
assert_equal false, @header.footer_present
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
should
|
|
38
|
+
should 'not have an extended header' do
|
|
37
39
|
assert_equal false, @header.extended_header
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
context
|
|
41
|
-
|
|
42
|
+
context 'changing the major version' do
|
|
42
43
|
setup do
|
|
43
44
|
@header.major_version = 4
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
should
|
|
47
|
+
should 'have a different major verson' do
|
|
47
48
|
assert_equal 4, @header.major_version
|
|
48
49
|
end
|
|
49
50
|
|
data/test/id3v2_memory_test.rb
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2Memory < Test::Unit::TestCase
|
|
4
|
-
|
|
5
6
|
N = 1000
|
|
6
7
|
|
|
7
|
-
context
|
|
8
|
+
context 'TagLib::ID3v2' do
|
|
8
9
|
setup do
|
|
9
|
-
@file = TagLib::MPEG::File.new(
|
|
10
|
+
@file = TagLib::MPEG::File.new('test/data/sample.mp3', false)
|
|
10
11
|
@tag = @file.id3v2_tag
|
|
11
|
-
@apic = @tag.frame_list(
|
|
12
|
+
@apic = @tag.frame_list('APIC').first
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
should
|
|
15
|
+
should 'not corrupt memory with FrameList' do
|
|
15
16
|
N.times do
|
|
16
17
|
@tag.frame_list
|
|
17
18
|
end
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
should
|
|
21
|
+
should 'not corrupt memory with ByteVector' do
|
|
21
22
|
data = nil
|
|
22
23
|
N.times do
|
|
23
24
|
data = @apic.picture
|
|
@@ -27,32 +28,32 @@ class TestID3v2Memory < Test::Unit::TestCase
|
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
should
|
|
31
|
+
should 'not corrupt memory with StringList' do
|
|
31
32
|
txxx = @tag.frame_list('TXXX').first
|
|
32
33
|
N.times do
|
|
33
34
|
txxx.field_list
|
|
34
35
|
end
|
|
35
36
|
N.times do
|
|
36
|
-
txxx.field_list = [
|
|
37
|
+
txxx.field_list = %w[one two three]
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
should
|
|
41
|
+
should 'not segfault when tag is deleted along with file' do
|
|
41
42
|
@file = nil
|
|
42
43
|
begin
|
|
43
44
|
N.times do
|
|
44
45
|
GC.start
|
|
45
46
|
@tag.title
|
|
46
47
|
end
|
|
47
|
-
rescue => e
|
|
48
|
-
assert_equal
|
|
48
|
+
rescue StandardError => e
|
|
49
|
+
assert_equal 'ObjectPreviouslyDeleted', e.class.to_s
|
|
49
50
|
else
|
|
50
|
-
raise
|
|
51
|
+
raise 'GC did not delete file, unsure if test was successful.'
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
should
|
|
55
|
-
file = TagLib::MPEG::File.new(
|
|
55
|
+
should 'not segfault when audio properties are deleted along with file' do
|
|
56
|
+
file = TagLib::MPEG::File.new('test/data/crash.mp3', true)
|
|
56
57
|
properties = file.audio_properties
|
|
57
58
|
file.close
|
|
58
59
|
begin
|
|
@@ -60,20 +61,20 @@ class TestID3v2Memory < Test::Unit::TestCase
|
|
|
60
61
|
GC.start
|
|
61
62
|
properties.bitrate
|
|
62
63
|
end
|
|
63
|
-
rescue => e
|
|
64
|
-
assert_equal
|
|
64
|
+
rescue StandardError => e
|
|
65
|
+
assert_equal 'ObjectPreviouslyDeleted', e.class.to_s
|
|
65
66
|
else
|
|
66
|
-
raise
|
|
67
|
+
raise 'GC did not delete file, unsure if test was successful.'
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
70
|
|
|
70
|
-
should
|
|
71
|
+
should 'not throw when adding frame via Tag.add_frame' do
|
|
71
72
|
tcom = TagLib::ID3v2::TextIdentificationFrame.new('TCOM', TagLib::String::Latin1)
|
|
72
|
-
tcom.text =
|
|
73
|
+
tcom.text = 'Some composer'
|
|
73
74
|
@tag.add_frame tcom
|
|
74
75
|
# the following leads to an ObjectPreviouslyDeleted error (see Issue #8)
|
|
75
76
|
assert_nothing_raised do
|
|
76
|
-
@tag.frame_list.find { |fr| 'TCOM'
|
|
77
|
+
@tag.frame_list.find { |fr| fr.frame_id == 'TCOM' }
|
|
77
78
|
end
|
|
78
79
|
end
|
|
79
80
|
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2RelativeVolumeFrame < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The relative-volume.mp3 RVA2 frame' do
|
|
5
7
|
setup do
|
|
6
|
-
@file = TagLib::MPEG::File.new(
|
|
8
|
+
@file = TagLib::MPEG::File.new('test/data/relative-volume.mp3')
|
|
7
9
|
@tag = @file.id3v2_tag
|
|
8
10
|
@rv = @tag.frame_list('RVA2').first
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
should
|
|
13
|
+
should 'exist' do
|
|
12
14
|
assert_not_nil @rv
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
should
|
|
17
|
+
should 'have channels' do
|
|
16
18
|
expected = [TagLib::ID3v2::RelativeVolumeFrame::MasterVolume, TagLib::ID3v2::RelativeVolumeFrame::Subwoofer]
|
|
17
19
|
assert_equal expected, @rv.channels
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
should
|
|
22
|
+
should 'have volume adjustments' do
|
|
21
23
|
assert_equal 512, @rv.volume_adjustment_index
|
|
22
24
|
assert_equal 1.0, @rv.volume_adjustment
|
|
23
25
|
assert_equal 1024, @rv.volume_adjustment_index(TagLib::ID3v2::RelativeVolumeFrame::Subwoofer)
|
|
24
26
|
assert_equal 2.0, @rv.volume_adjustment(TagLib::ID3v2::RelativeVolumeFrame::Subwoofer)
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
should
|
|
29
|
+
should 'have peak volumes' do
|
|
28
30
|
master_pv = @rv.peak_volume
|
|
29
31
|
assert_equal 8, master_pv.bits_representing_peak
|
|
30
32
|
assert_equal 0b01000001.chr, master_pv.peak_volume
|
|
@@ -34,17 +36,17 @@ class TestID3v2RelativeVolumeFrame < Test::Unit::TestCase
|
|
|
34
36
|
assert_equal 0b00111111.chr, subwoofer_pv.peak_volume
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
should
|
|
39
|
+
should 'accept new volume adjustments' do
|
|
38
40
|
@rv.set_volume_adjustment_index(2048, TagLib::ID3v2::RelativeVolumeFrame::FrontCentre)
|
|
39
41
|
assert_equal 2048, @rv.volume_adjustment_index(TagLib::ID3v2::RelativeVolumeFrame::FrontCentre)
|
|
40
42
|
@rv.set_volume_adjustment(4.0, TagLib::ID3v2::RelativeVolumeFrame::FrontLeft)
|
|
41
43
|
assert_equal 4.0, @rv.volume_adjustment(TagLib::ID3v2::RelativeVolumeFrame::FrontLeft)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
should
|
|
46
|
+
should 'accept new peak volumes' do
|
|
45
47
|
pv = TagLib::ID3v2::PeakVolume.new
|
|
46
48
|
assert_equal 0, pv.bits_representing_peak
|
|
47
|
-
assert_equal
|
|
49
|
+
assert_equal '', pv.peak_volume
|
|
48
50
|
pv.bits_representing_peak = 6
|
|
49
51
|
pv.peak_volume = 0b110111.chr
|
|
50
52
|
@rv.set_peak_volume(pv, TagLib::ID3v2::RelativeVolumeFrame::BackLeft)
|
data/test/id3v2_tag_test.rb
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2Tag < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The sample.mp3 file' do
|
|
5
7
|
setup do
|
|
6
8
|
read_properties = false
|
|
7
|
-
@file = TagLib::MPEG::File.new(
|
|
9
|
+
@file = TagLib::MPEG::File.new('test/data/sample.mp3', read_properties)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
should
|
|
12
|
+
should 'have an ID3v2 tag' do
|
|
11
13
|
assert_not_nil @file.id3v2_tag
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
context
|
|
16
|
+
context 'tag' do
|
|
15
17
|
setup do
|
|
16
18
|
@tag = @file.id3v2_tag
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
should
|
|
21
|
+
should 'have basic properties' do
|
|
20
22
|
assert_equal 'Dummy Title', @tag.title
|
|
21
23
|
assert_equal 'Dummy Artist', @tag.artist
|
|
22
24
|
assert_equal 'Dummy Album', @tag.album
|
|
@@ -34,24 +36,24 @@ class TestID3v2Tag < Test::Unit::TestCase
|
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
context
|
|
39
|
+
context 'A new ID3v2::Tag' do
|
|
38
40
|
setup do
|
|
39
41
|
@tag = TagLib::ID3v2::Tag.new
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
should
|
|
44
|
+
should 'be empty' do
|
|
43
45
|
assert @tag.empty?
|
|
44
46
|
end
|
|
45
47
|
|
|
46
|
-
should
|
|
47
|
-
assert_equal
|
|
48
|
-
assert_equal
|
|
49
|
-
assert_equal
|
|
50
|
-
assert_equal
|
|
51
|
-
assert_equal
|
|
48
|
+
should 'have empty string attributes' do
|
|
49
|
+
assert_equal '', @tag.title
|
|
50
|
+
assert_equal '', @tag.artist
|
|
51
|
+
assert_equal '', @tag.album
|
|
52
|
+
assert_equal '', @tag.comment
|
|
53
|
+
assert_equal '', @tag.genre
|
|
52
54
|
end
|
|
53
55
|
|
|
54
|
-
should
|
|
56
|
+
should 'have 0 for numeric attributes' do
|
|
55
57
|
assert_equal 0, @tag.track
|
|
56
58
|
assert_equal 0, @tag.year
|
|
57
59
|
end
|
data/test/id3v2_unicode_test.rb
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2Unicode < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The unicode.mp3 file' do
|
|
5
7
|
setup do
|
|
6
8
|
read_properties = false
|
|
7
|
-
@file = TagLib::MPEG::File.new(
|
|
9
|
+
@file = TagLib::MPEG::File.new('test/data/unicode.mp3', read_properties)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
should
|
|
12
|
+
should 'have an ID3v2 tag' do
|
|
11
13
|
assert_not_nil @file.id3v2_tag
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
if HAVE_ENCODING
|
|
15
|
-
context
|
|
17
|
+
context 'tag' do
|
|
16
18
|
setup do
|
|
17
19
|
@tag = @file.id3v2_tag
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
should
|
|
21
|
-
assert_equal
|
|
22
|
+
should 'return strings in the right encoding' do
|
|
23
|
+
assert_equal 'UTF-8', @tag.title.encoding.to_s
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
should
|
|
26
|
+
should 'convert strings to the right encoding' do
|
|
25
27
|
# Unicode Snowman in UTF-16
|
|
26
|
-
utf16_encoded = "\x26\x03"
|
|
27
|
-
utf16_encoded.force_encoding(
|
|
28
|
+
utf16_encoded = "\x26\x03".dup # mutable
|
|
29
|
+
utf16_encoded.force_encoding('UTF-16BE')
|
|
28
30
|
|
|
29
31
|
# It should be converted here
|
|
30
32
|
@tag.title = utf16_encoded
|
|
@@ -33,7 +35,7 @@ class TestID3v2Unicode < Test::Unit::TestCase
|
|
|
33
35
|
|
|
34
36
|
# In order for == to work, they have to be in the same
|
|
35
37
|
# encoding
|
|
36
|
-
utf8_encoded = utf16_encoded.encode(
|
|
38
|
+
utf8_encoded = utf16_encoded.encode('UTF-8')
|
|
37
39
|
assert_equal utf8_encoded, result
|
|
38
40
|
end
|
|
39
41
|
end
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestID3v2UnknownFrames < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'UnknownFrame' do
|
|
5
7
|
setup do
|
|
6
8
|
read_properties = false
|
|
7
|
-
@file = TagLib::MPEG::File.new(
|
|
9
|
+
@file = TagLib::MPEG::File.new('test/data/sample.mp3', read_properties)
|
|
8
10
|
@tag = @file.id3v2_tag
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
should
|
|
12
|
-
f = TagLib::ID3v2::UnknownFrame.new(
|
|
13
|
+
should 'should be returned with correct class' do
|
|
14
|
+
f = TagLib::ID3v2::UnknownFrame.new('TDAT')
|
|
13
15
|
assert_not_nil f
|
|
14
16
|
@tag.add_frame(f)
|
|
15
|
-
frames = @tag.frame_list(
|
|
17
|
+
frames = @tag.frame_list('TDAT')
|
|
16
18
|
tdat = frames.first
|
|
17
19
|
assert_not_nil tdat
|
|
18
20
|
# By looking at ID alone, it would have returned a
|
data/test/id3v2_write_test.rb
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
require 'fileutils'
|
|
4
6
|
|
|
5
7
|
class TestID3v2Write < Test::Unit::TestCase
|
|
8
|
+
SAMPLE_FILE = 'test/data/sample.mp3'
|
|
9
|
+
OUTPUT_FILE = 'test/data/output.mp3'
|
|
10
|
+
PICTURE_FILE = 'test/data/globe_east_540.jpg'
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
PICTURE_FILE = "test/data/globe_east_540.jpg"
|
|
10
|
-
|
|
11
|
-
def reloaded
|
|
12
|
-
TagLib::MPEG::File.open(OUTPUT_FILE, false) do |file|
|
|
13
|
-
yield file
|
|
14
|
-
end
|
|
12
|
+
def reloaded(&block)
|
|
13
|
+
TagLib::MPEG::File.open(OUTPUT_FILE, false, &block)
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
context
|
|
16
|
+
context 'TagLib::MPEG::File' do
|
|
18
17
|
setup do
|
|
19
18
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
|
20
19
|
@file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
should
|
|
22
|
+
should 'be able to strip the tag' do
|
|
24
23
|
assert_not_nil @file.id3v2_tag
|
|
25
24
|
success = @file.strip
|
|
26
25
|
assert success
|
|
@@ -34,7 +33,7 @@ class TestID3v2Write < Test::Unit::TestCase
|
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
35
|
|
|
37
|
-
should
|
|
36
|
+
should 'be able to save only ID3v2 tag' do
|
|
38
37
|
assert_not_nil @file.id3v2_tag
|
|
39
38
|
assert_not_nil @file.id3v1_tag
|
|
40
39
|
@file.save(TagLib::MPEG::File::ID3v2)
|
|
@@ -54,7 +53,7 @@ class TestID3v2Write < Test::Unit::TestCase
|
|
|
54
53
|
end
|
|
55
54
|
end
|
|
56
55
|
|
|
57
|
-
should
|
|
56
|
+
should 'be able to save ID3v2.3' do
|
|
58
57
|
success = @file.save(TagLib::MPEG::File::ID3v2, true, 3)
|
|
59
58
|
assert_equal true, success
|
|
60
59
|
@file.close
|
|
@@ -64,38 +63,38 @@ class TestID3v2Write < Test::Unit::TestCase
|
|
|
64
63
|
f.read(5)
|
|
65
64
|
end
|
|
66
65
|
# 3 stands for v2.3
|
|
67
|
-
s = "ID3
|
|
66
|
+
s = "ID3#{3.chr}#{0.chr}"
|
|
68
67
|
assert_equal s, header
|
|
69
68
|
end
|
|
70
69
|
|
|
71
|
-
should
|
|
70
|
+
should 'be able to set fields to nil' do
|
|
72
71
|
tag = @file.id3v2_tag
|
|
73
72
|
tag.title = nil
|
|
74
73
|
assert_equal [], tag.frame_list('TIT2')
|
|
75
74
|
end
|
|
76
75
|
|
|
77
|
-
context
|
|
76
|
+
context 'with a fresh tag' do
|
|
78
77
|
setup do
|
|
79
78
|
@file.strip
|
|
80
79
|
@tag = @file.id3v2_tag(true)
|
|
81
80
|
end
|
|
82
81
|
|
|
83
|
-
should
|
|
82
|
+
should 'be able to create a new tag' do
|
|
84
83
|
assert_not_nil @tag
|
|
85
84
|
assert_equal 0, @tag.frame_list.size
|
|
86
85
|
end
|
|
87
86
|
|
|
88
|
-
should
|
|
87
|
+
should 'be able to save it' do
|
|
89
88
|
success = @file.save
|
|
90
89
|
assert success
|
|
91
90
|
end
|
|
92
91
|
|
|
93
|
-
should
|
|
92
|
+
should 'be able to add a new frame to it and read it back' do
|
|
94
93
|
picture_data = File.open(PICTURE_FILE, 'rb') { |f| f.read }
|
|
95
94
|
|
|
96
95
|
apic = TagLib::ID3v2::AttachedPictureFrame.new
|
|
97
|
-
apic.mime_type =
|
|
98
|
-
apic.description =
|
|
96
|
+
apic.mime_type = 'image/jpeg'
|
|
97
|
+
apic.description = 'desc'
|
|
99
98
|
apic.text_encoding = TagLib::String::UTF8
|
|
100
99
|
apic.picture = picture_data
|
|
101
100
|
apic.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
|
|
@@ -108,16 +107,16 @@ class TestID3v2Write < Test::Unit::TestCase
|
|
|
108
107
|
@file = nil
|
|
109
108
|
|
|
110
109
|
written_file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
|
|
111
|
-
written_apic = written_file.id3v2_tag.frame_list(
|
|
112
|
-
assert_equal
|
|
113
|
-
assert_equal
|
|
110
|
+
written_apic = written_file.id3v2_tag.frame_list('APIC').first
|
|
111
|
+
assert_equal 'image/jpeg', written_apic.mime_type
|
|
112
|
+
assert_equal 'desc', written_apic.description
|
|
114
113
|
assert_equal picture_data, written_apic.picture
|
|
115
114
|
written_file.close
|
|
116
115
|
end
|
|
117
116
|
|
|
118
|
-
should
|
|
119
|
-
tit2 = TagLib::ID3v2::TextIdentificationFrame.new(
|
|
120
|
-
texts = [
|
|
117
|
+
should 'be able to set field_list' do
|
|
118
|
+
tit2 = TagLib::ID3v2::TextIdentificationFrame.new('TIT2', TagLib::String::UTF8)
|
|
119
|
+
texts = %w[one two]
|
|
121
120
|
tit2.field_list = texts
|
|
122
121
|
assert_equal texts, tit2.field_list
|
|
123
122
|
@tag.add_frame(tit2)
|
|
@@ -125,14 +124,14 @@ class TestID3v2Write < Test::Unit::TestCase
|
|
|
125
124
|
assert success
|
|
126
125
|
end
|
|
127
126
|
|
|
128
|
-
should
|
|
129
|
-
tit2 = TagLib::ID3v2::TextIdentificationFrame.new(
|
|
127
|
+
should 'not fail when field_list is nil' do
|
|
128
|
+
tit2 = TagLib::ID3v2::TextIdentificationFrame.new('TIT2', TagLib::String::UTF8)
|
|
130
129
|
tit2.field_list = nil
|
|
131
130
|
assert_equal [], tit2.field_list
|
|
132
131
|
end
|
|
133
132
|
|
|
134
133
|
if HAVE_ENCODING
|
|
135
|
-
should
|
|
134
|
+
should 'be able to set unicode fields' do
|
|
136
135
|
# Hello, Unicode Snowman (not in Latin1)
|
|
137
136
|
text = "Hello, \u{2603}"
|
|
138
137
|
|