taglib-ruby 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.yardopts +1 -1
  2. data/CHANGES.md +11 -0
  3. data/LICENSE.txt +0 -2
  4. data/README.md +7 -9
  5. data/docs/taglib/base.rb +35 -7
  6. data/docs/taglib/id3v2.rb +37 -5
  7. data/docs/taglib/mp4.rb +267 -0
  8. data/docs/taglib/mpeg.rb +23 -8
  9. data/ext/taglib_base/includes.i +2 -2
  10. data/ext/taglib_base/taglib_base.i +3 -0
  11. data/ext/taglib_base/taglib_base_wrap.cxx +11 -12
  12. data/ext/taglib_flac/taglib_flac_wrap.cxx +21 -25
  13. data/ext/taglib_id3v1/taglib_id3v1_wrap.cxx +4 -8
  14. data/ext/taglib_id3v2/taglib_id3v2.i +3 -0
  15. data/ext/taglib_id3v2/taglib_id3v2_wrap.cxx +528 -69
  16. data/ext/taglib_mp4/extconf.rb +4 -0
  17. data/ext/taglib_mp4/taglib_mp4.i +225 -0
  18. data/ext/taglib_mp4/taglib_mp4_wrap.cxx +4830 -0
  19. data/ext/taglib_mpeg/taglib_mpeg.i +15 -0
  20. data/ext/taglib_mpeg/taglib_mpeg_wrap.cxx +174 -88
  21. data/ext/taglib_ogg/taglib_ogg_wrap.cxx +2 -6
  22. data/ext/taglib_vorbis/taglib_vorbis_wrap.cxx +8 -12
  23. data/lib/taglib.rb +1 -0
  24. data/lib/taglib/mp4.rb +33 -0
  25. data/lib/taglib/version.rb +2 -2
  26. data/taglib-ruby.gemspec +19 -3
  27. data/tasks/ext.rake +3 -0
  28. data/tasks/swig.rake +6 -1
  29. data/test/base_test.rb +11 -0
  30. data/test/data/Makefile +5 -2
  31. data/test/data/flac-create.cpp +2 -22
  32. data/test/data/get_picture_data.cpp +22 -0
  33. data/test/data/mp4-create.cpp +38 -0
  34. data/test/data/mp4.m4a +0 -0
  35. data/test/fileref_write_test.rb +9 -0
  36. data/test/flac_file_test.rb +2 -1
  37. data/test/id3v2_header_test.rb +61 -0
  38. data/test/id3v2_write_test.rb +17 -0
  39. data/test/mp4_file_test.rb +51 -0
  40. data/test/mp4_file_write_test.rb +66 -0
  41. data/test/mp4_items_test.rb +183 -0
  42. metadata +39 -8
@@ -54,6 +54,23 @@ class TestID3v2Write < Test::Unit::TestCase
54
54
  end
55
55
  end
56
56
 
57
+ should "be able to save ID3v2.3 when compiled against TagLib >= 1.8" do
58
+ if TagLib::TAGLIB_MAJOR_VERSION > 1 ||
59
+ (TagLib::TAGLIB_MAJOR_VERSION == 1 && TagLib::TAGLIB_MINOR_VERSION >= 8)
60
+ success = @file.save(TagLib::MPEG::File::ID3v2, true, 3)
61
+ assert_equal true, success
62
+ @file.close
63
+ @file = nil
64
+
65
+ header = File.open(OUTPUT_FILE, 'rb') do |f|
66
+ f.read(5)
67
+ end
68
+ # 3 stands for v2.3
69
+ s = "ID3" + 3.chr + 0.chr
70
+ assert_equal s, header
71
+ end
72
+ end
73
+
57
74
  should "be able to set fields to nil" do
58
75
  tag = @file.id3v2_tag
