Hi all,
Sorry for the double-post - gmail has decided to send the mail before I was done :-(
I want to tag existing, untagged mp3 files. Using the code below, I can save v1.1 id3 tags in the file, but I'm struggling to get v2.3.0 tags to be saved as well (I want both v1.1 and v2.3.0 in the same file). The code below will just save properly the first tag (ID3_FRAME_COMMENT), the second one seems to be ignored.
Any help or code snippet would be welcome!
Thank's,
Pog
--- Code snippet below:
{ struct id3_file *id3 = id3_file_open("/home/myself/foo.mp3", ID3_FILE_MODE_READWRITE);
struct id3_tag *tag = id3_file_tag(id3);
if (tag != NULL) {
id3_tag_options(tag, ID3_TAG_OPTION_ID3V1, ~0); id3_tag_options(tag, ID3_TAG_OPTION_COMPRESSION, 0);//for ipod/itunes compatibility id3_tag_options(tag, ID3_TAG_OPTION_CRC, 0);
id3_set_string(tag, ID3_FRAME_TITLE, "azertyuiopqdsfhjkklwxcéèàç@êôî", ID3_FIELD_TEXTENCODING_UTF_16); id3_set_string(tag, "TOWN", "SimplePod", ID3_FIELD_TEXTENCODING_UTF_16);
} // update id3_file_update(id3); id3_file_close(id3); }
// taken from the gtkpod code base void id3_set_string(struct id3_tag *tag, const char *frame_name, const char *data, enum id3_field_textencoding encoding) { int res;
struct id3_frame *frame;
union id3_field *field;
id3_ucs4_t *ucs4;
/* clear the frame, because of bug in libid3tag see http://www.mars.org/mailman/public/mad-dev/2004-October/001113.html */ while ((frame = id3_tag_findframe(tag, frame_name, 0))) { id3_tag_detachframe(tag, frame); id3_frame_delete(frame); }
if ((data == NULL) || (strlen(data) == 0)) return;
frame = id3_frame_new(frame_name); id3_tag_attachframe(tag, frame);
/* Use the specified text encoding */ field = id3_frame_field(frame, 0); id3_field_settextencoding(field, encoding);
if ((strcmp(frame_name, ID3_FRAME_COMMENT) == 0) || (strcmp(frame_name, "USLT") == 0)) { field = id3_frame_field(frame, 3); field->type = ID3_FIELD_TYPE_STRINGFULL; } else { field = id3_frame_field(frame, 1); field->type = ID3_FIELD_TYPE_STRINGLIST; }
if (encoding == ID3_FIELD_TEXTENCODING_ISO_8859_1) { /* we read 'ISO_8859_1' to stand for 'any locale charset' -- most programs seem to work that way */
//always use utf-8, local encoding FIXME //id3_latin1_t *raw = charset_from_utf8(data);
ucs4 = id3_latin1_ucs4duplicate(data); //g_free(raw); } else { /* Yeah! We use unicode encoding and won't have to worry about charsets */ ucs4 = id3_utf8_ucs4duplicate((id3_utf8_t *) data); }
if ((strcmp(frame_name, ID3_FRAME_COMMENT) == 0) || (strcmp(frame_name, "USLT") == 0)) res = id3_field_setfullstring(field, ucs4); else res = id3_field_setstrings(field, 1, &ucs4);
g_free(ucs4);
if (res != 0) g_print(_("Error setting ID3 field: %s\n"), frame_name); }