ruby-mp3info 0.8.8 → 0.8.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2623bb3c42570ac26f433976d36d71e1ed64faf0
4
- data.tar.gz: be52e6fb3afb871e59f8a24b9e18dda682f91e70
3
+ metadata.gz: ce54c521b67a367467f344b231debdbb1e36b543
4
+ data.tar.gz: 160261476cab97ea32fddd4870ff67a92ffd6ac5
5
5
  SHA512:
6
- metadata.gz: 885f991c667e898af9decb33a2a63515c705f7eaf69f17f682410f117583edbf67febaf0dba7d218fcd9a1fd826a34c26be7abfcfb1cc1ecb4942c73cd2c702c
7
- data.tar.gz: a7658745342508647a955ae12c9cdb0b74041e780fb15ac249414bb8aec254e553a51f492384ce27aa834c85f3704ae98dc6f4ffe2f9db2a1840ec37e8947e45
6
+ metadata.gz: 0609877cdd0fba3d09a74bc613338da699eb67dfe7bedf80f872ff09bdc23689bcb3e86c97632133f4c60bbad1c4ba8ac6e188799670e73772f818803627c9a4
7
+ data.tar.gz: 08999c5701caab8ba9a2a6e0d0ac0961e076d1acea747114878f1d84e2238631cf36cf472f5b2a4ad3bc880c6efa0eef2f0b558d544afb20bdfaf8c94c7e6076
@@ -1,3 +1,7 @@
1
+ === 0.8.9 / 2016-02-03
2
+
3
+ * bugfix on JPEG picture parsing + testsuite
4
+
1
5
  === 0.8.8 / 2016-01-26
2
6
 
3
7
  * fix on picture parsing when mime type is wrong
@@ -132,9 +136,9 @@
132
136
 
133
137
  === 0.6.2 / 2008-03-02
134
138
 
135
- * better handling of frames:
139
+ * better handling of frames:
136
140
  decode and encode as raw string by default,
137
- or handle charset decoding/encoding for /^T/ and
141
+ or handle charset decoding/encoding for /^T/ and
138
142
  COMM frames
139
143
 
140
144
  === 0.6.1 / 2008-02-28
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'hoe'
5
5
  Hoe.plugin :yard
6
6
  Hoe.plugin :gemspec
7
7
 
8
- Hoe.spec('ruby-mp3info') do
8
+ Hoe.spec('ruby-mp3info') do
9
9
  developer "Guillaume Pierronnet", "guillaume.pierronnet@gmail.com"
10
10
  end
11
11
 
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  class Mp3Info
20
20
 
21
- VERSION = "0.8.8"
21
+ VERSION = "0.8.9"
22
22
 
23
23
  LAYER = [ nil, 3, 2, 1]