59
76
  tag.title = nil
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class MP4FileTest < Test::Unit::TestCase
4
+ context "TagLib::MP4::File" do
5
+ setup do
6
+ @file = TagLib::MP4::File.new("test/data/mp4.m4a")
7
+ @tag = @file.tag
8
+ end
9
+
10
+ should "contain basic tag information" do
11
+ assert_equal "Title", @tag.title
12
+ assert_equal "Artist", @tag.artist
13
+ assert_equal "Album", @tag.album
14
+ assert_equal "Comment", @tag.comment
15
+ assert_equal "Pop", @tag.genre
16
+ assert_equal 2011, @tag.year
17
+ assert_equal 7, @tag.track
18
+ assert_equal false, @tag.empty?
19
+ end
20
+
21
+ context "audio properties" do
22
+ setup do
23
+ @properties = @file.audio_properties
24
+ end
25
+
26
+ should "exist" do
27
+ assert_not_nil @properties
28
+ end
29
+
30
+ should "contain basic information" do
31
+ assert_equal 1, @properties.length
32
+ assert_equal 54, @properties.bitrate
33
+ assert_equal 44100, @properties.sample_rate
34
+ # The test file is mono, this appears to be a TagLib bug
35
+ assert_equal 2, @properties.channels
36
+ end
37
+
38
+ should "contain mp4-specific information" do
39
+ assert_equal 16, @properties.bits_per_sample
40
+ # Properties#encrypted? raises a NoMethodError
41
+ # assert_equal false, @properties.encrypted?
42
+ end
43
+ end
44
+
45
+ teardown do
46
+ @file.close
47
+ @file = nil
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,66 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class MP4FileWriteTest < Test::Unit::TestCase
4
+
5
+ SAMPLE_FILE = "test/data/mp4.m4a"
6
+ OUTPUT_FILE = "test/data/output.m4a"
7
+ PICTURE_FILE = "test/data/globe_east_540.jpg"
8
+
9
+ def reloaded
10
+ TagLib::MP4::File.open(OUTPUT_FILE, false) do |file|
11
+ yield file
12
+ end
13
+ end
14
+
15
+ context "TagLib::MP4::File" do
16
+ setup do
17
+ FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
18
+ @file = TagLib::MP4::File.new(OUTPUT_FILE, false)
19
+ end
20
+
21
+ should "be able to save the title" do
22
+ tag = @file.tag
23
+ assert_not_nil tag
24
+ tag.title = "New Title"
25
+ success = @file.save
26
+ assert success
27
+ @file.close
28
+ @file = nil
29
+
30
+ written_title = reloaded do |file|
31
+ file.tag.title
32
+ end
33
+ assert_equal "New Title", written_title
34
+ end
35
+
36
+ should "be able to add and save new cover art" do
37
+ item_list_map = @file.tag.item_list_map
38
+ cover_art_list = item_list_map['covr'].to_cover_art_list
39
+ assert_equal 1, cover_art_list.size
40
+
41
+ data = File.open(PICTURE_FILE, 'rb') { |f| f.read }
42
+ new_cover_art = TagLib::MP4::CoverArt.new(TagLib::MP4::CoverArt::JPEG, data)
43
+
44
+ cover_art_list << new_cover_art
45
+ item_list_map.insert('covr', TagLib::MP4::Item.from_cover_art_list(cover_art_list))
46
+ assert_equal 2, item_list_map['covr'].to_cover_art_list.size
47
+
48
+ success = @file.save
49
+ assert success
50
+
51
+ reloaded do |file|
52
+ written_cover_art = file.tag.item_list_map['covr'].to_cover_art_list.last
53
+ assert_equal TagLib::MP4::CoverArt::JPEG, written_cover_art.format
54
+ assert_equal data, written_cover_art.data
55
+ end
56
+ end
57
+
58
+ teardown do
59
+ if @file
60
+ @file.close
61
+ @file = nil
62
+ end
63
+ FileUtils.rm OUTPUT_FILE
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,183 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ class MP4ItemsTest < Test::Unit::TestCase
5
+ ITUNES_LEADER = "\xC2\xA9"
6
+
7
+ context "The mp4.m4a file's items" do
8
+ setup do
9
+ @file = TagLib::MP4::File.new("test/data/mp4.m4a")
10
+ @tag = @file.tag
11
+ @item_list_map = @file.tag.item_list_map
12
+ @item_keys = [
13
+ "cover", "#{ITUNES_LEADER}nam", "#{ITUNES_LEADER}ART", "#{ITUNES_LEADER}alb",
14
+ "#{ITUNES_LEADER}cmt", "#{ITUNES_LEADER}gen", "#{ITUNES_LEADER}day",
15
+ "trkn", "#{ITUNES_LEADER}too", "#{ITUNES_LEADER}cpy"
16
+ ]
17
+ end
18
+
19
+ context "item_list_map" do
20
+ should "exist" do
21
+ assert_not_nil @item_list_map
22
+ end
23
+
24
+ should "not be empty" do
25
+ assert_equal false, @item_list_map.empty?
26
+ end
27
+
28
+ should "contain 10 items" do
29
+ assert_equal @item_keys.count, @item_list_map.size
30
+ end
31
+
32
+ should "have keys" do
33
+ assert_equal true, @item_list_map.contains("trkn")
34
+ assert_equal true, @item_list_map.has_key?("#{ITUNES_LEADER}too")
35
+ assert_equal true, @item_list_map.include?("#{ITUNES_LEADER}cpy")
36
+ assert_equal false, @item_list_map.include?("none such key")
37
+ end
38
+
39
+ should "look up keys" do
40
+ assert_nil @item_list_map["none such key"]
41
+ assert_equal ["Title"], @item_list_map["#{ITUNES_LEADER}nam"].to_string_list
42
+ end
43
+
44
+ should "be clearable" do
45
+ assert_equal 10, @item_list_map.size
46
+ comment = @item_list_map["#{ITUNES_LEADER}cmt"]
47
+ @item_list_map.clear
48
+ assert_equal true, @item_list_map.empty?
49
+ begin
50
+ comment.to_string_list
51
+ flunk("Should have raised ObjectPreviouslyDeleted.")
52
+ rescue => e
53
+ assert_equal "ObjectPreviouslyDeleted", e.class.to_s
54
+ end
55
+ end
56
+
57
+ should "be convertable to an array" do
58
+ array = @item_list_map.to_a
59
+ assert_equal 10, array.count
60
+ array.each do |object|
61
+ assert_equal Array, object.class
62
+ assert_equal 2, object.count
63
+ assert_equal String, object.first.class
64
+ assert_equal TagLib::MP4::Item, object.last.class
65
+ end
66
+ end
67
+ end
68
+
69
+ should "be removable" do
70
+ assert_equal 10, @item_list_map.size
71
+ title = @item_list_map["#{ITUNES_LEADER}nam"]
72
+ @item_list_map.erase("#{ITUNES_LEADER}nam")
73
+ assert_equal 9, @item_list_map.size
74
+ begin
75
+ title.to_string_list
76
+ flunk("Should have raised ObjectPreviouslyDeleted.")
77
+ rescue => e
78
+ assert_equal "ObjectPreviouslyDeleted", e.class.to_s
79
+ end
80
+ end
81
+
82
+ context "inserting items" do
83
+ should "insert a new item" do
84
+ new_title = TagLib::MP4::Item.from_string_list(['new title'])
85
+ @item_list_map.insert("#{ITUNES_LEADER}nam", new_title)
86
+ new_title = nil
87
+ GC.start
88
+ assert_equal ['new title'], @item_list_map["#{ITUNES_LEADER}nam"].to_string_list
89
+ end
90
+
91
+ should "unlink items that get replaced" do
92
+ title = @item_list_map["#{ITUNES_LEADER}nam"]
93
+ @item_list_map.insert("#{ITUNES_LEADER}nam", TagLib::MP4::Item.from_int(1))
94
+ begin
95
+ title.to_string_list
96
+ flunk("Should have raised ObjectPreviouslyDeleted.")
97
+ rescue => e
98
+ assert_equal "ObjectPreviouslyDeleted", e.class.to_s
99
+ end
100
+ end
101
+ end
102
+
103
+ context "TagLib::MP4::Item" do
104
+ should "be creatable from an int" do
105
+ item = TagLib::MP4::Item.from_int(-42)
106
+ assert_equal TagLib::MP4::Item, item.class
107
+ assert_equal -42, item.to_int
108
+ end
109
+
110
+ should "be creatable from a boolean" do
111
+ item = TagLib::MP4::Item.from_bool(false)
112
+ assert_equal TagLib::MP4::Item, item.class
113
+ assert_equal false, item.to_bool
114
+ end
115
+
116
+ context ".from_int_pair" do
117
+ should "be creatable from a pair of ints" do
118
+ item = TagLib::MP4::Item.from_int_pair([123, 456])
119
+ assert_equal TagLib::MP4::Item, item.class
120
+ assert_equal [123, 456], item.to_int_pair
121
+ end
122
+
123
+ should "raise an error when passed something other than an Array" do
124
+ begin
125
+ TagLib::MP4::Item.from_int_pair(1)
126
+ flunk("Should have raised ArgumentError.")
127
+ rescue => e
128
+ assert_equal "ArgumentError", e.class.to_s
129
+ end
130
+ end
131
+
132
+ should "raise an error when passed an Array with more than two elements" do
133
+ begin
134
+ TagLib::MP4::Item.from_int_pair([1, 2, 3])
135
+ flunk("Should have raised ArgumentError.")
136
+ rescue => e
137
+ assert_equal "ArgumentError", e.class.to_s
138
+ end
139
+ end
140
+
141
+ should "raise an error when passed an Array with less than two elements" do
142
+ begin
143
+ TagLib::MP4::Item.from_int_pair([1])
144
+ flunk("Should have raised ArgumentError.")
145
+ rescue => e
146
+ assert_equal "ArgumentError", e.class.to_s
147
+ end
148
+ end
149
+ end
150
+
151
+ context "created from an array of strings" do
152
+ should "interpreted as strings with an encoding" do
153
+ item = TagLib::MP4::Item.from_string_list(["héllo"])
154
+ assert_equal TagLib::MP4::Item, item.class
155
+ assert_equal ["héllo"], item.to_string_list
156
+ end
157
+ end
158
+
159
+ should "be creatable from a CoverArt list" do
160
+ cover_art = TagLib::MP4::CoverArt.new(TagLib::MP4::CoverArt::JPEG, 'foo')
161
+ item = TagLib::MP4::Item.from_cover_art_list([cover_art])
162
+ assert_equal TagLib::MP4::Item, item.class
163
+ new_cover_art = item.to_cover_art_list.first
164
+ assert_equal 'foo', new_cover_art.data
165
+ assert_equal TagLib::MP4::CoverArt::JPEG, new_cover_art.format
166
+ end
167
+ end
168
+
169
+ context "TagLib::MP4::CoverArt" do
170
+ should "be creatable from a string" do
171
+ cover_art = TagLib::MP4::CoverArt.new(TagLib::MP4::CoverArt::JPEG, 'foo')
172
+ assert_equal TagLib::MP4::CoverArt::JPEG, cover_art.format
173
+ assert_equal 'foo', cover_art.data
174
+ end
175
+ end
176
+
177
+ teardown do
178
+ @file.close
179
+ @file = nil
180
+ end
181
+ end
182
+
183
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taglib-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robin Stocker
9
+ - Jacob Vosmaer
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
13
+ date: 2013-04-26 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -18,7 +19,7 @@ dependencies:
18
19
  requirements:
