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
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
require 'fileutils'
|
|
3
5
|
|
|
4
6
|
class TestUnicodeFilename < Test::Unit::TestCase
|
|
5
|
-
SRC_FILE =
|
|
7
|
+
SRC_FILE = 'test/data/vorbis.oga'
|
|
6
8
|
# That's "hello-" followed by "ni hao" in UTF-8
|
|
7
|
-
DST_FILE = "test/data/hello-\xE4\xBD\xA0\xE5\xA5\xBD.oga"
|
|
9
|
+
DST_FILE = "test/data/hello-\xE4\xBD\xA0\xE5\xA5\xBD.oga".dup # mutable
|
|
8
10
|
|
|
9
|
-
context
|
|
11
|
+
context 'TagLib::FileRef' do
|
|
10
12
|
setup do
|
|
11
|
-
if HAVE_ENCODING
|
|
12
|
-
DST_FILE.force_encoding('UTF-8')
|
|
13
|
-
end
|
|
13
|
+
DST_FILE.force_encoding('UTF-8') if HAVE_ENCODING
|
|
14
14
|
FileUtils.cp SRC_FILE, DST_FILE
|
|
15
15
|
@fileref = TagLib::FileRef.new(DST_FILE, false)
|
|
16
16
|
@tag = @fileref.tag
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
should
|
|
19
|
+
should 'be possible to read' do
|
|
20
20
|
assert_not_nil @tag
|
|
21
21
|
assert_equal 'Title', @tag.title
|
|
22
22
|
end
|
data/test/vorbis_file_test.rb
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestVorbisFile < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The vorbis.oga file' do
|
|
5
7
|
setup do
|
|
6
|
-
@file = TagLib::Ogg::Vorbis::File.new(
|
|
8
|
+
@file = TagLib::Ogg::Vorbis::File.new('test/data/vorbis.oga')
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
should
|
|
11
|
+
should 'have a tag' do
|
|
10
12
|
tag = @file.tag
|
|
11
13
|
assert_not_nil tag
|
|
12
14
|
assert_equal TagLib::Ogg::XiphComment, tag.class
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
context
|
|
17
|
+
context 'audio properties' do
|
|
16
18
|
setup do
|
|
17
19
|
@properties = @file.audio_properties
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
should
|
|
22
|
+
should 'exist' do
|
|
21
23
|
assert_not_nil @properties
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
should
|
|
26
|
+
should 'contain basic information' do
|
|
25
27
|
assert_equal 0, @properties.length_in_seconds # file is short
|
|
26
|
-
|
|
28
|
+
assert_includes [371, 76], @properties.bitrate
|
|
27
29
|
assert_equal 44100, @properties.sample_rate
|
|
28
30
|
assert_equal 2, @properties.channels
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
should
|
|
33
|
+
should 'contain vorbis-specific information' do
|
|
32
34
|
assert_equal 0, @properties.vorbis_version
|
|
33
35
|
assert_equal 0, @properties.bitrate_maximum
|
|
34
36
|
assert_equal 64000, @properties.bitrate_nominal
|
|
@@ -42,13 +44,13 @@ class TestVorbisFile < Test::Unit::TestCase
|
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
context
|
|
46
|
-
should
|
|
47
|
+
context 'TagLib::Ogg::Vorbis::File' do
|
|
48
|
+
should 'have open method' do
|
|
47
49
|
title = nil
|
|
48
|
-
TagLib::Ogg::Vorbis::File.open(
|
|
50
|
+
TagLib::Ogg::Vorbis::File.open('test/data/vorbis.oga', false) do |file|
|
|
49
51
|
title = file.tag.title
|
|
50
52
|
end
|
|
51
|
-
assert_equal
|
|
53
|
+
assert_equal 'Title', title
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
data/test/vorbis_tag_test.rb
CHANGED
|
@@ -1,118 +1,120 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class TestVorbisTag < Test::Unit::TestCase
|
|
4
|
-
context
|
|
6
|
+
context 'The vorbis.oga file tag' do
|
|
5
7
|
setup do
|
|
6
|
-
@file = TagLib::Ogg::Vorbis::File.new(
|
|
8
|
+
@file = TagLib::Ogg::Vorbis::File.new('test/data/vorbis.oga')
|
|
7
9
|
@tag = @file.tag
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
should
|
|
11
|
-
assert_equal
|
|
12
|
-
assert_equal
|
|
13
|
-
assert_equal
|
|
12
|
+
should 'contain basic tag information' do
|
|
13
|
+
assert_equal 'Title', @tag.title
|
|
14
|
+
assert_equal 'Artist', @tag.artist
|
|
15
|
+
assert_equal 'Album', @tag.album
|
|
14
16
|
# Use DESCRIPTION if it exists, otherwise COMMENT.
|
|
15
|
-
assert_equal
|
|
16
|
-
assert_equal
|
|
17
|
+
assert_equal 'Test file', @tag.comment
|
|
18
|
+
assert_equal 'Pop', @tag.genre
|
|
17
19
|
assert_equal 2011, @tag.year
|
|
18
20
|
assert_equal 7, @tag.track
|
|
19
21
|
assert_equal false, @tag.empty?
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
should
|
|
24
|
+
should 'have contains? method' do
|
|
23
25
|
assert @tag.contains?('TITLE')
|
|
24
26
|
assert !@tag.contains?('DOESNTEXIST')
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
should
|
|
29
|
+
should 'have field_count' do
|
|
28
30
|
assert_equal 18, @tag.field_count
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
should
|
|
32
|
-
assert_equal
|
|
33
|
+
should 'have vendor_id' do
|
|
34
|
+
assert_equal 'Xiph.Org libVorbis I 20101101 (Schaufenugget)', @tag.vendor_id
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
context
|
|
37
|
+
context 'fields' do
|
|
36
38
|
setup do
|
|
37
39
|
@fields = @tag.field_list_map
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
should
|
|
42
|
+
should 'exist' do
|
|
41
43
|
assert_not_nil @fields
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
should
|
|
45
|
-
assert_equal [
|
|
46
|
+
should 'be usable as a Hash' do
|
|
47
|
+
assert_equal ['Title'], @fields['TITLE']
|
|
46
48
|
assert_nil @fields['DOESNTEXIST']
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
should
|
|
50
|
-
assert_equal [
|
|
51
|
+
should 'be able to return more than one value for a key' do
|
|
52
|
+
assert_equal %w[A B], @fields['MULTIPLE']
|
|
51
53
|
end
|
|
52
54
|
end
|
|
53
55
|
|
|
54
|
-
should
|
|
55
|
-
@tag.add_field('TITLE',
|
|
56
|
-
assert_equal [
|
|
56
|
+
should 'support add_field with replace' do
|
|
57
|
+
@tag.add_field('TITLE', 'New Title')
|
|
58
|
+
assert_equal ['New Title'], @tag.field_list_map['TITLE']
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
should
|
|
61
|
+
should 'support add_field without replace' do
|
|
60
62
|
replace = false
|
|
61
|
-
@tag.add_field('TITLE',
|
|
62
|
-
assert_equal [
|
|
63
|
+
@tag.add_field('TITLE', 'Additional Title', replace)
|
|
64
|
+
assert_equal ['Title', 'Additional Title'], @tag.field_list_map['TITLE']
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
should
|
|
67
|
+
should 'support remove_fields' do
|
|
66
68
|
assert @tag.contains?('MULTIPLE')
|
|
67
69
|
@tag.remove_fields('MULTIPLE')
|
|
68
70
|
refute @tag.contains?('MULTIPLE')
|
|
69
71
|
end
|
|
70
72
|
|
|
71
|
-
should
|
|
73
|
+
should 'support remove_all_fields' do
|
|
72
74
|
refute_equal 0, @tag.field_count
|
|
73
|
-
@tag.remove_all_fields
|
|
75
|
+
@tag.remove_all_fields
|
|
74
76
|
# remove_all_fields() do not remove pictures
|
|
75
77
|
assert_equal 1, @tag.field_count
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
should
|
|
80
|
+
should 'have pictures' do
|
|
79
81
|
refute_empty @tag.picture_list
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
context
|
|
84
|
+
context 'first picture' do
|
|
83
85
|
setup do
|
|
84
86
|
@picture = @tag.picture_list.first
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
should
|
|
89
|
+
should 'be a TagLib::FLAC::Picture,' do
|
|
88
90
|
assert_equal TagLib::FLAC::Picture, @picture.class
|
|
89
91
|
end
|
|
90
92
|
|
|
91
|
-
should
|
|
93
|
+
should 'have meta-data' do
|
|
92
94
|
assert_equal TagLib::FLAC::Picture::FrontCover, @picture.type
|
|
93
|
-
assert_equal
|
|
94
|
-
assert_equal
|
|
95
|
+
assert_equal 'image/jpeg', @picture.mime_type
|
|
96
|
+
assert_equal 'Globe', @picture.description
|
|
95
97
|
assert_equal 90, @picture.width
|
|
96
98
|
assert_equal 90, @picture.height
|
|
97
99
|
assert_equal 24, @picture.color_depth
|
|
98
100
|
assert_equal 0, @picture.num_colors
|
|
99
101
|
end
|
|
100
102
|
|
|
101
|
-
should
|
|
102
|
-
picture_data = File.open(
|
|
103
|
+
should 'have data' do
|
|
104
|
+
picture_data = File.open('test/data/globe_east_90.jpg', 'rb') { |f| f.read }
|
|
103
105
|
assert_equal picture_data, @picture.data
|
|
104
106
|
end
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
should
|
|
109
|
+
should 'support removing a picture' do
|
|
108
110
|
refute_empty @tag.picture_list
|
|
109
111
|
@tag.remove_picture(@tag.picture_list.first)
|
|
110
112
|
assert_empty @tag.picture_list
|
|
111
113
|
end
|
|
112
114
|
|
|
113
|
-
should
|
|
115
|
+
should 'support removing all pictures' do
|
|
114
116
|
refute_empty @tag.picture_list
|
|
115
|
-
@tag.remove_all_pictures
|
|
117
|
+
@tag.remove_all_pictures
|
|
116
118
|
assert_empty @tag.picture_list
|
|
117
119
|
end
|
|
118
120
|
|
|
@@ -122,12 +124,12 @@ class TestVorbisTag < Test::Unit::TestCase
|
|
|
122
124
|
end
|
|
123
125
|
end
|
|
124
126
|
|
|
125
|
-
context
|
|
126
|
-
should
|
|
127
|
-
refute TagLib::Ogg::XiphComment
|
|
128
|
-
refute TagLib::Ogg::XiphComment
|
|
129
|
-
refute TagLib::Ogg::XiphComment
|
|
130
|
-
assert TagLib::Ogg::XiphComment
|
|
127
|
+
context 'The XiphComment class' do
|
|
128
|
+
should 'support check_key' do
|
|
129
|
+
refute TagLib::Ogg::XiphComment.check_key('')
|
|
130
|
+
refute TagLib::Ogg::XiphComment.check_key('something=')
|
|
131
|
+
refute TagLib::Ogg::XiphComment.check_key('something~')
|
|
132
|
+
assert TagLib::Ogg::XiphComment.check_key('something')
|
|
131
133
|
end
|
|
132
134
|
end
|
|
133
135
|
end
|
data/test/wav_examples_test.rb
CHANGED
|
@@ -1,42 +1,34 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class WAVExamples < Test::Unit::TestCase
|
|
6
|
+
DATA_FILE_PREFIX = 'test/data/wav-'
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
context "TagLib::RIFF::WAV::File" do
|
|
8
|
-
|
|
9
|
-
should "Run TagLib::RIFF::WAV::File examples" do
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
context 'TagLib::RIFF::WAV::File' do
|
|
9
|
+
should 'Run TagLib::RIFF::WAV::File examples' do
|
|
12
10
|
# Reading the title
|
|
13
|
-
|
|
14
11
|
title = TagLib::RIFF::WAV::File.open("#{DATA_FILE_PREFIX}sample.wav") do |file|
|
|
15
12
|
file.tag.title
|
|
16
13
|
end
|
|
17
14
|
|
|
18
15
|
# Reading WAV-specific audio properties
|
|
19
|
-
|
|
20
16
|
TagLib::RIFF::WAV::File.open("#{DATA_FILE_PREFIX}sample.wav") do |file|
|
|
21
|
-
file.audio_properties.sample_rate
|
|
17
|
+
file.audio_properties.sample_rate #=> 8
|
|
22
18
|
end
|
|
23
19
|
|
|
24
20
|
# Saving ID3v2 cover-art to disk
|
|
25
|
-
|
|
26
21
|
TagLib::RIFF::WAV::File.open("#{DATA_FILE_PREFIX}sample.wav") do |file|
|
|
27
22
|
id3v2_tag = file.tag
|
|
28
23
|
cover = id3v2_tag.frame_list('APIC').first
|
|
29
24
|
ext = cover.mime_type.rpartition('/')[2]
|
|
30
|
-
File.open("#{DATA_FILE_PREFIX}cover-art.#{ext}",
|
|
25
|
+
File.open("#{DATA_FILE_PREFIX}cover-art.#{ext}", 'wb') { |f| f.write cover.picture }
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
|
|
34
28
|
# checks
|
|
35
|
-
assert_equal
|
|
29
|
+
assert_equal 'WAV Dummy Track Title', title
|
|
36
30
|
assert_equal true, File.exist?("#{DATA_FILE_PREFIX}cover-art.jpeg")
|
|
37
31
|
FileUtils.rm("#{DATA_FILE_PREFIX}cover-art.jpeg")
|
|
38
32
|
end
|
|
39
|
-
|
|
40
33
|
end
|
|
41
|
-
|
|
42
34
|
end
|
data/test/wav_file_test.rb
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class WAVFileTest < Test::Unit::TestCase
|
|
6
|
+
SAMPLE_FILE = 'test/data/wav-sample.wav'
|
|
7
|
+
PICTURE_FILE = 'test/data/globe_east_540.jpg'
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
PICTURE_FILE = "test/data/globe_east_540.jpg"
|
|
7
|
-
|
|
8
|
-
context "TagLib::RIFF::WAV::File" do
|
|
9
|
+
context 'TagLib::RIFF::WAV::File' do
|
|
9
10
|
setup do
|
|
10
11
|
@file = TagLib::RIFF::WAV::File.new(SAMPLE_FILE)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
should
|
|
14
|
+
should 'open' do
|
|
14
15
|
assert_not_nil @file
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
context
|
|
18
|
+
context 'audio properties' do
|
|
18
19
|
setup do
|
|
19
20
|
@properties = @file.audio_properties
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
should
|
|
23
|
+
should 'exist' do
|
|
23
24
|
assert_not_nil @properties
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
should
|
|
27
|
+
should 'contain basic information' do
|
|
27
28
|
assert_equal 0, @properties.length_in_seconds
|
|
28
29
|
assert_equal 698, @properties.length_in_milliseconds
|
|
29
30
|
assert_equal 88, @properties.bitrate
|
|
@@ -31,59 +32,59 @@ class WAVFileTest < Test::Unit::TestCase
|
|
|
31
32
|
assert_equal 1, @properties.channels
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
should
|
|
35
|
+
should 'contain WAV-specific information' do
|
|
35
36
|
assert_equal 8, @properties.bits_per_sample
|
|
36
37
|
assert_equal TagLib::RIFF::WAV::FORMAT_PCM, @properties.format
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
context
|
|
41
|
+
context 'ID3V2 tag' do
|
|
41
42
|
setup do
|
|
42
43
|
@tag = @file.tag
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
should
|
|
46
|
+
should 'exist' do
|
|
46
47
|
assert @file.id3v2_tag?
|
|
47
48
|
assert_not_nil @tag
|
|
48
49
|
assert_equal TagLib::ID3v2::Tag, @tag.class
|
|
49
50
|
end
|
|
50
51
|
|
|
51
|
-
should
|
|
52
|
+
should 'not have an Info tag' do
|
|
52
53
|
refute @file.info_tag?
|
|
53
54
|
end
|
|
54
55
|
|
|
55
|
-
should
|
|
56
|
-
assert_equal
|
|
57
|
-
assert_equal
|
|
58
|
-
assert_equal
|
|
59
|
-
assert_equal
|
|
60
|
-
assert_equal
|
|
56
|
+
should 'contain basic tag information' do
|
|
57
|
+
assert_equal 'WAV Dummy Track Title', @tag.title
|
|
58
|
+
assert_equal 'WAV Dummy Artist Name', @tag.artist
|
|
59
|
+
assert_equal 'WAV Dummy Album Title', @tag.album
|
|
60
|
+
assert_equal 'WAV Dummy Comment', @tag.comment
|
|
61
|
+
assert_equal 'Jazz', @tag.genre
|
|
61
62
|
assert_equal 2014, @tag.year
|
|
62
63
|
assert_equal 5, @tag.track
|
|
63
64
|
assert_equal false, @tag.empty?
|
|
64
65
|
end
|
|
65
66
|
|
|
66
|
-
context
|
|
67
|
+
context 'APIC frame' do
|
|
67
68
|
setup do
|
|
68
69
|
@picture_data = File.open(PICTURE_FILE, 'rb') { |f| f.read }
|
|
69
70
|
@apic = @tag.frame_list('APIC').first
|
|
70
71
|
end
|
|
71
72
|
|
|
72
|
-
should
|
|
73
|
+
should 'exist' do
|
|
73
74
|
assert_not_nil @apic
|
|
74
75
|
assert_equal TagLib::ID3v2::AttachedPictureFrame, @apic.class
|
|
75
76
|
end
|
|
76
77
|
|
|
77
|
-
should
|
|
78
|
+
should 'have a type' do
|
|
78
79
|
assert_equal TagLib::ID3v2::AttachedPictureFrame::FrontCover, @apic.type
|
|
79
80
|
end
|
|
80
81
|
|
|
81
|
-
should
|
|
82
|
-
assert_equal
|
|
82
|
+
should 'have a mime type' do
|
|
83
|
+
assert_equal 'image/jpeg', @apic.mime_type
|
|
83
84
|
end
|
|
84
85
|
|
|
85
|
-
should
|
|
86
|
-
assert_equal
|
|
86
|
+
should 'have picture bytes' do
|
|
87
|
+
assert_equal 61_649, @apic.picture.size
|
|
87
88
|
assert_equal @picture_data, @apic.picture
|
|
88
89
|
end
|
|
89
90
|
end
|
|
@@ -95,14 +96,13 @@ class WAVFileTest < Test::Unit::TestCase
|
|
|
95
96
|
end
|
|
96
97
|
end
|
|
97
98
|
|
|
98
|
-
context
|
|
99
|
-
should
|
|
99
|
+
context 'TagLib::RIFF::WAV::File.open' do
|
|
100
|
+
should 'have open method' do
|
|
100
101
|
title = nil
|
|
101
102
|
TagLib::RIFF::WAV::File.open(SAMPLE_FILE, false) do |file|
|
|
102
103
|
title = file.tag.title
|
|
103
104
|
end
|
|
104
|
-
assert_equal
|
|
105
|
+
assert_equal 'WAV Dummy Track Title', title
|
|
105
106
|
end
|
|
106
107
|
end
|
|
107
|
-
|
|
108
108
|
end
|
data/test/wav_file_write_test.rb
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
4
|
|
|
3
5
|
class WAVFileWriteTest < Test::Unit::TestCase
|
|
6
|
+
SAMPLE_FILE = 'test/data/wav-sample.wav'
|
|
7
|
+
OUTPUT_FILE = 'test/data/_output.wav'
|
|
8
|
+
PICTURE_FILE = 'test/data/globe_east_90.jpg'
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
PICTURE_FILE = "test/data/globe_east_90.jpg"
|
|
8
|
-
|
|
9
|
-
def reloaded
|
|
10
|
-
TagLib::RIFF::WAV::File.open(OUTPUT_FILE, false) do |file|
|
|
11
|
-
yield file
|
|
12
|
-
end
|
|
10
|
+
def reloaded(&block)
|
|
11
|
+
TagLib::RIFF::WAV::File.open(OUTPUT_FILE, false, &block)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
context
|
|
14
|
+
context 'TagLib::RIFF::WAV::File' do
|
|
16
15
|
setup do
|
|
17
16
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
|
18
17
|
@file = TagLib::RIFF::WAV::File.new(OUTPUT_FILE, false)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
should
|
|
20
|
+
should 'be able to save the title' do
|
|
22
21
|
tag = @file.tag
|
|
23
22
|
assert_not_nil tag
|
|
24
|
-
tag.title =
|
|
23
|
+
tag.title = 'New Title'
|
|
25
24
|
success = @file.save
|
|
26
25
|
assert success
|
|
27
26
|
@file.close
|
|
@@ -30,14 +29,14 @@ class WAVFileWriteTest < Test::Unit::TestCase
|
|
|
30
29
|
written_title = reloaded do |file|
|
|
31
30
|
file.tag.title
|
|
32
31
|
end
|
|
33
|
-
assert_equal
|
|
32
|
+
assert_equal 'New Title', written_title
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
should
|
|
35
|
+
should 'have one picture frame' do
|
|
37
36
|
assert_equal 2, @file.tag.frame_list('APIC').size
|
|
38
37
|
end
|
|
39
38
|
|
|
40
|
-
should
|
|
39
|
+
should 'be able to remove all picture frames' do
|
|
41
40
|
@file.tag.remove_frames('APIC')
|
|
42
41
|
success = @file.save
|
|
43
42
|
assert success
|
|
@@ -49,12 +48,12 @@ class WAVFileWriteTest < Test::Unit::TestCase
|
|
|
49
48
|
end
|
|
50
49
|
end
|
|
51
50
|
|
|
52
|
-
should
|
|
51
|
+
should 'be able to add a picture frame' do
|
|
53
52
|
picture_data = File.open(PICTURE_FILE, 'rb') { |f| f.read }
|
|
54
53
|
|
|
55
54
|
apic = TagLib::ID3v2::AttachedPictureFrame.new
|
|
56
|
-
apic.mime_type =
|
|
57
|
-
apic.description =
|
|
55
|
+
apic.mime_type = 'image/jpeg'
|
|
56
|
+
apic.description = 'desc'
|
|
58
57
|
apic.text_encoding = TagLib::String::UTF8
|
|
59
58
|
apic.picture = picture_data
|
|
60
59
|
apic.type = TagLib::ID3v2::AttachedPictureFrame::BackCover
|
|
@@ -70,9 +69,9 @@ class WAVFileWriteTest < Test::Unit::TestCase
|
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
reloaded do |file|
|
|
73
|
-
written_apic = file.tag.frame_list(
|
|
74
|
-
assert_equal
|
|
75
|
-
assert_equal
|
|
72
|
+
written_apic = file.tag.frame_list('APIC')[2]
|
|
73
|
+
assert_equal 'image/jpeg', written_apic.mime_type
|
|
74
|
+
assert_equal 'desc', written_apic.description
|
|
76
75
|
assert_equal picture_data, written_apic.picture
|
|
77
76
|
end
|
|
78
77
|
end
|
|
@@ -86,18 +85,18 @@ class WAVFileWriteTest < Test::Unit::TestCase
|
|
|
86
85
|
end
|
|
87
86
|
end
|
|
88
87
|
|
|
89
|
-
context
|
|
88
|
+
context 'TagLib::RIFF::WAV::File.strip' do
|
|
90
89
|
setup do
|
|
91
90
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
|
92
91
|
@file = TagLib::RIFF::WAV::File.new(OUTPUT_FILE)
|
|
93
92
|
end
|
|
94
93
|
|
|
95
|
-
should
|
|
94
|
+
should 'update the file immediately' do
|
|
96
95
|
assert @file.id3v2_tag?
|
|
97
96
|
|
|
98
97
|
@file.strip(TagLib::RIFF::WAV::File::ID3v2)
|
|
99
98
|
|
|
100
|
-
reloaded do |
|
|
99
|
+
reloaded do |_file|
|
|
101
100
|
refute @file.id3v2_tag?
|
|
102
101
|
end
|
|
103
102
|
end
|