ruby-mp3info 0.8.7 → 0.8.8
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 +4 -4
- data/History.txt +4 -0
- data/lib/mp3info.rb +2 -1
- data/lib/mp3info/id3v2.rb +18 -23
- data/test/test_ruby-mp3info.rb +11 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2623bb3c42570ac26f433976d36d71e1ed64faf0
         | 
| 4 | 
            +
              data.tar.gz: be52e6fb3afb871e59f8a24b9e18dda682f91e70
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 885f991c667e898af9decb33a2a63515c705f7eaf69f17f682410f117583edbf67febaf0dba7d218fcd9a1fd826a34c26be7abfcfb1cc1ecb4942c73cd2c702c
         | 
| 7 | 
            +
              data.tar.gz: a7658745342508647a955ae12c9cdb0b74041e780fb15ac249414bb8aec254e553a51f492384ce27aa834c85f3704ae98dc6f4ffe2f9db2a1840ec37e8947e45
         | 
    
        data/History.txt
    CHANGED
    
    
    
        data/lib/mp3info.rb
    CHANGED
    
    | @@ -18,7 +18,7 @@ end | |
| 18 18 |  | 
| 19 19 | 
             
            class Mp3Info
         | 
| 20 20 |  | 
| 21 | 
            -
              VERSION = "0.8. | 
| 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
         | 
    
        data/lib/mp3info/id3v2.rb
    CHANGED
    
    | @@ -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 | 
            -
             | 
| 302 | 
            -
             | 
| 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  | 
| 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 | 
            -
                   | 
| 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 | 
            -
                   | 
| 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 =  | 
| 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
         | 
    
        data/test/test_ruby-mp3info.rb
    CHANGED
    
    | @@ -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. | 
| 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:  | 
| 11 | 
            +
            date: 2016-01-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rdoc
         |