id3lib-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -0
- data/README +91 -0
- data/Rakefile +108 -0
- data/TODO +9 -0
- data/ext/extconf.rb +6 -0
- data/ext/id3lib_api_wrap.cxx +1950 -0
- data/lib/id3lib.rb +349 -0
- data/lib/id3lib/accessors.rb +260 -0
- data/lib/id3lib/info.rb +253 -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 +56 -0
- data/test/test_writing.rb +214 -0
- metadata +63 -0
data/test/data/cover.jpg
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
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
|
+
end
|
@@ -0,0 +1,214 @@
|
|
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
|
+
# The track can be set in various ways. Test them all :)
|
57
|
+
def test_track
|
58
|
+
@tag.track = 1
|
59
|
+
assert_equal [1], @tag.track
|
60
|
+
@tag.update!
|
61
|
+
assert_equal [1], @tag.track
|
62
|
+
reload!
|
63
|
+
assert_equal [1], @tag.track
|
64
|
+
|
65
|
+
@tag.track = [2]
|
66
|
+
assert_equal [2], @tag.track
|
67
|
+
@tag.update!
|
68
|
+
assert_equal [2], @tag.track
|
69
|
+
reload!
|
70
|
+
assert_equal [2], @tag.track
|
71
|
+
|
72
|
+
@tag.track = [3,10]
|
73
|
+
assert_equal [3,10], @tag.track
|
74
|
+
@tag.update!
|
75
|
+
assert_equal [3,10], @tag.track
|
76
|
+
reload!
|
77
|
+
assert_equal [3,10], @tag.track
|
78
|
+
|
79
|
+
@tag.track = '4'
|
80
|
+
assert_equal [4], @tag.track
|
81
|
+
@tag.update!
|
82
|
+
assert_equal [4], @tag.track
|
83
|
+
reload!
|
84
|
+
assert_equal [4], @tag.track
|
85
|
+
|
86
|
+
@tag.track = '5/12'
|
87
|
+
assert_equal [5,12], @tag.track
|
88
|
+
@tag.update!
|
89
|
+
assert_equal [5,12], @tag.track
|
90
|
+
reload!
|
91
|
+
assert_equal [5,12], @tag.track
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_year
|
95
|
+
@tag.year = 2001
|
96
|
+
assert_equal 2001, @tag.year
|
97
|
+
@tag.update!
|
98
|
+
assert_equal 2001, @tag.year
|
99
|
+
reload!
|
100
|
+
assert_equal 2001, @tag.year
|
101
|
+
|
102
|
+
@tag.year = '2002'
|
103
|
+
assert_equal 2002, @tag.year
|
104
|
+
@tag.update!
|
105
|
+
assert_equal 2002, @tag.year
|
106
|
+
reload!
|
107
|
+
assert_equal 2002, @tag.year
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_comments
|
111
|
+
@tag.comment = 'New Comment'
|
112
|
+
assert_equal 'New Comment', @tag.comment
|
113
|
+
assert_equal 1, @tag.comment_frames.length
|
114
|
+
one = @tag.comment_frames.first
|
115
|
+
assert_equal 'New Comment', one[:text]
|
116
|
+
|
117
|
+
@tag.update!
|
118
|
+
assert_equal 'New Comment', @tag.comment
|
119
|
+
|
120
|
+
reload!
|
121
|
+
assert_equal 'New Comment', @tag.comment
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_manual_frame
|
125
|
+
@tag << {:id => :TLAN, :text => 'zho'}
|
126
|
+
assert_equal 'zho', @tag.frame_text(:TLAN)
|
127
|
+
@tag.update!
|
128
|
+
assert_equal 'zho', @tag.frame_text(:TLAN)
|
129
|
+
reload!
|
130
|
+
assert_equal 'zho', @tag.frame_text(:TLAN)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_apic
|
134
|
+
pic = {
|
135
|
+
:id => :APIC,
|
136
|
+
:mimetype => 'image/jpeg',
|
137
|
+
:picturetype => 3,
|
138
|
+
:description => 'A pretty picture.',
|
139
|
+
:textenc => 0,
|
140
|
+
:data => File.read('test/data/cover.jpg')
|
141
|
+
}
|
142
|
+
@tag << pic
|
143
|
+
@tag.update!
|
144
|
+
assert_equal pic, @tag.frame(:APIC)
|
145
|
+
reload!
|
146
|
+
assert_equal pic, @tag.frame(:APIC)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_remove_frame
|
150
|
+
@tag.remove_frame(:TIT2)
|
151
|
+
assert_nil @tag.frame(:TIT2)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_wrong_frame
|
155
|
+
l = @tag.length
|
156
|
+
@tag << {:id => :WRONG, :text => "Test"}
|
157
|
+
@tag.update!
|
158
|
+
assert_equal l, @tag.length
|
159
|
+
reload!
|
160
|
+
assert_equal l, @tag.length
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_strip
|
164
|
+
@tag.strip!
|
165
|
+
assert @tag.empty?
|
166
|
+
reload!
|
167
|
+
assert @tag.empty?
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_tagtype
|
171
|
+
@tag.strip!(ID3Lib::V1)
|
172
|
+
reload!(ID3Lib::V1)
|
173
|
+
assert @tag.empty?
|
174
|
+
reload!
|
175
|
+
assert !@tag.empty?
|
176
|
+
@tag.strip!(ID3Lib::V2)
|
177
|
+
reload!(ID3Lib::V2)
|
178
|
+
assert @tag.empty?
|
179
|
+
reload!
|
180
|
+
assert @tag.empty?
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_unicode
|
184
|
+
nihao = "\x4f\x60\x59\x7d"
|
185
|
+
@tag.reject!{ |f| f[:id] == :TIT2 }
|
186
|
+
@tag << {:id => :TIT2, :text => nihao, :textenc => 1}
|
187
|
+
@tag.update!(ID3Lib::V2)
|
188
|
+
assert_equal nihao, @tag.title
|
189
|
+
reload!(ID3Lib::V2)
|
190
|
+
assert_equal nihao, @tag.title
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_unicode_invalid_data
|
194
|
+
nonstr = 1
|
195
|
+
@tag.reject!{ |f| f[:id] == :TIT2 }
|
196
|
+
@tag << {:id => :TIT2, :text => nonstr, :textenc => 1}
|
197
|
+
assert_raise(TypeError) { @tag.update!(ID3Lib::V2) }
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_padding
|
201
|
+
assert_equal 2176, File.size(Temp)
|
202
|
+
@tag.padding = false
|
203
|
+
@tag.update!
|
204
|
+
assert_equal 348, File.size(Temp)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_failing_update
|
208
|
+
# Note filename which is a directory -> update! should fail
|
209
|
+
@tag = ID3Lib::Tag.new("test/data/")
|
210
|
+
@tag.performer = "Nobody"
|
211
|
+
assert_equal nil, @tag.update!
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
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.1.0
|
7
|
+
date: 2006-04-24 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
|
+
email: robinstocker@rubyforge.org
|
12
|
+
homepage: http://id3lib-ruby.rubyforge.org
|
13
|
+
rubyforge_project: id3lib-ruby
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
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
|
+
- ext/extconf.rb
|
36
|
+
- ext/id3lib_api_wrap.cxx
|
37
|
+
- test/test_reading.rb
|
38
|
+
- test/test_writing.rb
|
39
|
+
- test/data/sample.mp3
|
40
|
+
- test/data/unicode.mp3
|
41
|
+
- test/data/cover.jpg
|
42
|
+
- Rakefile
|
43
|
+
- setup.rb
|
44
|
+
- README
|
45
|
+
- CHANGES
|
46
|
+
- TODO
|
47
|
+
test_files:
|
48
|
+
- test/test_reading.rb
|
49
|
+
- test/test_writing.rb
|
50
|
+
rdoc_options:
|
51
|
+
- "--line-numbers"
|
52
|
+
- "--main"
|
53
|
+
- README
|
54
|
+
extra_rdoc_files:
|
55
|
+
- README
|
56
|
+
- CHANGES
|
57
|
+
- TODO
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/extconf.rb
|
61
|
+
requirements:
|
62
|
+
- id3lib C++ library
|
63
|
+
dependencies: []
|