benrr101 / node-taglib-sharp

A node.js port of mono/taglib-sharp
GNU Lesser General Public License v2.1
42 stars 11 forks source link

Pictures cannot display in windows file browser. #83

Closed RogerChen2005 closed 1 year ago

RogerChen2005 commented 1 year ago

When attaching pictures to .mp3 files, the cover cannot display in windows file browser.

let cover = {
           data: taglib.ByteVector.fromByteArray(data),
           mimeType: 'image/jpeg',
           type: taglib.PictureType.FrontCover,
 }
let dest = taglib.File.createFromPath(save_path);
dest.tag.pictures = [cover];
dest.save();
dest.dispose();

The result I get: {7E01F5C4-7825-4e3a-BBAC-44DC493A78BE} However, Foobar2000 can read the picture: {49347EBB-C0A0-43ae-85B3-6D7940FF73D8}

benrr101 commented 1 year ago

Hmmm... I played around with it for a bit this evening and so far haven't been able to directly reproduce your issue. I do however notice neither windows nor Foobar2000 seem to recognize ID3v2 tags placed at the end of the file with node-taglib-sharp. It's worth noting as well that Foobar2000 seems to cache tags when a file is added to a playlist. I wasn't able to get the scenario you had where Windows doesn't show the picture but Foobar2000 does, but this might be because Foobar2000 needed to reload the tags.

node-taglib-sharp by default creates new ID3v2 tags at the beginning of the file, but if a file already has ID3v2 tag at the end of the file, it will write any changes (via dest.tag) to that tag. As a workaround, you could try removing and re-adding the tag so that it is added at the end of the file.

const file = taglib.File.createFromPath("pathtofile");
const cover = taglib.Picture.fromPath("pathtopicture");

const oldId3v2 = file.getTag(taglib.TagTypes.Id3v2, false);
file.removeTags(0xFFFFFFFF);

const newId3v2 = file.getTag(taglib.TagTypes.Id3v2, true);
oldId3v2.copyTo(newId3v2, true);

// make changes via file.tag

file.save();
file.dispose();

Inspecting the file I tested with, I see the image is being added to the tag and node-taglib-sharp can see it. However, the fact neither foobar2000, vlc, nor windows can see the tag means something is wrong.

RogerChen2005 commented 1 year ago

Thanks for your help, I accidentally got two samples today, one cover displays properly and the other doesn't. 2 Compared the content of two files, I notice that the tag type of two samples are different, and 'id3v2.3' can display properly,
1 Thus, I suppose that explorer.exe can't read newer tag type. Thanks again for your help, have a nice day.

RogerChen2005 commented 1 year ago
taglib.Id3v2Settings.forceDefaultVersion=true;
taglib.Id3v2Settings.defaultVersion=3;

After forcing the version of id3v2, The problem has been solved. {C12CC650-7036-4023-9A4F-25549B81B8AA}

benrr101 commented 1 year ago

Hi @RogerChen2005 yes, ID3v2.4 still isn't supported in nearly as many places as ID3v2.3 is. Glad you found a workaround. The investigation for your issue also uncovered a related issue with ID3v2 tags at the end of a file. I'll track that in a separate issue, but thanks for helping bring it to my attention.