taglib-ruby 1.0.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +15 -0
- 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 +21 -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.i +17 -0
- data/ext/taglib_id3v2/taglib_id3v2_wrap.cxx +2923 -999
- data/ext/taglib_mp4/extconf.rb +2 -0
- data/ext/taglib_mp4/taglib_mp4_wrap.cxx +311 -281
- 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 +103 -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 +24 -21
data/tasks/ext.rake
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
# Extension tasks and cross-compiling
|
2
4
|
|
3
5
|
host = 'i686-w64-mingw32'
|
4
6
|
$plat = ENV['PLATFORM'] || 'i386-mingw32'
|
5
7
|
|
6
|
-
|
7
8
|
taglib_version = ENV['TAGLIB_VERSION'] || '1.9.1'
|
8
9
|
taglib = "taglib-#{taglib_version}"
|
9
10
|
|
@@ -16,62 +17,62 @@ install_so = "#{install_dir}/lib/libtag.so"
|
|
16
17
|
$cross_config_options = ["--with-opt-dir=#{install_dir}"]
|
17
18
|
|
18
19
|
taglib_url = "https://github.com/taglib/taglib/archive/v#{taglib_version}.tar.gz"
|
19
|
-
taglib_options = [
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
taglib_options = ['-DCMAKE_BUILD_TYPE=Release',
|
21
|
+
'-DBUILD_EXAMPLES=OFF',
|
22
|
+
'-DBUILD_TESTS=OFF',
|
23
|
+
'-DBUILD_BINDINGS=OFF', # 1.11 builds bindings by default
|
24
|
+
'-DBUILD_SHARED_LIBS=ON', # 1.11 builds static by default
|
25
|
+
'-DWITH_MP4=ON', # WITH_MP4, WITH_ASF only needed with taglib 1.7, will be default in 1.8
|
26
|
+
'-DWITH_ASF=ON'].join(' ')
|
26
27
|
|
27
28
|
def configure_cross_compile(ext)
|
28
29
|
ext.cross_compile = true
|
29
30
|
ext.cross_platform = $plat
|
30
31
|
ext.cross_config_options.concat($cross_config_options)
|
31
32
|
ext.cross_compiling do |gem|
|
32
|
-
gem.files <<
|
33
|
+
gem.files << 'lib/libtag.dll'
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
require 'rake/extensiontask'
|
37
|
-
Rake::ExtensionTask.new(
|
38
|
+
Rake::ExtensionTask.new('taglib_base', $gemspec) do |ext|
|
38
39
|
configure_cross_compile(ext)
|
39
40
|
end
|
40
|
-
Rake::ExtensionTask.new(
|
41
|
+
Rake::ExtensionTask.new('taglib_mpeg', $gemspec) do |ext|
|
41
42
|
configure_cross_compile(ext)
|
42
43
|
end
|
43
|
-
Rake::ExtensionTask.new(
|
44
|
+
Rake::ExtensionTask.new('taglib_id3v1', $gemspec) do |ext|
|
44
45
|
configure_cross_compile(ext)
|
45
46
|
end
|
46
|
-
Rake::ExtensionTask.new(
|
47
|
+
Rake::ExtensionTask.new('taglib_id3v2', $gemspec) do |ext|
|
47
48
|
configure_cross_compile(ext)
|
48
49
|
end
|
49
|
-
Rake::ExtensionTask.new(
|
50
|
+
Rake::ExtensionTask.new('taglib_ogg', $gemspec) do |ext|
|
50
51
|
configure_cross_compile(ext)
|
51
52
|
end
|
52
|
-
Rake::ExtensionTask.new(
|
53
|
+
Rake::ExtensionTask.new('taglib_vorbis', $gemspec) do |ext|
|
53
54
|
configure_cross_compile(ext)
|
54
55
|
end
|
55
|
-
Rake::ExtensionTask.new(
|
56
|
+
Rake::ExtensionTask.new('taglib_flac_picture', $gemspec) do |ext|
|
56
57
|
configure_cross_compile(ext)
|
57
58
|
end
|
58
|
-
Rake::ExtensionTask.new(
|
59
|
+
Rake::ExtensionTask.new('taglib_flac', $gemspec) do |ext|
|
59
60
|
configure_cross_compile(ext)
|
60
61
|
end
|
61
|
-
Rake::ExtensionTask.new(
|
62
|
+
Rake::ExtensionTask.new('taglib_mp4', $gemspec) do |ext|
|
62
63
|
configure_cross_compile(ext)
|
63
64
|
end
|
64
|
-
Rake::ExtensionTask.new(
|
65
|
+
Rake::ExtensionTask.new('taglib_aiff', $gemspec) do |ext|
|
65
66
|
configure_cross_compile(ext)
|
66
67
|
end
|
67
|
-
Rake::ExtensionTask.new(
|
68
|
+
Rake::ExtensionTask.new('taglib_wav', $gemspec) do |ext|
|
68
69
|
configure_cross_compile(ext)
|
69
70
|
end
|
70
71
|
|
71
72
|
task :cross do
|
72
73
|
# Mkmf just uses "g++" as C++ compiler, despite what's in rbconfig.rb.
|
73
74
|
# So, we need to hack around it by setting CXX to the cross compiler.
|
74
|
-
ENV[
|
75
|
+
ENV['CXX'] = "#{host}-g++"
|
75
76
|
end
|
76
77
|
|
77
78
|
file "#{tmp_arch}/stage/lib/libtag.dll" => [install_dll] do |f|
|
@@ -81,17 +82,17 @@ end
|
|
81
82
|
file install_dll => ["#{tmp}/#{taglib}"] do
|
82
83
|
chdir "#{tmp}/#{taglib}" do
|
83
84
|
sh %(cmake -DCMAKE_INSTALL_PREFIX=#{install_dir} -DCMAKE_TOOLCHAIN_FILE=#{toolchain_file} #{taglib_options})
|
84
|
-
sh
|
85
|
-
sh
|
85
|
+
sh 'make VERBOSE=1'
|
86
|
+
sh 'make install'
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
|
-
task :
|
90
|
+
task vendor: [install_so]
|
90
91
|
|
91
92
|
file install_so => ["#{tmp_arch}/#{taglib}", "#{tmp_arch}/#{taglib}-build", "#{tmp}/#{taglib}"] do
|
92
93
|
chdir "#{tmp_arch}/#{taglib}-build" do
|
93
94
|
sh %(cmake -DCMAKE_INSTALL_PREFIX=#{install_dir} #{taglib_options} #{tmp}/#{taglib})
|
94
|
-
sh
|
95
|
+
sh 'make install VERBOSE=1'
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
data/tasks/gemspec_check.rake
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
desc 'Checks file list in .gemspec against files tracked in Git'
|
4
|
+
task :gemspec_check do |_t|
|
5
|
+
exclude = ['.gitignore', '.github/workflows/ci.yml']
|
4
6
|
git_files = `git ls-files`.split("\n") - exclude
|
5
7
|
gemspec_files = $gemspec.files
|
6
8
|
|
@@ -8,12 +10,12 @@ task :gemspec_check do |t|
|
|
8
10
|
only_in_git = git_files - gemspec_files
|
9
11
|
|
10
12
|
unless only_in_gemspec.empty?
|
11
|
-
puts
|
13
|
+
puts 'In gemspec but not in git:'
|
12
14
|
puts only_in_gemspec
|
13
15
|
end
|
14
16
|
|
15
17
|
unless only_in_git.empty?
|
16
|
-
puts
|
18
|
+
puts 'In git but not in gemspec:'
|
17
19
|
puts only_in_git
|
18
20
|
end
|
19
21
|
end
|
data/tasks/swig.rake
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
# Tasks for generating SWIG wrappers in ext
|
2
4
|
|
3
5
|
# Execute SWIG for the specified extension.
|
@@ -8,26 +10,24 @@
|
|
8
10
|
# $TAGLIB_DIR/include will be searched first for taglib headers.
|
9
11
|
def run_swig(mod)
|
10
12
|
swig = `which swig`.chomp
|
11
|
-
if swig.empty?
|
12
|
-
swig = `which swig2.0`.chomp
|
13
|
-
end
|
13
|
+
swig = `which swig2.0`.chomp if swig.empty?
|
14
14
|
|
15
|
-
#
|
16
|
-
include_args = %w
|
15
|
+
# Standard search location for headers
|
16
|
+
include_args = %w[-I/usr/local/include -I/usr/include]
|
17
17
|
|
18
|
-
if ENV.
|
18
|
+
if ENV.key?('TAGLIB_DIR')
|
19
19
|
unless File.directory?(ENV['TAGLIB_DIR'])
|
20
|
-
abort
|
20
|
+
abort 'When defined, the TAGLIB_DIR environment variable must point to a valid directory.'
|
21
21
|
end
|
22
22
|
|
23
23
|
# Push it in front to get it searched first.
|
24
|
-
include_args.unshift(
|
24
|
+
include_args.unshift("-I#{ENV['TAGLIB_DIR']}/include")
|
25
25
|
end
|
26
26
|
|
27
27
|
sh "cd ext/#{mod} && #{swig} -c++ -ruby -autorename -initname #{mod} #{include_args.join(' ')} #{mod}.i"
|
28
28
|
end
|
29
29
|
|
30
|
-
task :
|
30
|
+
task swig:
|
31
31
|
['ext/taglib_base/taglib_base_wrap.cxx',
|
32
32
|
'ext/taglib_mpeg/taglib_mpeg_wrap.cxx',
|
33
33
|
'ext/taglib_id3v1/taglib_id3v1_wrap.cxx',
|
@@ -38,8 +38,7 @@ task :swig =>
|
|
38
38
|
'ext/taglib_flac/taglib_flac_wrap.cxx',
|
39
39
|
'ext/taglib_mp4/taglib_mp4_wrap.cxx',
|
40
40
|
'ext/taglib_aiff/taglib_aiff_wrap.cxx',
|
41
|
-
'ext/taglib_wav/taglib_wav_wrap.cxx'
|
42
|
-
]
|
41
|
+
'ext/taglib_wav/taglib_wav_wrap.cxx']
|
43
42
|
|
44
43
|
base_dependencies = ['ext/taglib_base/taglib_base.i', 'ext/taglib_base/includes.i']
|
45
44
|
|
data/test/aiff_examples_test.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class AIFFExamples < Test::Unit::TestCase
|
6
|
+
DATA_FILE_PREFIX = 'test/data/aiff-'
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
context "TagLib::RIFF::AIFF::File" do
|
8
|
-
|
9
|
-
should "Run TagLib::RIFF::AIFF::File examples" do
|
10
|
-
|
11
|
-
|
8
|
+
context 'TagLib::RIFF::AIFF::File' do
|
9
|
+
should 'Run TagLib::RIFF::AIFF::File examples' do
|
12
10
|
# @example Reading the title
|
13
11
|
title = TagLib::RIFF::AIFF::File.open("#{DATA_FILE_PREFIX}sample.aiff") do |file|
|
14
12
|
file.tag.title
|
@@ -16,7 +14,7 @@ class AIFFExamples < Test::Unit::TestCase
|
|
16
14
|
|
17
15
|
# @example Reading AIFF-specific audio properties
|
18
16
|
TagLib::RIFF::AIFF::File.open("#{DATA_FILE_PREFIX}sample.aiff") do |file|
|
19
|
-
file.audio_properties.bits_per_sample
|
17
|
+
file.audio_properties.bits_per_sample # => 16
|
20
18
|
end
|
21
19
|
|
22
20
|
# @example Saving ID3v2 cover-art to disk
|
@@ -24,16 +22,13 @@ class AIFFExamples < Test::Unit::TestCase
|
|
24
22
|
id3v2_tag = file.tag
|
25
23
|
cover = id3v2_tag.frame_list('APIC').first
|
26
24
|
ext = cover.mime_type.rpartition('/')[2]
|
27
|
-
File.open("#{DATA_FILE_PREFIX}cover-art.#{ext}",
|
25
|
+
File.open("#{DATA_FILE_PREFIX}cover-art.#{ext}", 'wb') { |f| f.write cover.picture }
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
28
|
# checks
|
32
|
-
assert_equal
|
29
|
+
assert_equal 'AIFF Dummy Track Title - ID3v2.4', title
|
33
30
|
assert_equal true, File.exist?("#{DATA_FILE_PREFIX}cover-art.jpeg")
|
34
31
|
FileUtils.rm("#{DATA_FILE_PREFIX}cover-art.jpeg")
|
35
32
|
end
|
36
|
-
|
37
33
|
end
|
38
|
-
|
39
34
|
end
|
data/test/aiff_file_test.rb
CHANGED
@@ -1,70 +1,71 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class AIFFFileTest < Test::Unit::TestCase
|
6
|
+
SAMPLE_FILE = 'test/data/aiff-sample.aiff'
|
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::AIFF::File" do
|
9
|
+
context 'TagLib::RIFF::AIFF::File' do
|
9
10
|
setup do
|
10
11
|
@file = TagLib::RIFF::AIFF::File.new(SAMPLE_FILE)
|
11
12
|
@tag = @file.tag
|
12
|
-
File.open(PICTURE_FILE,
|
13
|
+
File.open(PICTURE_FILE, 'rb') do |f|
|
13
14
|
@picture_data = f.read
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
should
|
18
|
+
should 'have an ID3v2 tag' do
|
18
19
|
assert @file.id3v2_tag?
|
19
20
|
refute_nil @tag
|
20
21
|
assert_equal TagLib::ID3v2::Tag, @tag.class
|
21
22
|
end
|
22
23
|
|
23
|
-
should
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
27
|
-
assert_equal
|
28
|
-
assert_equal
|
24
|
+
should 'contain basic tag information' do
|
25
|
+
assert_equal 'AIFF Dummy Track Title - ID3v2.4', @tag.title
|
26
|
+
assert_equal 'AIFF Dummy Artist Name', @tag.artist
|
27
|
+
assert_equal 'AIFF Dummy Album Title', @tag.album
|
28
|
+
assert_equal 'AIFF Dummy Comment', @tag.comment
|
29
|
+
assert_equal 'Jazz', @tag.genre
|
29
30
|
assert_equal 2014, @tag.year
|
30
31
|
assert_equal 3, @tag.track
|
31
32
|
assert_equal false, @tag.empty?
|
32
33
|
end
|
33
34
|
|
34
|
-
context
|
35
|
+
context 'APIC frame' do
|
35
36
|
setup do
|
36
37
|
@apic = @tag.frame_list('APIC').first
|
37
38
|
end
|
38
39
|
|
39
|
-
should
|
40
|
+
should 'exist' do
|
40
41
|
assert_not_nil @apic
|
41
42
|
assert_equal TagLib::ID3v2::AttachedPictureFrame, @apic.class
|
42
43
|
end
|
43
44
|
|
44
|
-
should
|
45
|
+
should 'have a type' do
|
45
46
|
assert_equal TagLib::ID3v2::AttachedPictureFrame::FrontCover, @apic.type
|
46
47
|
end
|
47
48
|
|
48
|
-
should
|
49
|
-
assert_equal
|
49
|
+
should 'have a mime type' do
|
50
|
+
assert_equal 'image/jpeg', @apic.mime_type
|
50
51
|
end
|
51
52
|
|
52
|
-
should
|
53
|
+
should 'have picture bytes' do
|
53
54
|
assert_equal 61649, @apic.picture.size
|
54
55
|
assert_equal @picture_data, @apic.picture
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
context
|
59
|
+
context 'audio properties' do
|
59
60
|
setup do
|
60
61
|
@properties = @file.audio_properties
|
61
62
|
end
|
62
63
|
|
63
|
-
should
|
64
|
+
should 'exist' do
|
64
65
|
assert_not_nil @properties
|
65
66
|
end
|
66
67
|
|
67
|
-
should
|
68
|
+
should 'contain basic information' do
|
68
69
|
assert_equal 2, @properties.length_in_seconds
|
69
70
|
assert_equal 2937, @properties.length_in_milliseconds
|
70
71
|
assert_equal 256, @properties.bitrate
|
@@ -72,15 +73,15 @@ class AIFFFileTest < Test::Unit::TestCase
|
|
72
73
|
assert_equal 2, @properties.channels
|
73
74
|
end
|
74
75
|
|
75
|
-
should
|
76
|
+
should 'contain AIFF-specific information' do
|
76
77
|
assert_equal 16, @properties.bits_per_sample
|
77
78
|
assert_equal 23493, @properties.sample_frames
|
78
79
|
end
|
79
80
|
|
80
|
-
should
|
81
|
+
should 'do not contain AIFF-C information' do
|
81
82
|
refute @properties.aiff_c?
|
82
|
-
assert_equal
|
83
|
-
assert_equal
|
83
|
+
assert_equal '', @properties.compression_type
|
84
|
+
assert_equal '', @properties.compression_name
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
@@ -90,14 +91,13 @@ class AIFFFileTest < Test::Unit::TestCase
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
context
|
94
|
-
should
|
94
|
+
context 'TagLib::RIFF::AIFF::File.open' do
|
95
|
+
should 'have open method' do
|
95
96
|
title = nil
|
96
97
|
TagLib::RIFF::AIFF::File.open(SAMPLE_FILE, false) do |file|
|
97
98
|
title = file.tag.title
|
98
99
|
end
|
99
|
-
assert_equal
|
100
|
+
assert_equal 'AIFF Dummy Track Title - ID3v2.4', title
|
100
101
|
end
|
101
102
|
end
|
102
|
-
|
103
103
|
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 AIFFFileWriteTest < Test::Unit::TestCase
|
6
|
+
SAMPLE_FILE = 'test/data/aiff-sample.aiff'
|
7
|
+
OUTPUT_FILE = 'test/data/_output.aiff'
|
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::AIFF::File.open(OUTPUT_FILE, false) do |file|
|
11
|
-
yield file
|
12
|
-
end
|
10
|
+
def reloaded(&block)
|
11
|
+
TagLib::RIFF::AIFF::File.open(OUTPUT_FILE, false, &block)
|
13
12
|
end
|
14
13
|
|
15
|
-
context
|
14
|
+
context 'TagLib::RIFF::AIFF::File' do
|
16
15
|
setup do
|
17
16
|
FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
|
18
17
|
@file = TagLib::RIFF::AIFF::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 AIFFFileWriteTest < 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 1, @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 AIFFFileWriteTest < 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 AIFFFileWriteTest < 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')[1]
|
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
|
data/test/base_test.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
4
|
|
3
5
|
class BaseTest < Test::Unit::TestCase
|
4
|
-
context
|
5
|
-
should
|
6
|
+
context 'TagLib' do
|
7
|
+
should 'contain version constants' do
|
6
8
|
assert TagLib::TAGLIB_MAJOR_VERSION.is_a? Integer
|
7
9
|
assert TagLib::TAGLIB_MINOR_VERSION.is_a? Integer
|
8
10
|
assert TagLib::TAGLIB_PATCH_VERSION.is_a? Integer
|
@@ -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/mpegfile.h>
|
@@ -10,8 +10,8 @@ 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.mp3" << std::endl;
|
14
|
+
return EXIT_FAILURE;
|
15
15
|
}
|
16
16
|
char *filename = argv[1];
|
17
17
|
|
@@ -35,6 +35,10 @@ int main(int argc, char **argv) {
|
|
35
35
|
|
36
36
|
tag->addFrame(rv);
|
37
37
|
file.save();
|
38
|
+
|
39
|
+
delete rv;
|
40
|
+
|
41
|
+
return EXIT_SUCCESS;
|
38
42
|
}
|
39
43
|
|
40
44
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|
data/test/data/flac-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/flacfile.h>
|
@@ -11,9 +11,10 @@ using namespace TagLib;
|
|
11
11
|
|
12
12
|
int main(int argc, char **argv) {
|
13
13
|
if (argc != 2) {
|
14
|
-
std::
|
15
|
-
|
14
|
+
std::cerr << "usage: " << argv[0] << " file" << std::endl;
|
15
|
+
return EXIT_FAILURE;
|
16
16
|
}
|
17
|
+
|
17
18
|
char *filename = argv[1];
|
18
19
|
|
19
20
|
FLAC::File file(filename);
|
@@ -49,12 +50,21 @@ int main(int argc, char **argv) {
|
|
49
50
|
picture->setColorDepth(8);
|
50
51
|
picture->setNumColors(0);
|
51
52
|
|
52
|
-
ByteVector data = getPictureData("globe_east_90.jpg");
|
53
|
+
const ByteVector data = getPictureData("globe_east_90.jpg");
|
54
|
+
if (data.isEmpty()) {
|
55
|
+
std::cerr << "failed to get picture data" << std::endl;
|
56
|
+
delete picture;
|
57
|
+
return EXIT_FAILURE;
|
58
|
+
}
|
59
|
+
|
53
60
|
picture->setData(data);
|
54
61
|
|
55
62
|
file.addPicture(picture);
|
56
|
-
|
57
63
|
file.save();
|
64
|
+
|
65
|
+
delete picture;
|
66
|
+
|
67
|
+
return EXIT_SUCCESS;
|
58
68
|
}
|
59
69
|
|
60
70
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|
Binary file
|
@@ -5,9 +5,13 @@ using namespace TagLib;
|
|
5
5
|
ByteVector getPictureData(const char *filename) {
|
6
6
|
std::ifstream is;
|
7
7
|
is.open(filename, std::ios::binary);
|
8
|
+
if (!is.is_open()) {
|
9
|
+
std::cerr << "failed to open file: " << filename << std::endl;
|
10
|
+
return ByteVector();
|
11
|
+
}
|
8
12
|
|
9
13
|
is.seekg(0, std::ios::end);
|
10
|
-
int length = is.tellg();
|
14
|
+
const int length = is.tellg();
|
11
15
|
is.seekg(0, std::ios::beg);
|
12
16
|
|
13
17
|
char *buffer = new char[length];
|
data/test/data/id3v1-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/mpegfile.h>
|
@@ -9,9 +9,10 @@ using namespace TagLib;
|
|
9
9
|
|
10
10
|
int main(int argc, char **argv) {
|
11
11
|
if (argc != 2) {
|
12
|
-
std::
|
13
|
-
|
12
|
+
std::cerr << "usage: " << argv[0] << " file.mp3" << std::endl;
|
13
|
+
return EXIT_FAILURE;
|
14
14
|
}
|
15
|
+
|
15
16
|
char *filename = argv[1];
|
16
17
|
|
17
18
|
MPEG::File file(filename);
|
@@ -26,6 +27,8 @@ int main(int argc, char **argv) {
|
|
26
27
|
tag->setTrack(7);
|
27
28
|
|
28
29
|
file.save(MPEG::File::ID3v1);
|
30
|
+
|
31
|
+
return EXIT_SUCCESS;
|
29
32
|
}
|
30
33
|
|
31
34
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|
data/test/data/mp4-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/mp4file.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.m4a" << std::endl;
|
14
|
+
return EXIT_FAILURE;
|
15
15
|
}
|
16
|
+
|
16
17
|
char *filename = argv[1];
|
17
18
|
|
18
19
|
MP4::File file(filename);
|
@@ -26,13 +27,20 @@ int main(int argc, char **argv) {
|
|
26
27
|
tag->setYear(2011);
|
27
28
|
tag->setTrack(7);
|
28
29
|
|
29
|
-
ByteVector data = getPictureData("globe_east_90.jpg");
|
30
|
+
const ByteVector data = getPictureData("globe_east_90.jpg");
|
31
|
+
if (data.isEmpty()) {
|
32
|
+
std::cerr << "failed to get picture data" << std::endl;
|
33
|
+
return EXIT_FAILURE;
|
34
|
+
}
|
35
|
+
|
30
36
|
MP4::CoverArt cover_art = MP4::CoverArt(MP4::CoverArt::JPEG, data);
|
31
37
|
MP4::CoverArtList cover_art_list = MP4::CoverArtList();
|
32
38
|
cover_art_list.append(cover_art);
|
33
39
|
tag->itemListMap().insert("covr", MP4::Item(cover_art_list));
|
34
40
|
|
35
41
|
file.save();
|
42
|
+
|
43
|
+
return EXIT_SUCCESS;
|
36
44
|
}
|
37
45
|
|
38
46
|
// vim: set filetype=cpp sw=2 ts=2 expandtab:
|