larsbs / id3v2lib

id3v2lib is a library written in C to read and edit id3 tags from mp3 files.
BSD 2-Clause "Simplified" License
128 stars 44 forks source link

tag_set_comment always sets the comment to "eng" #20

Closed ooola closed 1 year ago

ooola commented 7 years ago

For some reason whenever the comment tag is set it is set to "eng".

The following demonstrates the issue. I've tested several different mp3 files.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>

#include "id3v2lib.h"

void print_all_tags(const char *file)
{
    ID3v2_tag* tag = load_tag(file); // Load the full tag from the file
    if (tag == NULL) {
        printf("%s: no tag found\n", file);
    }
    else {
        ID3v2_frame* f = tag_get_title(tag);
        ID3v2_frame_text_content* tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("TITLE: %s\n", tc->data);
        } else {
            printf("failed to parse TITLE\n");
        }

        f = tag_get_artist(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("ARTIST: %s\n", tc->data);
        } else {
            printf("failed to parse ARTIST\n");
        }

        f = tag_get_album(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("ALBUM: %s\n", tc->data);
        } else {
            printf("failed to parse ALBUM\n");
        }

        f = tag_get_album_artist(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("ALBUM ARTIST: %s\n", tc->data);
        } else {
            printf("failed to parse ALBUM ARTIST\n");
        }

        f = tag_get_genre(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("GENRE: %s\n", tc->data);
        } else {
            printf("failed to parse GENRE\n");
        }

        f = tag_get_track(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("TRACK: %s\n", tc->data);
        } else {
            printf("failed to parse TRACK\n");
        }

        f = tag_get_year(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("YEAR: %s\n", tc->data);
        } else {
            printf("failed to parse YEAR\n");
        }

        f = tag_get_comment(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("COMMENT: %s\n", tc->data);
        } else {
            printf("failed to parse COMMENT\n");
        }

        f = tag_get_disc_number(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("DISC NUMBER: %s\n", tc->data);
        } else {
            printf("failed to parse DISC NUMBER\n");
        }

        f = tag_get_composer(tag);
        tc = parse_text_frame_content(f);
        if (tc != NULL) {
            printf("COMPOSER: %s\n", tc->data);
        } else {
            printf("failed to parse COMPOSER\n");
        }
    }
}

int main(int argc, char *argv[])
{
    char *file = argv[1];

    // print initial state
    print_all_tags(file);

    ID3v2_tag* tag = load_tag(file);
    if(tag == NULL)
    {
        tag = new_tag();
    }
    tag_set_title("Some great song", 0, tag);
    set_tag(file, tag);

    // print all tags after setting title
    print_all_tags(file);

    tag = load_tag(file);
    if(tag == NULL)
    {
        tag = new_tag();
    }
    tag_set_comment("comment 123", 0, tag);
    set_tag(file, tag);

    // print all tags after setting comment
    print_all_tags(file);

    return EXIT_SUCCESS;
}

It prints the following

$ ./tagmp3 tiny.mp3 
tiny.mp3: no tag found
TITLE: Some great song
failed to parse ARTIST
failed to parse ALBUM
failed to parse ALBUM ARTIST
failed to parse GENRE
failed to parse TRACK
failed to parse YEAR
failed to parse COMMENT
failed to parse DISC NUMBER
failed to parse COMPOSER
TITLE: Some great song
failed to parse ARTIST
failed to parse ALBUM
failed to parse ALBUM ARTIST
failed to parse GENRE
failed to parse TRACK
failed to parse YEAR
COMMENT: eng
failed to parse DISC NUMBER
failed to parse COMPOSER

Why is comment set to "eng" ?