Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Year tag #634

Closed
RedHeadEmile opened this issue Feb 11, 2024 · 2 comments
Closed

[BUG] Year tag #634

RedHeadEmile opened this issue Feb 11, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@RedHeadEmile
Copy link

RedHeadEmile commented Feb 11, 2024

I try to use the "Year" tag but it seems saving the setter of the year tag struggle a bit.

Here is my code:

    const buffer = fs.readFileSync(file.absolutePath);
    const mp3tag = new MP3Tag(buffer);

    mp3tag.read({
      id3v1: false,
      id3v2: true
    });

    if (!!mp3tag.error)
      throw new Error(mp3tag.error);

    mp3tag.tags.title = tag.title ?? '';
    mp3tag.tags.artist = tag.artist ?? '';
    mp3tag.tags.album = tag.album ?? '';
    mp3tag.tags.year = tag.year ?? '';
    mp3tag.tags.track = tag.track ?? '';

    if (!tag.coverImageBase64)
      mp3tag.tags.v2!.APIC = undefined;
    else
      mp3tag.tags.v2!.APIC = [{
        data: this._base64ToArray(tag.coverImageBase64),
        format: tag.coverImageMimeType,
        type: 3,
        description: 'Cover'
      }] as any;

    const newBuffer = mp3tag.save({
      strict: true,
      id3v1: { include: false },
      id3v2: {
        include: true,
        unsynch: false,
        version: 4,
        padding: 4096
      }
    });
    if (!!mp3tag.error) {
      console.log(tag);
      throw new Error(mp3tag.error);
    }

    fs.writeFileSync(file.absolutePath, Buffer.from(newBuffer));

As you can see, I read the original file, I patch it with the data contained in my object tag then I save the patched file.

The problem is:
If I set id3v2 version to 3, I get TDRC is not supported in ID3v2.3.
And if I set id3v2 version to 4, I get TYER is not supported in ID3v2.4.

Note that to fill the tag object, I used the getter mp3tag.tags.year.

I think the problem is my original file as it already contains both TDRC and TYER tag and when mp3tag.js try to save it in strict mode, it messes up :(

I don't know what would be the better way to fix it, maybe having an option in the save function to delete the wrong frames ?

Thanks in advance :)

@eidoriantan
Copy link
Owner

I'm thinking the same thing. Adding a new option to delete unsupported frames instead of throwing errors is best for this kind of situations.

@eidoriantan eidoriantan added the enhancement New feature or request label Feb 11, 2024
@eidoriantan eidoriantan added this to To Do in Project API via automation Feb 11, 2024
@eidoriantan eidoriantan moved this from To Do to In Progress in Project API Feb 11, 2024
eidoriantan added a commit that referenced this issue Feb 11, 2024
@eidoriantan eidoriantan moved this from In Progress to Done in Project API Feb 11, 2024
@eidoriantan
Copy link
Owner

Added in v3.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Project API
  
Done
Development

No branches or pull requests

2 participants