43081j / id3

A JavaScript ID3 tags parser for Node & browsers.
MIT License
335 stars 63 forks source link

image tag does not contain the image that other software uses to display album art #36

Closed ReinierRothuis closed 5 years ago

ReinierRothuis commented 6 years ago

Hi,

When I was trying to use this library I noticed that the image tag contains a different image than I expected to see. Correct me if I'm wrong, but what I think is happening is that each APIC or PIC record is getting read but only the last one is saved. I think this is because there is only one image property on the tags object.

// Code snippet from id3.js
} else if(header.id === 'APIC') {
  var encoding = dv.getUint8(10),
    image = {
      type: null,
      mime: null,
      description: null,
     data: null
    };
  var variableStart = 11, variableLength = 0;
  for(var i = variableStart;;i++) {
    if(dv.getUint8(i) === 0x00) {
      variableLength = i - variableStart;
      break;
    }
  }
  image.mime = dv.getString(variableLength, variableStart);
  image.type = ID3Frame.imageTypes[dv.getUint8(variableStart + variableLength + 1)] || 'other';
  variableStart += variableLength + 2;
  variableLength = 0;
  for(var i = variableStart;; i++) {
    if(dv.getUint8(i) === 0x00) {
      variableLength = i - variableStart;
      break;
    }
  }
  image.description = (variableLength === 0 ? null : dv.getString(variableLength, variableStart));
  image.data = buffer.slice(variableStart + 1);
  result.value = image;
}

Anyone have a workaround for this?