Пример #1
0
/*
 * NAME:	ucs4->size()
 * DESCRIPTION:	return the encoding size of a ucs4 string
 */
id3_length_t id3_ucs4_size(id3_ucs4_t const *ucs4)
{
  return id3_ucs4_length(ucs4) + 1;
}
Пример #2
0
/*
 * NAME:    compat->fixup()
 * DESCRIPTION: finish compatibility translations
 */
int id3_compat_fixup(struct id3_tag *tag)
{
    struct id3_frame *frame;
    unsigned int index;
    id3_ucs4_t timestamp[17] = { 0 };
    int result = 0;

    /* create a TDRC frame from obsolete TYER/TDAT/TIME frames */

    /*
     * TYE/TYER: YYYY
     * TDA/TDAT: DDMM
     * TIM/TIME: HHMM
     *
     * TDRC: yyyy-MM-ddTHH:mm
     */

    index = 0;
    while((frame = id3_tag_findframe(tag, ID3_FRAME_OBSOLETE, index++)))
    {
        char const *id;
        id3_byte_t const *data, *end;
        id3_length_t length;
        enum id3_field_textencoding encoding;
        id3_ucs4_t *string;

        id = id3_field_getframeid(&frame->fields[0]);
        assert(id);

        if(strcmp(id, "TYER") != 0 && strcmp(id, "YTYE") != 0 &&
           strcmp(id, "TDAT") != 0 && strcmp(id, "YTDA") != 0 &&
           strcmp(id, "TIME") != 0 && strcmp(id, "YTIM") != 0)
            continue;

        data = id3_field_getbinarydata(&frame->fields[1], &length);
        assert(data);

        if(length < 1)
            continue;

        end = data + length;

        encoding = (enum id3_field_textencoding)id3_parse_uint(&data, 1);
        string   = id3_parse_string(&data, end - data, encoding, 0);

        if(id3_ucs4_length(string) < 4)
        {
            free(string);
            continue;
        }

        if(strcmp(id, "TYER") == 0 ||
           strcmp(id, "YTYE") == 0)
        {
            timestamp[0] = string[0];
            timestamp[1] = string[1];
            timestamp[2] = string[2];
            timestamp[3] = string[3];
        }
        else if(strcmp(id, "TDAT") == 0 ||
                strcmp(id, "YTDA") == 0)
        {
            timestamp[4] = '-';
            timestamp[5] = string[2];
            timestamp[6] = string[3];
            timestamp[7] = '-';
            timestamp[8] = string[0];
            timestamp[9] = string[1];
        }
        else    /* TIME or YTIM */
        {
            timestamp[10] = 'T';
            timestamp[11] = string[0];
            timestamp[12] = string[1];
            timestamp[13] = ':';
            timestamp[14] = string[2];
            timestamp[15] = string[3];
        }

        free(string);
    }

    if(timestamp[0])
    {
        id3_ucs4_t *strings;

        frame = id3_frame_new("TDRC");
        if(frame == 0)
            goto fail;

        strings = timestamp;

        if(id3_field_settextencoding(&frame->fields[0],
                                     ID3_FIELD_TEXTENCODING_ISO_8859_1) == -1 ||
           id3_field_setstrings(&frame->fields[1], 1, &strings) == -1 ||
           id3_tag_attachframe(tag, frame) == -1)
        {
            id3_frame_delete(frame);
            goto fail;
        }
    }

    if(0)
    {
fail:
        result = -1;
    }

    return result;
}