taglib-ruby 1.0.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/.yardopts +1 -1
- data/{CHANGES.md → CHANGELOG.md} +35 -14
- data/Gemfile +2 -0
- data/Guardfile +4 -2
- data/README.md +56 -38
- data/Rakefile +8 -8
- 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 +25 -0
- data/ext/taglib_base/taglib_base.i +18 -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.i +7 -0
- data/ext/taglib_flac/taglib_flac_wrap.cxx +235 -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.i +17 -0
- data/ext/taglib_id3v2/taglib_id3v2_wrap.cxx +2922 -993
- 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 +4 -2
- data/lib/taglib/vorbis.rb +2 -0
- data/lib/taglib/wav.rb +2 -1
- data/lib/taglib.rb +4 -3
- data/taglib-ruby.gemspec +165 -162
- data/tasks/docs_coverage.rake +10 -8
- data/tasks/ext.rake +26 -25
- data/tasks/gemspec_check.rake +7 -5
- 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/flac_nopic.flac +0 -0
- 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 +39 -0
- 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 +98 -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 +26 -23
data/test/data/vorbis-create.cpp
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#include <iostream>
|
2
|
-
#include <
|
2
|
+
#include <cstdlib>
|
3
3
|
|
4
4
|
#include <taglib/taglib.h>
|
5
5
|
#include <taglib/vorbisfile.h>
|
@@ -10,9 +10,10 @@ using namespace TagLib;
|
|
10
10
|
|
11
11
|
int main(int argc, char **argv) {
|
12
12
|
if (argc != 2) {
|
13
|
-
std::
|
14
|
-
|
13
|
+
std::cerr << "usage: " << argv[0] << " file.oga" << std::endl;
|
14
|
+
return EXIT_FAILURE;
|
15
15
|
}
|
16
|
+
|
16
17
|
char *filename = argv[1];
|
17
18
|
|
18
19
|
Vorbis::File file(filename);
|
@@ -41,7 +42,11 @@ int main(int argc, char **argv) {
|
|
41
42
|
tag->addField("MULTIPLE", "A");
|
42
43
|
tag->addField("MULTIPLE", "B", false);
|
43
44
|
|
44
|
-
ByteVector
|
45
|
+
const ByteVector data = getPictureData("globe_east_90.jpg");
|
46
|
+
if (data.isEmpty()) {
|
47
|
+
std::cerr << "failed to get picture data" << std::endl;
|
48
|
+
return EXIT_FAILURE;
|
49
|
+
}
|
45
50
|
|
46
51
|
FLAC::Picture picture;
|
47
52
|
picture.setType(FLAC::Picture::FrontCover);
|
@@ -51,11 +56,13 @@ int main(int argc, char **argv) {
|
|
51
56
|
picture.setHeight(90);
|
52
57
|
picture.setColorDepth(24);
|
53
58
|
picture.setNumColors(0);
|
54
|
-
picture.setData(
|
59
|
+
picture.setData(data);
|
55
60
|
|
56
61
|
tag->addField("METADATA_BLOCK_PICTURE", picture.render().toBase64());
|
57
62
|
|
58
63
|
file.save();
|
64
|
+
|
65
|
+
return EXIT_SUCCESS;
|
59
66
|
}
|
60
67
|
|
61
68
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|
data/test/data/wav-create.cpp
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include <cstdlib>
|
3
|
+
|
1
4
|
#include <taglib/taglib.h>
|
2
5
|
#include <taglib/wavfile.h>
|
3
6
|
#include <taglib/wavproperties.h>
|
@@ -7,12 +10,12 @@
|
|
7
10
|
|
8
11
|
using namespace TagLib;
|
9
12
|
|
10
|
-
|
11
13
|
int main(int argc, char **argv) {
|
12
14
|
if (argc != 2) {
|
13
|
-
std::
|
14
|
-
|
15
|
+
std::cerr << "usage: " << argv[0] << " file.wav" << std::endl;
|
16
|
+
return EXIT_FAILURE;
|
15
17
|
}
|
18
|
+
|
16
19
|
char *filename = argv[1];
|
17
20
|
|
18
21
|
RIFF::WAV::File file(filename);
|
@@ -32,6 +35,11 @@ int main(int argc, char **argv) {
|
|
32
35
|
ID3v2::AttachedPictureFrame *apic;
|
33
36
|
|
34
37
|
picture_data = getPictureData("globe_east_540.jpg");
|
38
|
+
if (picture_data.isEmpty()) {
|
39
|
+
std::cerr << "failed to get picture data" << std::endl;
|
40
|
+
return EXIT_FAILURE;
|
41
|
+
}
|
42
|
+
|
35
43
|
apic = new ID3v2::AttachedPictureFrame();
|
36
44
|
apic->setPicture(picture_data);
|
37
45
|
apic->setMimeType("image/jpeg");
|
@@ -41,6 +49,11 @@ int main(int argc, char **argv) {
|
|
41
49
|
tag->addFrame(apic);
|
42
50
|
|
43
51
|
picture_data = getPictureData("globe_east_90.jpg");
|
52
|
+
if (picture_data.isEmpty()) {
|
53
|
+
std::cerr << "failed to get picture data" << std::endl;
|
54
|
+
return EXIT_FAILURE;
|
55
|
+
}
|
56
|
+
|
44
57
|
apic = new ID3v2::AttachedPictureFrame();
|
45
58
|
apic->setPicture(picture_data);
|
46
59
|
apic->setMimeType("image/jpeg");
|
@@ -50,6 +63,8 @@ int main(int argc, char **argv) {
|
|
50
63
|
tag->addFrame(apic);
|
51
64
|
|
52
65
|
file.save();
|
66
|
+
|
67
|
+
return EXIT_SUCCESS;
|
53
68
|
}
|
54
69
|
|
55
70
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|
data/test/file_test.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class TestFile < Test::Unit::TestCase
|
4
|
-
context
|
6
|
+
context 'The sample.mp3 file' do
|
5
7
|
setup do
|
6
|
-
@mpeg_file = TagLib::MPEG::File.new(
|
8
|
+
@mpeg_file = TagLib::MPEG::File.new('test/data/sample.mp3', false)
|
7
9
|
end
|
8
10
|
|
9
|
-
context
|
10
|
-
should
|
11
|
+
context 'filename' do
|
12
|
+
should 'be the right name' do
|
11
13
|
assert_equal 'test/data/sample.mp3', @mpeg_file.name
|
12
14
|
end
|
13
15
|
|
14
16
|
if HAVE_ENCODING
|
15
|
-
should
|
17
|
+
should 'have the right encoding' do
|
16
18
|
assert_equal Encoding.find('filesystem'), @mpeg_file.name.encoding
|
17
19
|
end
|
18
20
|
end
|
data/test/fileref_open_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 FileRefOpenTest < Test::Unit::TestCase
|
4
|
-
context
|
5
|
-
should
|
6
|
-
title = TagLib::FileRef.open(
|
6
|
+
context 'TagLib::FileRef.open' do
|
7
|
+
should 'return result' do
|
8
|
+
title = TagLib::FileRef.open('test/data/vorbis.oga', false) do |file|
|
7
9
|
tag = file.tag
|
8
10
|
assert_not_nil tag
|
9
11
|
tag.title
|
10
12
|
end
|
11
|
-
assert_equal
|
13
|
+
assert_equal 'Title', title
|
12
14
|
end
|
13
15
|
|
14
|
-
should
|
16
|
+
should 'close even with exception' do
|
15
17
|
f = nil
|
16
18
|
begin
|
17
|
-
TagLib::FileRef.open(
|
19
|
+
TagLib::FileRef.open('test/data/vorbis.oga', false) do |file|
|
18
20
|
f = file
|
19
21
|
raise NotImplementedError
|
20
22
|
end
|
21
|
-
flunk(
|
23
|
+
flunk('Should have raised NotImplementedError.')
|
22
24
|
rescue NotImplementedError
|
23
25
|
begin
|
24
26
|
f.tag
|
25
|
-
flunk(
|
26
|
-
rescue => e
|
27
|
-
assert_equal
|
27
|
+
flunk('Should have raised ObjectPreviouslyDeleted.')
|
28
|
+
rescue StandardError => e
|
29
|
+
assert_equal 'ObjectPreviouslyDeleted', e.class.to_s
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class TestFileRefProperties < Test::Unit::TestCase
|
4
|
-
context
|
6
|
+
context 'The crash.mp3 file audio properties' do
|
5
7
|
setup do
|
6
|
-
@fileref = TagLib::FileRef.new(
|
8
|
+
@fileref = TagLib::FileRef.new('test/data/crash.mp3', true, TagLib::AudioProperties::Average)
|
7
9
|
@properties = @fileref.audio_properties
|
8
10
|
end
|
9
11
|
|
10
|
-
should
|
12
|
+
should 'exist' do
|
11
13
|
assert_not_nil @properties
|
12
14
|
end
|
13
15
|
|
14
|
-
should
|
16
|
+
should 'contain basic information' do
|
15
17
|
assert_equal 2, @properties.length_in_seconds
|
16
18
|
assert_equal 157, @properties.bitrate
|
17
19
|
assert_equal 44100, @properties.sample_rate
|
data/test/fileref_write_test.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
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 TestFileRefWrite < Test::Unit::TestCase
|
8
|
+
SAMPLE_FILE = 'test/data/sample.mp3'
|
9
|
+
OUTPUT_FILE = 'test/data/output.mp3'
|
6
10
|
|
7
|
-
|
8
|
-
OUTPUT_FILE = "test/data/output.mp3"
|
9
|
-
|
10
|
-
context "TagLib::FileRef" do
|
11
|
+
context 'TagLib::FileRef' do
|
11
12
|
setup do
|
12
13
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
13
14
|
@file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
|
14
15
|
end
|
15
16
|
|
16
|
-
should
|
17
|
+
should 'be able to save the title' do
|
17
18
|
tag = @file.tag
|
18
19
|
assert_not_nil tag
|
19
|
-
tag.title =
|
20
|
+
tag.title = 'New Title'
|
20
21
|
success = @file.save
|
21
22
|
assert success
|
22
23
|
@file.close
|
23
24
|
@file = nil
|
24
25
|
|
25
26
|
written_file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
|
26
|
-
assert_equal
|
27
|
+
assert_equal 'New Title', written_file.tag.title
|
27
28
|
written_file.close
|
28
29
|
end
|
29
30
|
|
30
|
-
should
|
31
|
+
should 'not segfault when setting int' do
|
31
32
|
begin
|
32
33
|
@file.tag.title = 42
|
33
|
-
flunk(
|
34
|
+
flunk('Should have raised a TypeError')
|
34
35
|
rescue TypeError
|
35
36
|
# this is good
|
36
37
|
end
|
@@ -45,15 +46,15 @@ class TestFileRefWrite < Test::Unit::TestCase
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
context
|
49
|
+
context 'TagLib::FileRef.open' do
|
49
50
|
setup do
|
50
51
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
51
52
|
end
|
52
53
|
|
53
|
-
should
|
54
|
+
should 'be able to save file' do
|
54
55
|
TagLib::MPEG::File.open(OUTPUT_FILE, false) do |file|
|
55
56
|
tag = file.tag
|
56
|
-
tag.title =
|
57
|
+
tag.title = 'New Title'
|
57
58
|
file.save
|
58
59
|
end
|
59
60
|
|
@@ -61,7 +62,7 @@ class TestFileRefWrite < Test::Unit::TestCase
|
|
61
62
|
tag = file.tag
|
62
63
|
tag.title
|
63
64
|
end
|
64
|
-
assert_equal
|
65
|
+
assert_equal 'New Title', title
|
65
66
|
end
|
66
67
|
|
67
68
|
teardown do
|
data/test/flac_file_test.rb
CHANGED
@@ -1,49 +1,54 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class FlacFileTest < Test::Unit::TestCase
|
4
|
-
context
|
6
|
+
context 'TagLib::FLAC::File' do
|
5
7
|
setup do
|
6
|
-
@file = TagLib::FLAC::File.new(
|
8
|
+
@file = TagLib::FLAC::File.new('test/data/flac.flac')
|
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::Tag, tag.class
|
13
15
|
end
|
14
16
|
|
15
|
-
should
|
17
|
+
should 'have XiphComment' do
|
16
18
|
assert @file.xiph_comment?
|
17
19
|
tag = @file.xiph_comment
|
18
20
|
assert_not_nil tag
|
19
21
|
assert_equal TagLib::Ogg::XiphComment, tag.class
|
22
|
+
assert_not_nil @file.xiph_comment(true)
|
20
23
|
end
|
21
24
|
|
22
|
-
should
|
25
|
+
should 'have method for ID3v1 tag' do
|
23
26
|
refute @file.id3v1_tag?
|
24
27
|
assert_nil @file.id3v1_tag
|
28
|
+
assert_not_nil @file.id3v1_tag(true)
|
25
29
|
end
|
26
30
|
|
27
|
-
should
|
31
|
+
should 'have method for ID3v2 tag' do
|
28
32
|
refute @file.id3v2_tag?
|
29
33
|
assert_nil @file.id3v2_tag
|
34
|
+
assert_not_nil @file.id3v2_tag(true)
|
30
35
|
end
|
31
36
|
|
32
|
-
should
|
37
|
+
should 'support stripping tags by type' do
|
33
38
|
@file.strip(TagLib::FLAC::File::XiphComment)
|
34
39
|
assert @file.xiph_comment?
|
35
40
|
end
|
36
41
|
|
37
|
-
context
|
42
|
+
context 'audio properties' do
|
38
43
|
setup do
|
39
44
|
@properties = @file.audio_properties
|
40
45
|
end
|
41
46
|
|
42
|
-
should
|
47
|
+
should 'exist' do
|
43
48
|
assert_not_nil @properties
|
44
49
|
end
|
45
50
|
|
46
|
-
should
|
51
|
+
should 'contain basic information' do
|
47
52
|
assert_equal 1, @properties.length_in_seconds
|
48
53
|
assert_equal 1017, @properties.length_in_milliseconds
|
49
54
|
assert_equal 209, @properties.bitrate
|
@@ -51,51 +56,51 @@ class FlacFileTest < Test::Unit::TestCase
|
|
51
56
|
assert_equal 1, @properties.channels
|
52
57
|
end
|
53
58
|
|
54
|
-
should
|
59
|
+
should 'contain flac-specific information' do
|
55
60
|
assert_equal 16, @properties.bits_per_sample
|
56
|
-
s = [
|
61
|
+
s = ['78d19b86df2cd488b35957e6bd884968'].pack('H*')
|
57
62
|
assert_equal s, @properties.signature
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
should
|
66
|
+
should 'have pictures' do
|
62
67
|
refute_empty @file.picture_list
|
63
68
|
end
|
64
69
|
|
65
|
-
context
|
70
|
+
context 'first picture' do
|
66
71
|
setup do
|
67
72
|
@picture = @file.picture_list.first
|
68
73
|
end
|
69
74
|
|
70
|
-
should
|
75
|
+
should 'be a TagLib::FLAC::Picture,' do
|
71
76
|
assert_equal TagLib::FLAC::Picture, @picture.class
|
72
77
|
end
|
73
78
|
|
74
|
-
should
|
79
|
+
should 'have meta-data' do
|
75
80
|
assert_equal TagLib::FLAC::Picture::FrontCover, @picture.type
|
76
|
-
assert_equal
|
77
|
-
assert_equal
|
81
|
+
assert_equal 'image/jpeg', @picture.mime_type
|
82
|
+
assert_equal 'Globe', @picture.description
|
78
83
|
assert_equal 90, @picture.width
|
79
84
|
assert_equal 90, @picture.height
|
80
85
|
assert_equal 8, @picture.color_depth
|
81
86
|
assert_equal 0, @picture.num_colors
|
82
87
|
end
|
83
88
|
|
84
|
-
should
|
85
|
-
picture_data = File.open(
|
89
|
+
should 'have data' do
|
90
|
+
picture_data = File.open('test/data/globe_east_90.jpg', 'rb') { |f| f.read }
|
86
91
|
assert_equal picture_data, @picture.data
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
90
|
-
should
|
95
|
+
should 'support removing a picture' do
|
91
96
|
refute_empty @file.picture_list
|
92
97
|
@file.remove_picture(@file.picture_list.first)
|
93
98
|
assert_empty @file.picture_list
|
94
99
|
end
|
95
100
|
|
96
|
-
should
|
101
|
+
should 'support removing all pictures' do
|
97
102
|
refute_empty @file.picture_list
|
98
|
-
@file.remove_pictures
|
103
|
+
@file.remove_pictures
|
99
104
|
assert_empty @file.picture_list
|
100
105
|
end
|
101
106
|
|
@@ -105,13 +110,13 @@ class FlacFileTest < Test::Unit::TestCase
|
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
108
|
-
context
|
109
|
-
should
|
113
|
+
context 'TagLib::FLAC::File.open' do
|
114
|
+
should 'should work' do
|
110
115
|
title = nil
|
111
|
-
TagLib::FLAC::File.open(
|
116
|
+
TagLib::FLAC::File.open('test/data/flac.flac', false) do |file|
|
112
117
|
title = file.tag.title
|
113
118
|
end
|
114
|
-
assert_equal
|
119
|
+
assert_equal 'Title', title
|
115
120
|
end
|
116
121
|
end
|
117
122
|
end
|
@@ -1,27 +1,26 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class FlacFileWriteTest < Test::Unit::TestCase
|
6
|
+
SAMPLE_FILE = 'test/data/flac.flac'
|
7
|
+
OUTPUT_FILE = 'test/data/output.flac'
|
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::FLAC::File.open(OUTPUT_FILE, false) do |file|
|
11
|
-
yield file
|
12
|
-
end
|
10
|
+
def reloaded(&block)
|
11
|
+
TagLib::FLAC::File.open(OUTPUT_FILE, false, &block)
|
13
12
|
end
|
14
13
|
|
15
|
-
context
|
14
|
+
context 'TagLib::FLAC::File' do
|
16
15
|
setup do
|
17
16
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
18
17
|
@file = TagLib::FLAC::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,10 +29,10 @@ class FlacFileWriteTest < 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 'be able to remove pictures' do
|
37
36
|
assert_equal 1, @file.picture_list.size
|
38
37
|
@file.remove_pictures
|
39
38
|
assert_equal 0, @file.picture_list.size
|
@@ -41,13 +40,13 @@ class FlacFileWriteTest < Test::Unit::TestCase
|
|
41
40
|
assert success
|
42
41
|
end
|
43
42
|
|
44
|
-
should
|
43
|
+
should 'be able to add and save a new picture' do
|
45
44
|
picture_data = File.open(PICTURE_FILE, 'rb') { |f| f.read }
|
46
45
|
|
47
46
|
pic = TagLib::FLAC::Picture.new
|
48
47
|
pic.type = TagLib::FLAC::Picture::FrontCover
|
49
|
-
pic.mime_type =
|
50
|
-
pic.description =
|
48
|
+
pic.mime_type = 'image/jpeg'
|
49
|
+
pic.description = 'desc'
|
51
50
|
pic.width = 90
|
52
51
|
pic.height = 90
|
53
52
|
pic.data = picture_data
|
@@ -62,8 +61,8 @@ class FlacFileWriteTest < Test::Unit::TestCase
|
|
62
61
|
reloaded do |file|
|
63
62
|
written_pic = file.picture_list.last
|
64
63
|
assert_equal TagLib::FLAC::Picture::FrontCover, written_pic.type
|
65
|
-
assert_equal
|
66
|
-
assert_equal
|
64
|
+
assert_equal 'image/jpeg', written_pic.mime_type
|
65
|
+
assert_equal 'desc', written_pic.description
|
67
66
|
assert_equal 90, written_pic.width
|
68
67
|
assert_equal 90, written_pic.height
|
69
68
|
assert_equal picture_data, written_pic.data
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
4
|
+
|
5
|
+
class TestFlacPictureMemory < Test::Unit::TestCase
|
6
|
+
N = 10000
|
7
|
+
|
8
|
+
context 'TagLib::FLAC::Picture' do
|
9
|
+
setup do
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'release memory when closing flac file with picture data' do
|
13
|
+
c = 0
|
14
|
+
N.times do
|
15
|
+
TagLib::FLAC::File.open('test/data/flac.flac', false) do |f|
|
16
|
+
f.picture_list.each do |_p|
|
17
|
+
c += 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
assert_equal N, c
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'process a flac file without picture data' do
|
25
|
+
c = 0
|
26
|
+
N.times do
|
27
|
+
TagLib::FLAC::File.open('test/data/flac_nopic.flac', false) do |f|
|
28
|
+
f.picture_list.each do |_p|
|
29
|
+
c += 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
assert_equal 0, c
|
34
|
+
end
|
35
|
+
|
36
|
+
teardown do
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'test/unit'
|
3
5
|
require 'shoulda-context'
|
@@ -7,4 +9,4 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
7
9
|
|
8
10
|
require 'taglib'
|
9
11
|
|
10
|
-
HAVE_ENCODING = !RUBY_VERSION.start_with?(
|
12
|
+
HAVE_ENCODING = !RUBY_VERSION.start_with?('1.8')
|
data/test/id3v1_genres_test.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
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
|
5
|
-
should
|
6
|
-
assert_equal
|
6
|
+
context 'TagLib::ID3v1' do
|
7
|
+
should 'list genres' do
|
8
|
+
assert_equal 'Jazz', TagLib::ID3v1.genre_list[8]
|
7
9
|
end
|
8
10
|
|
9
|
-
should
|
10
|
-
assert_equal 8, TagLib::ID3v1
|
11
|
+
should 'map genres to their index' do
|
12
|
+
assert_equal 8, TagLib::ID3v1.genre_map['Jazz']
|
11
13
|
end
|
12
14
|
|
13
|
-
should
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
15
|
+
should 'support to query the value of a genre' do
|
16
|
+
assert_equal 'Jazz', TagLib::ID3v1.genre(8)
|
17
|
+
assert_equal '', TagLib::ID3v1.genre(255)
|
16
18
|
end
|
17
19
|
|
18
|
-
should
|
19
|
-
assert_equal 8, TagLib::ID3v1
|
20
|
-
assert_equal 255, TagLib::ID3v1
|
20
|
+
should 'support to query the index of a genre' do
|
21
|
+
assert_equal 8, TagLib::ID3v1.genre_index('Jazz')
|
22
|
+
assert_equal 255, TagLib::ID3v1.genre_index('Unknown')
|
21
23
|
end
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
data/test/id3v1_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 TestID3v1Tag < Test::Unit::TestCase
|
4
|
-
context
|
6
|
+
context 'The id3v1.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/id3v1.mp3', read_properties)
|
8
10
|
end
|
9
11
|
|
10
|
-
should
|
12
|
+
should 'have an ID3v1 tag' do
|
11
13
|
assert_not_nil @file.id3v1_tag
|
12
14
|
end
|
13
15
|
|
14
|
-
context
|
16
|
+
context 'ID3v1 tag' do
|
15
17
|
setup do
|
16
18
|
@tag = @file.id3v1_tag
|
17
19
|
end
|
18
20
|
|
19
|
-
should
|
21
|
+
should 'have basic properties' do
|
20
22
|
assert_equal 'Title', @tag.title
|
21
23
|
assert_equal 'Artist', @tag.artist
|
22
24
|
assert_equal 'Album', @tag.album
|