ruby-mp3info 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dae26856d6a1cd3953b33d72433d5ec071c12d8
4
- data.tar.gz: d05a2acdadfa42efb5801cb2f8207acc0690f954
3
+ metadata.gz: 2623bb3c42570ac26f433976d36d71e1ed64faf0
4
+ data.tar.gz: be52e6fb3afb871e59f8a24b9e18dda682f91e70
5
5
  SHA512:
6
- metadata.gz: 56392604532e62fee6ab829f4a3d1d9d80672f1cde984540b0ff0b1b4eeee41ba96c9eba57b300214ab75954c533f0cdd7ea0d6d57458e358984c302ec681b1d
7
- data.tar.gz: 11a5c190a0837fcd840d2e0ce1932652ebf04f4f3017c38655502cc61affcf0edd7fd7990ee460336158ce5efaf10f29be74b97573a1890842e1537777770218
6
+ metadata.gz: 885f991c667e898af9decb33a2a63515c705f7eaf69f17f682410f117583edbf67febaf0dba7d218fcd9a1fd826a34c26be7abfcfb1cc1ecb4942c73cd2c702c
7
+ data.tar.gz: a7658745342508647a955ae12c9cdb0b74041e780fb15ac249414bb8aec254e553a51f492384ce27aa834c85f3704ae98dc6f4ffe2f9db2a1840ec37e8947e45
@@ -1,3 +1,7 @@
1
+ === 0.8.8 / 2016-01-26
2
+
3
+ * fix on picture parsing when mime type is wrong
4
+
1
5
  === 0.8.7 / 2015-07-13
2
6
 
3
7
  * Cope with malformed UTF16 string tags without BOM (thanks to mikecrowe)
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  class Mp3Info
20
20
 
21
- VERSION = "0.8.7"
21
+ VERSION = "0.8.8"
22
22
 
23
23
  LAYER = [ nil, 3, 2, 1]
24
24
  BITRATE = {
@@ -461,6 +461,7 @@ class Mp3Info
461
461
  FileUtils.rm tempfile_name
462
462
  end
463
463
  end
464
+ @io.close unless @io.closed?
464
465
  end
465
466
 
466
467
  # close and reopen the file, i.e. commit changes to disk and
@@ -292,50 +292,45 @@ class ID3v2 < DelegateClass(Hash)
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
295
+ if header.match jpg and not header.match png
296
296
  mime = "jpg"
297
297
  mime_pos = header =~ jpg
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
- Regexp::FIXEDENCODING )
302
- elsif header.match png
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
+ end
309
+
310
+ if header.match png and not header.match jpg
303
311
  mime = "png"
304
312
  mime_pos = header =~ png
305
313
  start = Regexp.new("\x89PNG".force_encoding("BINARY"),
306
314
  Regexp::FIXEDENCODING )
307
315
  start_with_anchor = Regexp.new("^\x89PNG".force_encoding("BINARY"),
308
316
  Regexp::FIXEDENCODING )
309
- else
310
- mime = "dat"
311
317
  end
312
-
318
+
313
319
  puts "analysing image: #{header.inspect}..." if $DEBUG
314
320
  _, _, desc, data = pic[mime_pos, pic.length].unpack('Z*hZ*a*')
315
321
 
316
- if mime != "dat" and (!data.match(start_with_anchor) or data.nil?)
322
+ if mime and (!data.match(start_with_anchor) or data.nil?)
317
323
  real_start = pic =~ start
318
324
  data = pic[real_start, pic.length]
319
325
  end
320
326
 
321
- if mime == "dat"
327
+ unless mime
328
+ mime = "dat"
322
329
  # if no jpg or png, extract data anyway e.g. gif
323
330
  mime, desc, data = pic.unpack('h Z* h Z* a*').values_at(1,3,4)
324
331
  end
325
332
 
326
- if mime == "jpg"
327
- # inspect jpg image header (first 10 chars) for "\xFF\x00" (expect "\xFF")
328
- trailing_null_byte = Regexp.new("(\377)(\000)".force_encoding('BINARY'),
329
- Regexp::FIXEDENCODING)
330
- if (data =~ trailing_null_byte) < 10
331
- data.gsub!(trailing_null_byte, "\xff".force_encoding('BINARY'))
332
- end
333
- end
334
-
335
- desc = "%02i_#{desc[0,25]}" % (index + 1)
336
-
337
- filename = desc.match("#{mime}$") ? desc : "#{desc}.#{mime}"
338
- filename.gsub!('/','')
333
+ filename = ("%02i_#{desc[0,25]}" % (index + 1)).gsub('/','')
339
334
 
340
335
  picture[0] = filename
341
336
  picture[1] = data
@@ -467,8 +462,8 @@ class ID3v2 < DelegateClass(Hash)
467
462
  p out
468
463
  =end
469
464
  comment = Mp3Info::EncodingHelper.decode_utf16(raw_tag)
470
- split_val = RUBY_1_8 ? "\x00\x00" : "\x00".encode(comment.encoding)
471
- out = comment.split(split_val).last rescue ""
465
+ split_val = RUBY_1_8 ? "\x00\x00" : "\x00".encode(comment.encoding).force_encoding('ASCII-8BIT')
466
+ out = raw_tag.split(split_val).last rescue ""
472
467
  else
473
468
  comment, out = raw_tag.split("\x00", 2)
474
469
  end
@@ -218,6 +218,17 @@ class Mp3InfoTest < TestCase
218
218
  end
219
219
  end
220
220
 
221
+ def test_id3v2_get_pictures
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
+ Mp3Info.open(TEMP_FILE) do |mp3|
224
+ mp3.tag2.add_picture(img, :description => 'example image.png', :mime => 'jpg')
225
+ end
226
+
227
+ Mp3Info.open(TEMP_FILE) do |mp3|
228
+ assert_equal(["01_example image.png", img], mp3.tag2.pictures[0])
229
+ end
230
+ end
231
+
221
232
  def test_id3v2_remove_pictures
222
233
  jpg_data = "\xFF".force_encoding('BINARY') +
223
234
  random_string(123).force_encoding('BINARY')
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.7
4
+ version: 0.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Pierronnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc