id3lib-ruby 0.6.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Binary file
Binary file
Binary file
@@ -0,0 +1,82 @@
1
+
2
+ require 'test/unit'
3
+ require 'id3lib'
4
+
5
+
6
+ class TestReading < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @tag = ID3Lib::Tag.new('test/data/sample.mp3')
10
+ end
11
+
12
+ def test_array
13
+ assert_equal 'Dummy Title', @tag[0][:text]
14
+ assert_equal 'Dummy Artist', @tag[1][:text]
15
+ assert_equal 'Dummy Album', @tag[2][:text]
16
+ assert_equal '1/10', @tag[3][:text]
17
+ assert_equal '2000', @tag[4][:text]
18
+ assert_equal 'Dummy Comment', @tag[5][:text]
19
+ assert_equal 'Dummy Comment 2', @tag[6][:text]
20
+ assert_equal 'Pop', @tag[7][:text]
21
+ end
22
+
23
+ def test_direct_access
24
+ assert_equal 'Dummy Title', @tag.title
25
+ assert_equal 'Dummy Artist', @tag.artist
26
+ assert_equal 'Dummy Artist', @tag.performer
27
+ assert_equal 'Dummy Album', @tag.album
28
+ assert_equal '1/10', @tag.track
29
+ assert_equal '2000', @tag.year
30
+ assert_equal 'Dummy Comment', @tag.comment
31
+ assert_equal 'Pop', @tag.genre
32
+ end
33
+
34
+ def test_frame_text
35
+ assert_equal 'Dummy Title', @tag.frame_text(:TIT2)
36
+ assert_equal 'Dummy Artist', @tag.frame_text(:TPE1)
37
+ assert_equal 'Dummy Album', @tag.frame_text(:TALB)
38
+ assert_equal '1/10', @tag.frame_text(:TRCK)
39
+ assert_equal '2000', @tag.frame_text(:TYER)
40
+ assert_equal 'Dummy Comment', @tag.frame_text(:COMM)
41
+ assert_equal 'Pop', @tag.frame_text(:TCON)
42
+ assert_equal nil, @tag.frame_text(:AENC)
43
+ end
44
+
45
+ def test_user_frame_text
46
+ album_id = @tag.user_frame_text('MusicBrainz Album Id')
47
+ assert_equal '992dc19a-5631-40f5-b252-fbfedbc328a9', album_id
48
+ assert_equal nil, @tag.user_frame_text('Inexistent')
49
+ end
50
+
51
+ def test_comments
52
+ one, two = @tag.comment_frames
53
+ assert_not_nil one
54
+ assert_not_nil two
55
+ assert_equal 'Dummy Comment', one[:text]
56
+ assert_equal 'Dummy Comment 2', two[:text]
57
+ end
58
+
59
+ def test_has_tag
60
+ assert @tag.has_tag?(ID3Lib::V1)
61
+ assert @tag.has_tag?(ID3Lib::V2)
62
+ end
63
+
64
+ def test_size
65
+ assert_equal 2038, @tag.size
66
+ end
67
+
68
+ def test_invalid_frames
69
+ assert_nil @tag.invalid_frames
70
+
71
+ @tag << { :id => :TITS }
72
+ assert_equal [[:TITS]], @tag.invalid_frames
73
+
74
+ @tag << { :id => :TALB, :invalid => 'text' }
75
+ assert_equal [[:TITS], [:TALB, :invalid]], @tag.invalid_frames
76
+
77
+ @tag << { :id => :APIC, :text => 'invalid' }
78
+ assert_equal [[:TITS], [:TALB, :invalid], [:APIC, :text]],
79
+ @tag.invalid_frames
80
+ end
81
+
82
+ end
@@ -0,0 +1,85 @@
1
+
2
+ require 'test/unit'
3
+ require 'fileutils'
4
+ require 'id3lib'
5
+
6
+
7
+ class TestUnicode < Test::Unit::TestCase
8
+
9
+ Sample = 'test/data/sample.mp3'
10
+ Temp = 'test/data/tmp.sample.mp3'
11
+
12
+ def setup
13
+ FileUtils.cp Sample, Temp
14
+ @tag = ID3Lib::Tag.new(Temp)
15
+ end
16
+
17
+ def teardown
18
+ FileUtils.rm Temp
19
+ end
20
+
21
+ # Failing because of id3lib.
22
+ def dont_test_UTF16BE
23
+ do_unicode_test :text => "\x4f\x60\x59\x7d", :textenc => 2
24
+ end
25
+
26
+ def test_UTF16LE
27
+ do_unicode_test :text => "\x60\x4f\x7d\x59", :textenc => 1
28
+ end
29
+
30
+ # Failing because of id3lib.
31
+ def dont_test_UTF16BE_with_BOM
32
+ do_unicode_test :text => "\xfe\xff\x4f\x60\x59\x7d", :textenc => 1
33
+ end
34
+
35
+ def test_UTF16LE_with_BOM
36
+ do_unicode_test :text => "\xff\xfe\x60\x4f\x7d\x59", :textenc => 1
37
+ end
38
+
39
+ # Failing because of id3lib.
40
+ def dont_test_UTF16BE_above_127
41
+ do_unicode_test :text => "\xfe\xffC\346", :textenc => 1
42
+ end
43
+
44
+ def test_UTF16LE_above_127
45
+ do_unicode_test :text => "\xe6C", :textenc => 1
46
+ end
47
+
48
+ def test_UTF16LE_above_127_with_BOM
49
+ do_unicode_test :text => "\xff\xfe\xe6C", :textenc => 1
50
+ end
51
+
52
+ def test_reading
53
+ @tag = ID3Lib::Tag.new('test/data/unicode.mp3', ID3Lib::V2)
54
+ assert_equal "\x4f\x60\x59\x7d", @tag.title
55
+ end
56
+
57
+ def test_reading_lyrics
58
+ @tag = ID3Lib::Tag.new('test/data/unicode.mp3', ID3Lib::V2)
59
+ lyrics = @tag.find{ |f| f[:id] == :USLT }
60
+ assert_equal 1, lyrics[:textenc]
61
+ assert_equal "zho", lyrics[:language]
62
+ # This is "U+6771 U+4EAC" (Tokyo) in UTF-16BE
63
+ tokyo = "\x67\x71\x4e\xac"
64
+ assert_equal tokyo, lyrics[:text]
65
+ end
66
+
67
+ def test_invalid_data
68
+ nonstr = 1
69
+ @tag.reject!{ |f| f[:id] == :TIT2 }
70
+ @tag << {:id => :TIT2, :text => nonstr, :textenc => 1}
71
+ assert_raise(TypeError) { @tag.update!(ID3Lib::V2) }
72
+ end
73
+
74
+ def do_unicode_test(opts)
75
+ frame = {:id => :TIT2}
76
+ frame.update(opts)
77
+ @tag.title = nil
78
+ @tag << frame
79
+ @tag.update!(ID3Lib::V2)
80
+ assert_equal frame, @tag.frame(:TIT2)
81
+ @tag = ID3Lib::Tag.new(Temp, ID3Lib::V2)
82
+ assert_equal frame, @tag.frame(:TIT2)
83
+ end
84
+
85
+ end
@@ -0,0 +1,221 @@
1
+
2
+ require 'test/unit'
3
+ require 'fileutils'
4
+ require 'id3lib'
5
+
6
+
7
+ class TestWriting < Test::Unit::TestCase
8
+
9
+ Sample = 'test/data/sample.mp3'
10
+ Temp = 'test/data/tmp.sample.mp3'
11
+
12
+ def setup
13
+ FileUtils.cp Sample, Temp
14
+ reload!
15
+ end
16
+
17
+ def teardown
18
+ FileUtils.rm Temp
19
+ end
20
+
21
+ def reload!(*args)
22
+ @tag = ID3Lib::Tag.new(Temp, *args)
23
+ end
24
+
25
+ # Test the title direct access. The others like performer or album
26
+ # work alike
27
+ def test_title
28
+ @tag.title = 'New Title'
29
+ assert_equal 'New Title', @tag.title
30
+ @tag.update!
31
+ assert_equal 'New Title', @tag.title
32
+ reload!
33
+ assert_equal 'New Title', @tag.title
34
+ end
35
+
36
+ def test_genre
37
+ @tag.genre = 'Rock'
38
+ assert_equal 'Rock', @tag.genre
39
+ @tag.update!
40
+ assert_equal 'Rock', @tag.genre
41
+ reload!
42
+ assert_equal 'Rock', @tag.genre
43
+ end
44
+
45
+ def test_id3v1_genre
46
+ @tag.strip!(ID3Lib::V2)
47
+ genre_id = '(' + ID3Lib::Info::Genres.index('Rock').to_s + ')'
48
+ @tag.genre = genre_id
49
+ assert_equal genre_id, @tag.genre
50
+ @tag.update!(ID3Lib::V1)
51
+ assert_equal genre_id, @tag.genre
52
+ reload!(ID3Lib::V1)
53
+ assert_equal genre_id, @tag.genre
54
+ end
55
+
56
+ def test_track
57
+ @tag.track = '4'
58
+ assert_equal '4', @tag.track
59
+ @tag.update!
60
+ assert_equal '4', @tag.track
61
+ reload!
62
+ assert_equal '4', @tag.track
63
+
64
+ @tag.track = '5/12'
65
+ assert_equal '5/12', @tag.track
66
+ @tag.update!
67
+ assert_equal '5/12', @tag.track
68
+ reload!
69
+ assert_equal '5/12', @tag.track
70
+
71
+ @tag.track = 6
72
+ assert_equal '6', @tag.track
73
+ @tag.update!
74
+ assert_equal '6', @tag.track
75
+ reload!
76
+ assert_equal '6', @tag.track
77
+ end
78
+
79
+ def test_year
80
+ @tag.year = '2001'
81
+ assert_equal '2001', @tag.year
82
+ @tag.update!
83
+ assert_equal '2001', @tag.year
84
+ reload!
85
+ assert_equal '2001', @tag.year
86
+
87
+ @tag.year = 2002
88
+ assert_equal '2002', @tag.year
89
+ @tag.update!
90
+ assert_equal '2002', @tag.year
91
+ reload!
92
+ assert_equal '2002', @tag.year
93
+ end
94
+
95
+ def test_comments
96
+ @tag.comment = 'New Comment'
97
+ assert_equal 'New Comment', @tag.comment
98
+ assert_equal 1, @tag.comment_frames.length
99
+ one = @tag.comment_frames.first
100
+ assert_equal 'New Comment', one[:text]
101
+
102
+ @tag.update!
103
+ assert_equal 'New Comment', @tag.comment
104
+
105
+ reload!
106
+ assert_equal 'New Comment', @tag.comment
107
+ end
108
+
109
+ def test_manual_frame
110
+ @tag << {:id => :TLAN, :text => 'zho'}
111
+ assert_equal 'zho', @tag.frame_text(:TLAN)
112
+ @tag.update!
113
+ assert_equal 'zho', @tag.frame_text(:TLAN)
114
+ reload!
115
+ assert_equal 'zho', @tag.frame_text(:TLAN)
116
+ end
117
+
118
+ def test_apic
119
+ pic = {
120
+ :id => :APIC,
121
+ :mimetype => 'image/jpeg',
122
+ :imageformat => '',
123
+ :picturetype => 3,
124
+ :description => 'A pretty picture.',
125
+ :textenc => 0,
126
+ :data => File.read('test/data/cover.jpg')
127
+ }
128
+ @tag << pic
129
+ @tag.update!
130
+ assert_equal pic, @tag.frame(:APIC)
131
+ reload!
132
+ assert_equal pic, @tag.frame(:APIC)
133
+ end
134
+
135
+ def test_remove_frame
136
+ @tag.remove_frame(:TIT2)
137
+ assert_nil @tag.frame(:TIT2)
138
+ end
139
+
140
+ def test_remove_frame_with_direct_access
141
+ @tag.title = nil
142
+ assert_nil @tag.frame(:TIT2)
143
+ end
144
+
145
+ def test_wrong_frame
146
+ l = @tag.length
147
+ @tag << {:id => :WRONG, :text => "Test"}
148
+ @tag.update!
149
+ assert_equal l, @tag.length
150
+ reload!
151
+ assert_equal l, @tag.length
152
+ end
153
+
154
+ def test_strip
155
+ @tag.strip!
156
+ assert @tag.empty?
157
+ reload!
158
+ assert @tag.empty?
159
+ end
160
+
161
+ def test_tagtype
162
+ @tag.strip!(ID3Lib::V1)
163
+ reload!(ID3Lib::V1)
164
+ assert @tag.empty?
165
+ reload!
166
+ assert !@tag.empty?
167
+ @tag.strip!(ID3Lib::V2)
168
+ reload!(ID3Lib::V2)
169
+ assert @tag.empty?
170
+ reload!
171
+ assert @tag.empty?
172
+ end
173
+
174
+ def test_padding
175
+ assert_equal 2176, File.size(Temp)
176
+ @tag.padding = false
177
+ @tag.update!
178
+ assert_equal 416, File.size(Temp)
179
+ end
180
+
181
+ def test_failing_update
182
+ # Note filename which is a directory -> update! should fail
183
+ @tag = ID3Lib::Tag.new("test/data/")
184
+ @tag.performer = "Nobody"
185
+ assert_equal nil, @tag.update!
186
+ end
187
+
188
+ def test_accessors
189
+ accessors = %w[
190
+ title performer album genre year track part_of_set comment composer
191
+ grouping bpm subtitle date time language lyrics lyricist band
192
+ conductor interpreted_by publisher encoded_by
193
+ ]
194
+ do_tests_for_accessors(accessors)
195
+ end
196
+
197
+ def test_accessor_aliases
198
+ aliases = %w[ artist content_type disc remixed_by ]
199
+ do_tests_for_accessors(aliases)
200
+ end
201
+
202
+ def do_tests_for_accessors(accessors)
203
+ accessors.each do |m|
204
+ @tag.send("#{m}=", "#{m} test")
205
+ assert_equal "#{m} test", @tag.send(m)
206
+ end
207
+
208
+ @tag.update!
209
+
210
+ accessors.each do |m|
211
+ assert_equal "#{m} test", @tag.send(m)
212
+ end
213
+
214
+ reload!
215
+
216
+ accessors.each do |m|
217
+ assert_equal "#{m} test", @tag.send(m)
218
+ end
219
+ end
220
+
221
+ end
@@ -0,0 +1,40 @@
1
+
2
+ require 'rubygems'
3
+ require 'id3lib'
4
+
5
+ # Load a tag from a file
6
+ tag = ID3Lib::Tag.new('talk.mp3')
7
+
8
+ # Get and set text frames with convenience methods
9
+ tag.title #=> "Talk"
10
+ tag.album = 'X&Y'
11
+ tag.track = '5/13'
12
+
13
+ # Tag is a subclass of Array and each frame is a Hash
14
+ tag[0]
15
+ #=> { :id => :TPE1, :textenc => 0, :text => "Coldplay" }
16
+
17
+ # Get the number of frames
18
+ tag.length #=> 7
19
+
20
+ # Remove all comment frames
21
+ tag.delete_if{ |frame| frame[:id] == :COMM }
22
+
23
+ # Get info about APIC frame to see which fields are allowed
24
+ ID3Lib::Info.frame(:APIC)
25
+ #=> [ 2, :APIC, "Attached picture",
26
+ #=> [:textenc, :mimetype, :picturetype, :description, :data] ]
27
+
28
+ # Add an attached picture frame
29
+ cover = {
30
+ :id => :APIC,
31
+ :mimetype => 'image/jpeg',
32
+ :picturetype => 3,
33
+ :description => 'A pretty picture',
34
+ :textenc => 0,
35
+ :data => File.read('cover.jpg')
36
+ }
37
+ tag << cover
38
+
39
+ # Last but not least, apply changes
40
+ tag.update!
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: id3lib-ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
10
+ platform: x86-mswin32-60
11
+ authors:
12
+ - Robin Stocker
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ = id3lib-ruby
23
+
24
+ id3lib-ruby provides a Ruby interface to the id3lib C++ library for easily
25
+ editing ID3 tags (v1 and v2) of MP3 audio files.
26
+
27
+ The class documentation starts at ID3Lib::Tag.
28
+
29
+
30
+ == Features
31
+
32
+ * Read and write ID3v1 and ID3v2 tags
33
+ * Simple interface for adding, changing and removing frames
34
+ * Quick access to common text frames like title and performer
35
+ * Custom data frames like attached picture (APIC)
36
+ * Pretty complete coverage of id3lib's features
37
+ * UTF-16 support (warning: id3lib writes broken UTF-16 frames)
38
+ * Windows binary gem available
39
+
40
+ The CHANGES file contains a list of changes between versions.
41
+
42
+
43
+ == Installation
44
+
45
+ See INSTALL.
46
+
47
+
48
+ == Online Information
49
+
50
+ The home of id3lib-ruby is http://id3lib-ruby.rubyforge.org
51
+
52
+
53
+ == Usage
54
+
55
+ require 'rubygems'
56
+ require 'id3lib'
57
+
58
+ # Load a tag from a file
59
+ tag = ID3Lib::Tag.new('talk.mp3')
60
+
61
+ # Get and set text frames with convenience methods
62
+ tag.title #=> "Talk"
63
+ tag.album = 'X&Y'
64
+ tag.track = '5/13'
65
+
66
+ # Tag is a subclass of Array and each frame is a Hash
67
+ tag[0]
68
+ #=> { :id => :TPE1, :textenc => 0, :text => "Coldplay" }
69
+
70
+ # Get the number of frames
71
+ tag.length #=> 7
72
+
73
+ # Remove all comment frames
74
+ tag.delete_if{ |frame| frame[:id] == :COMM }
75
+
76
+ # Get info about APIC frame to see which fields are allowed
77
+ ID3Lib::Info.frame(:APIC)
78
+ #=> [ 2, :APIC, "Attached picture",
79
+ #=> [:textenc, :mimetype, :picturetype, :description, :data] ]
80
+
81
+ # Add an attached picture frame
82
+ cover = {
83
+ :id => :APIC,
84
+ :mimetype => 'image/jpeg',
85
+ :picturetype => 3,
86
+ :description => 'A pretty picture',
87
+ :textenc => 0,
88
+ :data => File.read('cover.jpg')
89
+ }
90
+ tag << cover
91
+
92
+ # Last but not least, apply changes
93
+ tag.update!
94
+
95
+
96
+ == Licence
97
+
98
+ This library has Ruby's licence:
99
+
100
+ http://www.ruby-lang.org/en/LICENSE.txt
101
+
102
+
103
+ == Author
104
+
105
+ Robin Stocker <robinstocker at rubyforge.org>
106
+
107
+ email: robinstocker@rubyforge.org
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files:
113
+ - README
114
+ - INSTALL
115
+ - TODO
116
+ - CHANGES
117
+ files:
118
+ - lib/id3lib/accessors.rb
119
+ - lib/id3lib/info.rb
120
+ - lib/id3lib.rb
121
+ - test/test_unicode.rb
122
+ - test/test_writing.rb
123
+ - test/test_reading.rb
124
+ - test/data/sample.mp3
125
+ - test/data/unicode.mp3
126
+ - test/data/cover.jpg
127
+ - Rakefile
128
+ - usage.rb
129
+ - setup.rb
130
+ - ext/id3lib_api/extconf.rb
131
+ - ext/id3lib_api/id3lib_api_wrap.cxx
132
+ - ext/id3lib_api/id3lib_api.i
133
+ - ext/id3lib_api/Rakefile
134
+ - README
135
+ - INSTALL
136
+ - TODO
137
+ - CHANGES
138
+ - lib/id3lib_api.so
139
+ has_rdoc: true
140
+ homepage: http://id3lib-ruby.rubyforge.org
141
+ licenses: []
142
+
143
+ post_install_message:
144
+ rdoc_options:
145
+ - --inline-source
146
+ - --line-numbers
147
+ - --main
148
+ - README
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ requirements:
166
+ - id3lib C++ library
167
+ rubyforge_project: id3lib-ruby
168
+ rubygems_version: 1.3.6
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: id3lib-ruby provides a Ruby interface to the id3lib C++ library for easily editing ID3 tags (v1 and v2) of MP3 audio files.
172
+ test_files:
173
+ - test/test_unicode.rb
174
+ - test/test_writing.rb
175
+ - test/test_reading.rb