19
20
  - - ~>
20
21
  - !ruby/object:Gem::Version
21
- version: 1.1.0
22
+ version: '1.2'
22
23
  type: :development
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - ~>
28
29
  - !ruby/object:Gem::Version
29
- version: 1.1.0
30
+ version: '1.2'
30
31
  - !ruby/object:Gem::Dependency
31
32
  name: rake-compiler
32
33
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +76,22 @@ dependencies:
75
76
  - - ~>
76
77
  - !ruby/object:Gem::Version
77
78
  version: '0.7'
79
+ - !ruby/object:Gem::Dependency
80
+ name: kramdown
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '1.0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.0'
78
95
  description: ! 'Ruby interface for the taglib C++ library, for reading and writing
79
96
 
80
97
  meta-data (tags) of many audio formats.
@@ -96,6 +113,7 @@ extensions:
96
113
  - ext/taglib_ogg/extconf.rb
97
114
  - ext/taglib_vorbis/extconf.rb
98
115
  - ext/taglib_flac/extconf.rb
116
+ - ext/taglib_mp4/extconf.rb
99
117
  extra_rdoc_files:
100
118
  - CHANGES.md
101
119
  - LICENSE.txt
@@ -113,6 +131,7 @@ files:
113
131
  - docs/taglib/flac.rb
