mp3file 1.2.0 → 1.3.0
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.
- checksums.yaml +5 -5
- data/.travis.yml +4 -5
- data/lib/mp3file/mp3_header.rb +4 -0
- data/lib/mp3file/version.rb +1 -1
- data/mp3file.gemspec +2 -2
- data/spec/mp3file/id3v1_tag_spec.rb +100 -22
- data/spec/mp3file/id3v2/bit_padded_int_spec.rb +22 -22
- data/spec/mp3file/id3v2/frame_header_spec.rb +180 -36
- data/spec/mp3file/id3v2/header_spec.rb +221 -53
- data/spec/mp3file/id3v2/tag_spec.rb +40 -8
- data/spec/mp3file/id3v2/version_spec.rb +103 -23
- data/spec/mp3file/mp3_file_spec.rb +549 -106
- data/spec/mp3file/mp3_header_spec.rb +60 -43
- data/spec/mp3file/xing_header_spec.rb +121 -26
- metadata +7 -13
@@ -6,126 +6,294 @@ include CommonHelpers
|
|
6
6
|
describe Mp3file::ID3v2::Header do
|
7
7
|
it "raises an error if the first 3 bytes don't say \"ID3\"" do
|
8
8
|
io = StringIO.new("ID2\x03\x00\x00\x00\x00\x00\x00")
|
9
|
-
|
9
|
+
expect { Mp3file::ID3v2::Header.new(io) }.to(raise_error(Mp3file::ID3v2::InvalidID3v2TagError))
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises an error if the major version is more than 4 (e.g., no ID3v2.5.0+)" do
|
13
13
|
io = StringIO.new("ID3\x05\x00\x00\x00\x00\x00\x00")
|
14
|
-
|
14
|
+
expect { Mp3file::ID3v2::Header.new(io) }.to(raise_error(Mp3file::ID3v2::InvalidID3v2TagError))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "raises an error if the major version is less than 2 (e.g., no ID3v2.1.0)" do
|
18
18
|
io = StringIO.new("ID3\x01\x00\x00\x00\x00\x00\x00")
|
19
|
-
|
19
|
+
expect { Mp3file::ID3v2::Header.new(io) }.to(raise_error(Mp3file::ID3v2::InvalidID3v2TagError))
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "flags:" do
|
23
23
|
describe "An ID3v2.2 header with no set flags:" do
|
24
24
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x02\x00\x00\x00\x00\x00\x00")) }
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
|
26
|
+
describe '#version' do
|
27
|
+
subject { super().version }
|
28
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_2_0) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#unsynchronized' do
|
32
|
+
subject { super().unsynchronized }
|
33
|
+
it { is_expected.to eq(false) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#extended_header' do
|
37
|
+
subject { super().extended_header }
|
38
|
+
it { is_expected.to eq(false) }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#compression' do
|
42
|
+
subject { super().compression }
|
43
|
+
it { is_expected.to eq(false) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#experimental' do
|
47
|
+
subject { super().experimental }
|
48
|
+
it { is_expected.to eq(false) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#footer' do
|
52
|
+
subject { super().footer }
|
53
|
+
it { is_expected.to eq(false) }
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
describe "An ID3v2.2 header with the unsync flag set:" do
|
34
58
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x02\x00\x80\x00\x00\x00\x00")) }
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
59
|
+
|
60
|
+
describe '#version' do
|
61
|
+
subject { super().version }
|
62
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_2_0) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#unsynchronized' do
|
66
|
+
subject { super().unsynchronized }
|
67
|
+
it { is_expected.to eq(true) }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#extended_header' do
|
71
|
+
subject { super().extended_header }
|
72
|
+
it { is_expected.to eq(false) }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#compression' do
|
76
|
+
subject { super().compression }
|
77
|
+
it { is_expected.to eq(false) }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#experimental' do
|
81
|
+
subject { super().experimental }
|
82
|
+
it { is_expected.to eq(false) }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#footer' do
|
86
|
+
subject { super().footer }
|
87
|
+
it { is_expected.to eq(false) }
|
88
|
+
end
|
41
89
|
end
|
42
90
|
|
43
91
|
describe "An ID3v2.2 header with the compression flag set:" do
|
44
92
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x02\x00\x40\x00\x00\x00\x00")) }
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
93
|
+
|
94
|
+
describe '#version' do
|
95
|
+
subject { super().version }
|
96
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_2_0) }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#unsynchronized' do
|
100
|
+
subject { super().unsynchronized }
|
101
|
+
it { is_expected.to eq(false) }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#extended_header' do
|
105
|
+
subject { super().extended_header }
|
106
|
+
it { is_expected.to eq(false) }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#compression' do
|
110
|
+
subject { super().compression }
|
111
|
+
it { is_expected.to eq(true) }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#experimental' do
|
115
|
+
subject { super().experimental }
|
116
|
+
it { is_expected.to eq(false) }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#footer' do
|
120
|
+
subject { super().footer }
|
121
|
+
it { is_expected.to eq(false) }
|
122
|
+
end
|
51
123
|
end
|
52
124
|
|
53
125
|
describe "An ID3v2.2 header with an invalid flag set" do
|
54
126
|
it "raises an error" do
|
55
|
-
|
56
|
-
|
127
|
+
expect { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x02\x00\x20\x00\x00\x00\x00")) }.
|
128
|
+
to(raise_error(Mp3file::ID3v2::InvalidID3v2TagError))
|
57
129
|
end
|
58
130
|
end
|
59
131
|
|
60
132
|
describe "An ID3v2.3 header with the extended header flag set:" do
|
61
133
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x40\x00\x00\x00\x00")) }
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
134
|
+
|
135
|
+
describe '#version' do
|
136
|
+
subject { super().version }
|
137
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_3_0) }
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#unsynchronized' do
|
141
|
+
subject { super().unsynchronized }
|
142
|
+
it { is_expected.to eq(false) }
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#extended_header' do
|
146
|
+
subject { super().extended_header }
|
147
|
+
it { is_expected.to eq(true) }
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#compression' do
|
151
|
+
subject { super().compression }
|
152
|
+
it { is_expected.to eq(false) }
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#experimental' do
|
156
|
+
subject { super().experimental }
|
157
|
+
it { is_expected.to eq(false) }
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#footer' do
|
161
|
+
subject { super().footer }
|
162
|
+
it { is_expected.to eq(false) }
|
163
|
+
end
|
68
164
|
end
|
69
165
|
|
70
166
|
describe "An ID3v2.3 header with the experimental header flag set:" do
|
71
167
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x20\x00\x00\x00\x00")) }
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
168
|
+
|
169
|
+
describe '#version' do
|
170
|
+
subject { super().version }
|
171
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_3_0) }
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#unsynchronized' do
|
175
|
+
subject { super().unsynchronized }
|
176
|
+
it { is_expected.to eq(false) }
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#extended_header' do
|
180
|
+
subject { super().extended_header }
|
181
|
+
it { is_expected.to eq(false) }
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#compression' do
|
185
|
+
subject { super().compression }
|
186
|
+
it { is_expected.to eq(false) }
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#experimental' do
|
190
|
+
subject { super().experimental }
|
191
|
+
it { is_expected.to eq(true) }
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#footer' do
|
195
|
+
subject { super().footer }
|
196
|
+
it { is_expected.to eq(false) }
|
197
|
+
end
|
78
198
|
end
|
79
199
|
|
80
200
|
describe "An ID3v2.3 header with the experimental header flag set:" do
|
81
201
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x20\x00\x00\x00\x00")) }
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
202
|
+
|
203
|
+
describe '#version' do
|
204
|
+
subject { super().version }
|
205
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_3_0) }
|
206
|
+
end
|
207
|
+
|
208
|
+
describe '#unsynchronized' do
|
209
|
+
subject { super().unsynchronized }
|
210
|
+
it { is_expected.to eq(false) }
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#extended_header' do
|
214
|
+
subject { super().extended_header }
|
215
|
+
it { is_expected.to eq(false) }
|
216
|
+
end
|
217
|
+
|
218
|
+
describe '#compression' do
|
219
|
+
subject { super().compression }
|
220
|
+
it { is_expected.to eq(false) }
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '#experimental' do
|
224
|
+
subject { super().experimental }
|
225
|
+
it { is_expected.to eq(true) }
|
226
|
+
end
|
227
|
+
|
228
|
+
describe '#footer' do
|
229
|
+
subject { super().footer }
|
230
|
+
it { is_expected.to eq(false) }
|
231
|
+
end
|
88
232
|
end
|
89
233
|
|
90
234
|
describe "An ID3v2.3 header with an invalid flag set" do
|
91
235
|
it "raises an error" do
|
92
|
-
|
93
|
-
|
236
|
+
expect { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x10\x00\x00\x00\x00")) }.
|
237
|
+
to(raise_error(Mp3file::ID3v2::InvalidID3v2TagError))
|
94
238
|
end
|
95
239
|
end
|
96
240
|
|
97
241
|
describe "An ID3v2.4 header with the footer header flag set:" do
|
98
242
|
subject { Mp3file::ID3v2::Header.new(StringIO.new("ID3\x04\x00\x10\x00\x00\x00\x00")) }
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
243
|
+
|
244
|
+
describe '#version' do
|
245
|
+
subject { super().version }
|
246
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_4_0) }
|
247
|
+
end
|
248
|
+
|
249
|
+
describe '#unsynchronized' do
|
250
|
+
subject { super().unsynchronized }
|
251
|
+
it { is_expected.to eq(false) }
|
252
|
+
end
|
253
|
+
|
254
|
+
describe '#extended_header' do
|
255
|
+
subject { super().extended_header }
|
256
|
+
it { is_expected.to eq(false) }
|
257
|
+
end
|
258
|
+
|
259
|
+
describe '#compression' do
|
260
|
+
subject { super().compression }
|
261
|
+
it { is_expected.to eq(false) }
|
262
|
+
end
|
263
|
+
|
264
|
+
describe '#experimental' do
|
265
|
+
subject { super().experimental }
|
266
|
+
it { is_expected.to eq(false) }
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#footer' do
|
270
|
+
subject { super().footer }
|
271
|
+
it { is_expected.to eq(true) }
|
272
|
+
end
|
105
273
|
end
|
106
274
|
end
|
107
275
|
|
108
276
|
describe "#version" do
|
109
277
|
it "detects ID3v2.2.0" do
|
110
278
|
t = Mp3file::ID3v2::Header.new(StringIO.new("ID3\x02\x00\x00\x00\x00\x00\x00"))
|
111
|
-
t.version.
|
279
|
+
expect(t.version).to eq(Mp3file::ID3v2::ID3V2_2_0)
|
112
280
|
end
|
113
281
|
|
114
282
|
it "detects ID3v2.3.0" do
|
115
283
|
t = Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x00\x00\x00\x00\x00"))
|
116
|
-
t.version.
|
284
|
+
expect(t.version).to eq(Mp3file::ID3v2::ID3V2_3_0)
|
117
285
|
end
|
118
286
|
|
119
287
|
it "detects ID3v2.4.0" do
|
120
288
|
t = Mp3file::ID3v2::Header.new(StringIO.new("ID3\x04\x00\x00\x00\x00\x00\x00"))
|
121
|
-
t.version.
|
289
|
+
expect(t.version).to eq(Mp3file::ID3v2::ID3V2_4_0)
|
122
290
|
end
|
123
291
|
end
|
124
292
|
|
125
293
|
describe "#size" do
|
126
294
|
it "properly reads the size of an ID3v2 tag" do
|
127
295
|
t = Mp3file::ID3v2::Header.new(StringIO.new("ID3\x03\x00\x00\x00\x06\x49\x37"))
|
128
|
-
t.tag_size.
|
296
|
+
expect(t.tag_size).to eq(107703)
|
129
297
|
end
|
130
298
|
end
|
131
299
|
|
@@ -6,13 +6,45 @@ include CommonHelpers
|
|
6
6
|
describe Mp3file::ID3v2::Tag do
|
7
7
|
describe "An empty tag" do
|
8
8
|
subject { Mp3file::ID3v2::Tag.new(StringIO.new("ID3\x03\x00\x00\x00\x00\x00\x00")) }
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
|
10
|
+
describe '#version' do
|
11
|
+
subject { super().version }
|
12
|
+
it { is_expected.to eq(Mp3file::ID3v2::ID3V2_3_0) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#unsynchronized' do
|
16
|
+
subject { super().unsynchronized }
|
17
|
+
it { is_expected.to eq(false) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#extended_header' do
|
21
|
+
subject { super().extended_header }
|
22
|
+
it { is_expected.to eq(false) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#compression' do
|
26
|
+
subject { super().compression }
|
27
|
+
it { is_expected.to eq(false) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#experimental' do
|
31
|
+
subject { super().experimental }
|
32
|
+
it { is_expected.to eq(false) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#footer' do
|
36
|
+
subject { super().footer }
|
37
|
+
it { is_expected.to eq(false) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#size' do
|
41
|
+
subject { super().size }
|
42
|
+
it { is_expected.to eq(10) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#frames' do
|
46
|
+
subject { super().frames }
|
47
|
+
it { is_expected.to eq([]) }
|
48
|
+
end
|
17
49
|
end
|
18
50
|
end
|
@@ -6,51 +6,131 @@ include CommonHelpers
|
|
6
6
|
describe Mp3file::ID3v2::Version do
|
7
7
|
describe Mp3file::ID3v2::ID3V2_2_0 do
|
8
8
|
subject { Mp3file::ID3v2::ID3V2_2_0 }
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
|
10
|
+
describe '#vbig' do
|
11
|
+
subject { super().vbig }
|
12
|
+
it { is_expected.to eq(2) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#vmaj' do
|
16
|
+
subject { super().vmaj }
|
17
|
+
it { is_expected.to eq(2) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#vmin' do
|
21
|
+
subject { super().vmin }
|
22
|
+
it { is_expected.to eq(0) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#to_s' do
|
26
|
+
subject { super().to_s }
|
27
|
+
it { is_expected.to eq('ID3v2.2.0') }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#to_byte_string' do
|
31
|
+
subject { super().to_byte_string }
|
32
|
+
it { is_expected.to eq("\x02\x00") }
|
33
|
+
end
|
14
34
|
end
|
15
35
|
|
16
36
|
describe Mp3file::ID3v2::ID3V2_3_0 do
|
17
37
|
subject { Mp3file::ID3v2::ID3V2_3_0 }
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
38
|
+
|
39
|
+
describe '#vbig' do
|
40
|
+
subject { super().vbig }
|
41
|
+
it { is_expected.to eq(2) }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#vmaj' do
|
45
|
+
subject { super().vmaj }
|
46
|
+
it { is_expected.to eq(3) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#vmin' do
|
50
|
+
subject { super().vmin }
|
51
|
+
it { is_expected.to eq(0) }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#to_s' do
|
55
|
+
subject { super().to_s }
|
56
|
+
it { is_expected.to eq('ID3v2.3.0') }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#to_byte_string' do
|
60
|
+
subject { super().to_byte_string }
|
61
|
+
it { is_expected.to eq("\x03\x00") }
|
62
|
+
end
|
23
63
|
end
|
24
64
|
|
25
65
|
describe Mp3file::ID3v2::ID3V2_4_0 do
|
26
66
|
subject { Mp3file::ID3v2::ID3V2_4_0 }
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
67
|
+
|
68
|
+
describe '#vbig' do
|
69
|
+
subject { super().vbig }
|
70
|
+
it { is_expected.to eq(2) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#vmaj' do
|
74
|
+
subject { super().vmaj }
|
75
|
+
it { is_expected.to eq(4) }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#vmin' do
|
79
|
+
subject { super().vmin }
|
80
|
+
it { is_expected.to eq(0) }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#to_s' do
|
84
|
+
subject { super().to_s }
|
85
|
+
it { is_expected.to eq('ID3v2.4.0') }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#to_byte_string' do
|
89
|
+
subject { super().to_byte_string }
|
90
|
+
it { is_expected.to eq("\x04\x00") }
|
91
|
+
end
|
32
92
|
end
|
33
93
|
|
34
94
|
describe "#<=>" do
|
35
95
|
it("should recognize that ID3v2.2 < ID3v2.3") do
|
36
|
-
(Mp3file::ID3v2::ID3V2_2_0 <=> Mp3file::ID3v2::ID3V2_3_0).
|
96
|
+
expect(Mp3file::ID3v2::ID3V2_2_0 <=> Mp3file::ID3v2::ID3V2_3_0).to eq(-1)
|
37
97
|
end
|
38
98
|
|
39
99
|
it("should recognize that ID3v2.4 > ID3v2.2") do
|
40
|
-
(Mp3file::ID3v2::ID3V2_4_0 <=> Mp3file::ID3v2::ID3V2_2_0).
|
100
|
+
expect(Mp3file::ID3v2::ID3V2_4_0 <=> Mp3file::ID3v2::ID3V2_2_0).to eq(1)
|
41
101
|
end
|
42
102
|
|
43
103
|
it("should recognize that ID3v2.3 == ID3v2.3") do
|
44
|
-
(Mp3file::ID3v2::ID3V2_3_0 <=> Mp3file::ID3v2::ID3V2_3_0).
|
104
|
+
expect(Mp3file::ID3v2::ID3V2_3_0 <=> Mp3file::ID3v2::ID3V2_3_0).to eq(0)
|
45
105
|
end
|
46
106
|
end
|
47
107
|
|
48
108
|
describe "#new" do
|
49
109
|
subject { Mp3file::ID3v2::Version.new(3, 1) }
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
110
|
+
|
111
|
+
describe '#vbig' do
|
112
|
+
subject { super().vbig }
|
113
|
+
it { is_expected.to eq(2) }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#vmaj' do
|
117
|
+
subject { super().vmaj }
|
118
|
+
it { is_expected.to eq(3) }
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#vmin' do
|
122
|
+
subject { super().vmin }
|
123
|
+
it { is_expected.to eq(1) }
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#to_s' do
|
127
|
+
subject { super().to_s }
|
128
|
+
it { is_expected.to eq('ID3v2.3.1') }
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#to_byte_string' do
|
132
|
+
subject { super().to_byte_string }
|
133
|
+
it { is_expected.to eq("\x03\x01") }
|
134
|
+
end
|
55
135
|
end
|
56
136
|
end
|