id3lib-ruby 0.3.0-mswin32
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.
- data/CHANGES +28 -0
- data/README +95 -0
- data/Rakefile +119 -0
- data/TODO +4 -0
- data/ext/mswin32/id3lib_api.so +0 -0
- data/lib/id3lib.rb +384 -0
- data/lib/id3lib/accessors.rb +103 -0
- data/lib/id3lib/info.rb +389 -0
- data/setup.rb +1585 -0
- data/test/data/cover.jpg +0 -0
- data/test/data/sample.mp3 +0 -0
- data/test/data/unicode.mp3 +0 -0
- data/test/test_reading.rb +70 -0
- data/test/test_writing.rb +237 -0
- metadata +64 -0
data/test/data/cover.jpg
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,70 @@
|
|
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_comments
|
35
|
+
one, two = @tag.comment_frames
|
36
|
+
assert_not_nil one
|
37
|
+
assert_not_nil two
|
38
|
+
assert_equal 'Dummy Comment', one[:text]
|
39
|
+
assert_equal 'Dummy Comment 2', two[:text]
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_unicode
|
43
|
+
@tag = ID3Lib::Tag.new('test/data/unicode.mp3', ID3Lib::V2)
|
44
|
+
assert_equal "\x4f\x60\x59\x7d", @tag.title
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_has_tag
|
48
|
+
assert @tag.has_tag?(ID3Lib::V1)
|
49
|
+
assert @tag.has_tag?(ID3Lib::V2)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_size
|
53
|
+
assert_equal 2038, @tag.size
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_invalid_frames
|
57
|
+
assert_nil @tag.invalid_frames
|
58
|
+
|
59
|
+
@tag << { :id => :TITS }
|
60
|
+
assert_equal [[:TITS]], @tag.invalid_frames
|
61
|
+
|
62
|
+
@tag << { :id => :TALB, :invalid => 'text' }
|
63
|
+
assert_equal [[:TITS], [:TALB, :invalid]], @tag.invalid_frames
|
64
|
+
|
65
|
+
@tag << { :id => :APIC, :text => 'invalid' }
|
66
|
+
assert_equal [[:TITS], [:TALB, :invalid], [:APIC, :text]],
|
67
|
+
@tag.invalid_frames
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,237 @@
|
|
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
|
+
:picturetype => 3,
|
123
|
+
:description => 'A pretty picture.',
|
124
|
+
:textenc => 0,
|
125
|
+
:data => File.read('test/data/cover.jpg')
|
126
|
+
}
|
127
|
+
@tag << pic
|
128
|
+
@tag.update!
|
129
|
+
assert_equal pic, @tag.frame(:APIC)
|
130
|
+
reload!
|
131
|
+
assert_equal pic, @tag.frame(:APIC)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_remove_frame
|
135
|
+
@tag.remove_frame(:TIT2)
|
136
|
+
assert_nil @tag.frame(:TIT2)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_remove_frame_with_direct_access
|
140
|
+
@tag.title = nil
|
141
|
+
assert_nil @tag.frame(:TIT2)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_wrong_frame
|
145
|
+
l = @tag.length
|
146
|
+
@tag << {:id => :WRONG, :text => "Test"}
|
147
|
+
@tag.update!
|
148
|
+
assert_equal l, @tag.length
|
149
|
+
reload!
|
150
|
+
assert_equal l, @tag.length
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_strip
|
154
|
+
@tag.strip!
|
155
|
+
assert @tag.empty?
|
156
|
+
reload!
|
157
|
+
assert @tag.empty?
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_tagtype
|
161
|
+
@tag.strip!(ID3Lib::V1)
|
162
|
+
reload!(ID3Lib::V1)
|
163
|
+
assert @tag.empty?
|
164
|
+
reload!
|
165
|
+
assert !@tag.empty?
|
166
|
+
@tag.strip!(ID3Lib::V2)
|
167
|
+
reload!(ID3Lib::V2)
|
168
|
+
assert @tag.empty?
|
169
|
+
reload!
|
170
|
+
assert @tag.empty?
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_unicode
|
174
|
+
nihao = "\x4f\x60\x59\x7d"
|
175
|
+
@tag.reject!{ |f| f[:id] == :TIT2 }
|
176
|
+
@tag << {:id => :TIT2, :text => nihao, :textenc => 1}
|
177
|
+
@tag.update!(ID3Lib::V2)
|
178
|
+
assert_equal nihao, @tag.title
|
179
|
+
reload!(ID3Lib::V2)
|
180
|
+
assert_equal nihao, @tag.title
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_unicode_invalid_data
|
184
|
+
nonstr = 1
|
185
|
+
@tag.reject!{ |f| f[:id] == :TIT2 }
|
186
|
+
@tag << {:id => :TIT2, :text => nonstr, :textenc => 1}
|
187
|
+
assert_raise(TypeError) { @tag.update!(ID3Lib::V2) }
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_padding
|
191
|
+
assert_equal 2176, File.size(Temp)
|
192
|
+
@tag.padding = false
|
193
|
+
@tag.update!
|
194
|
+
assert_equal 348, File.size(Temp)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_failing_update
|
198
|
+
# Note filename which is a directory -> update! should fail
|
199
|
+
@tag = ID3Lib::Tag.new("test/data/")
|
200
|
+
@tag.performer = "Nobody"
|
201
|
+
assert_equal nil, @tag.update!
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_accessors
|
205
|
+
accessors = %w[
|
206
|
+
title performer album genre year track part_of_set comment composer
|
207
|
+
grouping bpm subtitle date time language lyrics lyricist band
|
208
|
+
conductor interpreted_by publisher encoded_by
|
209
|
+
]
|
210
|
+
do_tests_for_accessors(accessors)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_accessor_aliases
|
214
|
+
aliases = %w[ artist content_type disc remixed_by ]
|
215
|
+
do_tests_for_accessors(aliases)
|
216
|
+
end
|
217
|
+
|
218
|
+
def do_tests_for_accessors(accessors)
|
219
|
+
accessors.each do |m|
|
220
|
+
@tag.send("#{m}=", "#{m} test")
|
221
|
+
assert_equal "#{m} test", @tag.send(m)
|
222
|
+
end
|
223
|
+
|
224
|
+
@tag.update!
|
225
|
+
|
226
|
+
accessors.each do |m|
|
227
|
+
assert_equal "#{m} test", @tag.send(m)
|
228
|
+
end
|
229
|
+
|
230
|
+
reload!
|
231
|
+
|
232
|
+
accessors.each do |m|
|
233
|
+
assert_equal "#{m} test", @tag.send(m)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: id3lib-ruby
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2006-05-28 00:00:00 +02:00
|
8
|
+
summary: id3lib-ruby provides a Ruby interface to the id3lib C++ library for easily editing ID3 tags (v1 and v2) like with pyid3lib.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- ext/mswin32
|
12
|
+
email: robinstocker@rubyforge.org
|
13
|
+
homepage: http://id3lib-ruby.rubyforge.org
|
14
|
+
rubyforge_project: id3lib-ruby
|
15
|
+
description:
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: mswin32
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- Robin Stocker
|
31
|
+
files:
|
32
|
+
- lib/id3lib.rb
|
33
|
+
- lib/id3lib/accessors.rb
|
34
|
+
- lib/id3lib/info.rb
|
35
|
+
- test/test_writing.rb
|
36
|
+
- test/test_reading.rb
|
37
|
+
- test/data/sample.mp3
|
38
|
+
- test/data/unicode.mp3
|
39
|
+
- test/data/cover.jpg
|
40
|
+
- Rakefile
|
41
|
+
- setup.rb
|
42
|
+
- ext/mswin32/id3lib_api.so
|
43
|
+
- README
|
44
|
+
- CHANGES
|
45
|
+
- TODO
|
46
|
+
test_files:
|
47
|
+
- test/test_writing.rb
|
48
|
+
- test/test_reading.rb
|
49
|
+
rdoc_options:
|
50
|
+
- --line-numbers
|
51
|
+
- --main
|
52
|
+
- README
|
53
|
+
extra_rdoc_files:
|
54
|
+
- README
|
55
|
+
- CHANGES
|
56
|
+
- TODO
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
requirements:
|
62
|
+
- id3lib C++ library
|
63
|
+
dependencies: []
|
64
|
+
|