114
132
  - docs/taglib/id3v1.rb
115
133
  - docs/taglib/id3v2.rb
134
+ - docs/taglib/mp4.rb
116
135
  - docs/taglib/mpeg.rb
117
136
  - docs/taglib/ogg.rb
118
137
  - docs/taglib/vorbis.rb
@@ -121,6 +140,7 @@ files:
121
140
  - ext/taglib_base/includes.i
122
141
  - ext/taglib_base/taglib_base.i
123
142
  - ext/taglib_base/taglib_base_wrap.cxx
143
+ - ext/taglib_flac/extconf.rb
124
144
  - ext/taglib_flac/taglib_flac.i
125
145
  - ext/taglib_flac/taglib_flac_wrap.cxx
126
146
  - ext/taglib_id3v1/extconf.rb
@@ -130,6 +150,9 @@ files:
130
150
  - ext/taglib_id3v2/relativevolumeframe.i
131
151
  - ext/taglib_id3v2/taglib_id3v2.i
132
152
  - ext/taglib_id3v2/taglib_id3v2_wrap.cxx
153
+ - ext/taglib_mp4/extconf.rb
154
+ - ext/taglib_mp4/taglib_mp4.i
155
+ - ext/taglib_mp4/taglib_mp4_wrap.cxx
133
156
  - ext/taglib_mpeg/extconf.rb