24
24
  BITRATE = {
@@ -515,11 +515,11 @@ private
515
515
  bitrate = BITRATE[mpeg_version][layer-1][bits(head, 15,12)-1]
516
516
  samplerate = SAMPLERATE[mpeg_version][bits(head, 11,10)]
517
517
  padding = (head[9] == 1)
518
-
518
+
519
519
  frame_slot_count = (( ((SAMPLES_PER_FRAME[layer][mpeg_version] / 8) * (bitrate*1000.0)) / samplerate ) + (padding ? 1 : 0)).to_i
520
520
  bytes_per_slot = ((layer == 1) ? 4 : 1)
521
521
  size = frame_slot_count * bytes_per_slot
522
-
522
+
523
523
  channel_num = Mp3Info.bits(head, 7, 6)
524
524
  { :layer => layer,
525
525
  :bitrate => bitrate,
@@ -284,32 +284,26 @@ class ID3v2 < DelegateClass(Hash)
284
284
  next if !pic.is_a?(String) or pic == ""
285
285
  pic.force_encoding 'BINARY'
286
286
  picture = []
287
- jpg = Regexp.new("jpg|JPG|jpeg|JPEG".force_encoding("BINARY"),
287
+ jpg_regexp = Regexp.new("jpg|JPG|jpeg|JPEG".force_encoding("BINARY"),
288
288
  Regexp::FIXEDENCODING )
289
- png = Regexp.new("png|PNG".force_encoding("BINARY"),
289
+ png_regexp = Regexp.new("png|PNG".force_encoding("BINARY"),
290
290
  Regexp::FIXEDENCODING )
291
291
  header = pic.unpack('a120').first.force_encoding "BINARY"
292
292
  mime_pos = 0
293
293
 
294
294
  # safest way to correctly extract jpg and png is finding mime
295
- if header.match jpg and not header.match png
295
+ if header.match jpg_regexp and not header.match png_regexp
296
296
  mime = "jpg"
297
- mime_pos = header =~ jpg
297
+ mime_pos = header =~ jpg_regexp
298
298
  start = Regexp.new("\xFF\xD8".force_encoding("BINARY"),
299
299
  Regexp::FIXEDENCODING )
300
300
  start_with_anchor = Regexp.new("^\xFF\xD8".force_encoding("BINARY"),
301
301
  Regexp::FIXEDENCODING )
302
- # inspect jpg image header (first 10 chars) for "\xFF\x00" (expect "\xFF")
303
- trailing_null_byte = Regexp.new("(\377)(\000)".force_encoding('BINARY'),
304
- Regexp::FIXEDENCODING)
305
- if (data =~ trailing_null_byte) < 10
306
- data.gsub!(trailing_null_byte, "\xff".force_encoding('BINARY'))
307
- end
308
302
  end
309
303
 
310
- if header.match png and not header.match jpg
304
+ if header.match png_regexp and not header.match jpg_regexp
311
305
  mime = "png"
312
- mime_pos = header =~ png
306
+ mime_pos = header =~ png_regexp
313
307
  start = Regexp.new("\x89PNG".force_encoding("BINARY"),
314
308
  Regexp::FIXEDENCODING )
315
309
  start_with_anchor = Regexp.new("^\x89PNG".force_encoding("BINARY"),
@@ -319,12 +313,22 @@ class ID3v2 < DelegateClass(Hash)
319
313
  puts "analysing image: #{header.inspect}..." if $DEBUG
320
314
  _, _, desc, data = pic[mime_pos, pic.length].unpack('Z*hZ*a*')
321
315
 
322
- if mime and (!data.match(start_with_anchor) or data.nil?)
323
- real_start = pic =~ start
324
- data = pic[real_start, pic.length]
325
- end
326
-
327
- unless mime
316
+ if mime
317
+ if !data.match(start_with_anchor) or data.nil?
318
+ real_start = pic =~ start
319
+ data = pic[real_start, pic.length]
320
+ end
321
+
322
+ if mime == "jpg"
323
+ # inspect jpg image header (first 10 chars) for "\xFF\x00" (expect "\xFF")
324
+ trailing_null_byte = Regexp.new("(\377)(\000)".force_encoding('BINARY'),
325
+ Regexp::FIXEDENCODING)
326
+ md = data =~ trailing_null_byte
327
+ if !md.nil? and md < 10
328
+ data.gsub!(trailing_null_byte, "\xff".force_encoding('BINARY'))
329
+ end
330
+ end
331
+ else
328
332
  mime = "dat"
329
333
  # if no jpg or png, extract data anyway e.g. gif
330
334
  mime, desc, data = pic.unpack('h Z* h Z* a*').values_at(1,3,4)
@@ -207,7 +207,7 @@ class Mp3InfoTest < TestCase
207
207
  end
208
208
  end
209
209
 
210
- def test_id3v2_get_pictures
210
+ def test_id3v2_get_pictures_png
211
211
  img = "\x89PNG".force_encoding('BINARY') +
212
212
  random_string(120).force_encoding('BINARY')
213
213
  Mp3Info.open(TEMP_FILE) do |mp3|
@@ -218,19 +218,45 @@ class Mp3InfoTest < TestCase
218
218
  end
219
219
  end
220
220
 
221
- def test_id3v2_get_pictures
221
+ def test_id3v2_get_pictures_png_bad_mime
222
222
  img = "\x89PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0001\b\u0002\u0000\u0000\u0000\x90wS\xDE\u0000\u0000\u0000\fIDAT\b\xD7c\xF8\xFF\xFF?\u0000\u0005\xFE\u0002\xFE\xDC\xCCY\xE7\u0000\u0000\u0000\u0000IEND\xAEB`\x82".force_encoding('BINARY')
223
223
  Mp3Info.open(TEMP_FILE) do |mp3|
224
224
  mp3.tag2.add_picture(img, :description => 'example image.png', :mime => 'jpg')
225
225
  end
226
-
226
+
227
227
  Mp3Info.open(TEMP_FILE) do |mp3|
228
228
  assert_equal(["01_example image.png", img], mp3.tag2.pictures[0])
229
229
  end
230
230
  end
231
-
231
+
232
+ def test_id3v2_get_pictures_jpg
233
+ img = "\xFF\xD8".force_encoding('BINARY') +
234
+ random_string(120).force_encoding('BINARY')
235
+
236
+ Mp3Info.open(TEMP_FILE) do |mp3|
237
+ mp3.tag2.add_picture(img, :description => 'example image.jpg')
238
+ end
239
+
240
+ Mp3Info.open(TEMP_FILE) do |mp3|
241
+ assert_equal(["01_example image.jpg", img], mp3.tag2.pictures[0])
242
+ end
243
+ end
244
+
245
+ def test_id3v2_get_pictures_jpg_bad_mime
246
+ img = "\xFF\xD8".force_encoding('BINARY') +
247
+ random_string(120).force_encoding('BINARY')
248
+
249
+ Mp3Info.open(TEMP_FILE) do |mp3|
250
+ mp3.tag2.add_picture(img, :description => 'example image.jpg', :mime => 'png')
251
+ end
252
+
253
+ Mp3Info.open(TEMP_FILE) do |mp3|
254
+ assert_equal(["01_example image.jpg", img], mp3.tag2.pictures[0])
255
+ end
256
+ end
257
+
232
258
  def test_id3v2_remove_pictures
233
- jpg_data = "\xFF".force_encoding('BINARY') +
259
+ jpg_data = "\xFF\xD8".force_encoding('BINARY') +
234
260
  random_string(123).force_encoding('BINARY')
235
261
  Mp3Info.open(TEMP_FILE) do |mp|
236
262
  mp.tag2.add_picture(jpg_data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mp3info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Pierronnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc