static int translate_TCON(struct id3_frame *frame, char const *oldid, id3_byte_t const *data, id3_length_t length) { id3_byte_t const *end; enum id3_field_textencoding encoding; id3_ucs4_t *string = 0, *ptr, *endptr; int result = 0; (void)oldid; /* translate old TCON syntax into multiple strings */ assert(frame->nfields == 2); encoding = ID3_FIELD_TEXTENCODING_ISO_8859_1; end = data + length; if(id3_field_parse(&frame->fields[0], &data, end - data, &encoding) == -1) goto fail; string = id3_parse_string(&data, end - data, encoding, 0); if(string == 0) goto fail; ptr = string; while(*ptr == '(') { if(*++ptr == '(') break; endptr = ptr; while(*endptr && *endptr != ')') ++endptr; if(*endptr) *endptr++ = 0; if(id3_field_addstring(&frame->fields[1], ptr) == -1) goto fail; ptr = endptr; } if(*ptr && id3_field_addstring(&frame->fields[1], ptr) == -1) goto fail; if(0) { fail: result = -1; } if(string) free(string); return result; }
int BarFlyID3AddFrame(struct id3_tag* tag, char const* type, char const* value, BarSettings_t const* settings) { int exit_status = 0; int status; struct id3_frame* frame = NULL; union id3_field* field; id3_ucs4_t* ucs4 = NULL; int index; assert(tag != NULL); assert(type != NULL); assert(value != NULL); assert(settings != NULL); /* * Create the frame. */ frame = id3_frame_new(type); if (frame == NULL) { BarUiMsg(settings, MSG_ERR, "Failed to create new frame (type = %s).\n", type); goto error; } frame->flags &= ~ID3_FRAME_FLAG_FORMATFLAGS; /* * Get the string list field of the frame. */ index = 0; do { field = id3_frame_field(frame, index); index++; } while (id3_field_type(field) != ID3_FIELD_TYPE_STRINGLIST); assert(id3_field_type(field) == ID3_FIELD_TYPE_STRINGLIST); /* * Add the value as a string to the field. */ ucs4 = id3_latin1_ucs4duplicate((id3_latin1_t*)value); if (ucs4 == NULL) { BarUiMsg(settings, MSG_ERR, "Could not allocate memory.\n"); goto error; } status = id3_field_addstring(field, ucs4); if (status != 0) { BarUiMsg(settings, MSG_ERR, "Failed to set field value (value = %s).\n", value); goto error; } /* * Attach the frame to the tag. */ status = id3_tag_attachframe(tag, frame); if (status != 0) { BarUiMsg(settings, MSG_ERR, "Failed to attach frame (type = %s).\n", type); goto error; } goto end; error: if (frame != NULL) { id3_frame_delete(frame); } exit_status = -1; end: if (ucs4 != NULL) { free(ucs4); } return exit_status; }