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