134
157
  - ext/taglib_mpeg/taglib_mpeg.i
135
158
  - ext/taglib_mpeg/taglib_mpeg_wrap.cxx
@@ -146,6 +169,7 @@ files:
146
169
  - lib/taglib/flac.rb
147
170
  - lib/taglib/id3v1.rb
148
171
  - lib/taglib/id3v2.rb
172
+ - lib/taglib/mp4.rb
149
173
  - lib/taglib/mpeg.rb
150
174
  - lib/taglib/ogg.rb
151
175
  - lib/taglib/version.rb
@@ -155,15 +179,19 @@ files:
155
179
  - tasks/ext.rake
156
180
  - tasks/gemspec_check.rake
157
181
  - tasks/swig.rake
182
+ - test/base_test.rb
158
183
  - test/data/Makefile
159
184
  - test/data/add-relative-volume.cpp
160
185
  - test/data/crash.mp3
161
186
  - test/data/flac-create.cpp
162
187
  - test/data/flac.flac
188
+ - test/data/get_picture_data.cpp
163
189
  - test/data/globe_east_540.jpg
164
190
  - test/data/globe_east_90.jpg
165
191
  - test/data/id3v1-create.cpp
166
192
  - test/data/id3v1.mp3
193
+ - test/data/mp4-create.cpp
194
+ - test/data/mp4.m4a
167
195
  - test/data/relative-volume.mp3
168
196
  - test/data/sample.mp3
169
197
  - test/data/unicode.mp3
@@ -177,18 +205,21 @@ files:
177
205
  - test/flac_file_write_test.rb
178
206
  - test/id3v1_tag_test.rb
179
207
  - test/id3v2_frames_test.rb
208
+ - test/id3v2_header_test.rb
180
209
  - test/id3v2_memory_test.rb
181
210
  - test/id3v2_relative_volume_test.rb
182
211
  - test/id3v2_tag_test.rb
183
212
  - test/id3v2_unicode_test.rb
184
213
  - test/id3v2_write_test.rb
214
+ - test/mp4_file_test.rb
215
+ - test/mp4_file_write_test.rb
216
+ - test/mp4_items_test.rb
185
217
  - test/mpeg_file_test.rb
186
218
  - test/tag_test.rb
187
219
  - test/unicode_filename_test.rb
188
220
  - test/vorbis_file_test.rb
189
221
  - test/vorbis_tag_test.rb
190
- - ext/taglib_flac/extconf.rb
191
- homepage: http://robinst.github.com/taglib-ruby/
222
+ homepage: http://robinst.github.io/taglib-ruby/
192
223
  licenses:
193
224
  - MIT
194
225
  post_install_message:
@@ -203,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
234
  version: '0'
204
235
  segments:
205
236
  - 0
206
- hash: -3710784466911829915
237
+ hash: -3989506221310826679
207
238
  required_rubygems_version: !ruby/object:Gem::Requirement
208
239
  none: false
209
240
  requirements:
@@ -212,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
243
  version: '0'
213
244
  segments:
214
245
  - 0
215
- hash: -3710784466911829915
246
+ hash: -3989506221310826679
216
247
  requirements:
217
248
  - taglib (libtag1-dev in Debian/Ubuntu, taglib-devel in Fedora/RHEL)
218
249
  rubyforge_project: