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

Question - Setting the text information frames in a id3v2TextInformationFrame #77

Closed stuartambient closed 1 year ago

stuartambient commented 1 year ago

First, I want my tag to be id3v2.3 not v.2.4 so hopefully I am trying to use the correct classes. Anyway, in this particular I have a sandwich tag with the start tags being a id3v2.3 and an end tag being id3v1.

I get the v2.3 tag like this: const id3v2Tag = myFile.getTag(TagTypes.Id3v2, true);

and then set up the new frame:

const id = new Id3v2FrameIdentifier("v3");
const header = new Id3v2FrameHeader(id);
const frame = new Id3v2TextInformationFrame(header);
id3v2Tag.addFrame(frame);

but how / where to add in the (example) ('TIT2', 'mytitle') ?

benrr101 commented 1 year ago

Hi, let me do my best to help on this one. Sorry the advanced tagging docs on the wiki aren't done yet. I started working on them a while ago and keep getting sidetracked by other things.

If you want to use the myFile.getTag() method to create new tags, you'll want to look at the settings in Id3v2Settings Use Id3v2Settings.defaultVersion = 4 to make new ID3v2 tags v2.4. However, this won't affect existing tags. There's a couple ways to change version of existing tags (this is subject to change as per #47) but the most obvious is to update the version of the existing tag by setting id3v2Tag.version = 4.

As for creating the frame, see my notes on your other question about creating a frame identifier (ie, don't create a new one, use the existing ones). Ideally, if you're creating a text information frame, you can just use TextInformationFrame.FromIdentifier.

Putting it all together, here's an example for how you would add the title to your file:

const id3v2Tag = myFile.getTag(TagTypes.Id3v2, true);
id3v2Tag.version = 4;

const newFrame = Id3v2TextInformationFrame.fromIdentifier(Id3v2FrameIdentifiers.TIT2);
newFrame.text = ['mytitle'];

id3v2Tag.addFrame(newFrame);

I'm kinda winging it with the example since it's been a while since I've touched the ID3v2 code. Let me know if you run into any issues.

stuartambient commented 1 year ago

Your example worked for me. Appreciate the answer !