From: <ale...@us...> - 2023-12-14 09:12:23
|
Revision: 6527 http://sourceforge.net/p/lame/svn/6527 Author: aleidinger Date: 2023-12-14 09:12:21 +0000 (Thu, 14 Dec 2023) Log Message: ----------- Unbreak UTF8 genre tag, text-tags still broken (wrong encoding). Modified Paths: -------------- trunk/lame/include/lame.def trunk/lame/include/lame.h trunk/lame/libmp3lame/id3tag.c Modified: trunk/lame/include/lame.def =================================================================== --- trunk/lame/include/lame.def 2023-12-12 21:07:37 UTC (rev 6526) +++ trunk/lame/include/lame.def 2023-12-14 09:12:21 UTC (rev 6527) @@ -293,14 +293,15 @@ lame_get_id3v2_tag @2017 lame_set_write_id3tag_automatic @2018 lame_get_write_id3tag_automatic @2019 -id3tag_set_pad @2020 +id3tag_set_pad @2020 id3tag_set_comment_ucs2 @2021 -id3tag_set_textinfo_ucs2 @2022 +id3tag_set_textinfo_ucs2 @2022 id3tag_set_fieldvalue_ucs2 @2023 id3tag_set_comment_utf16 @2024 -id3tag_set_textinfo_utf16 @2025 +id3tag_set_textinfo_utf16 @2025 id3tag_set_fieldvalue_utf16 @2026 +id3tag_set_textinfo_utf8 @2027 ; two external functions for ID3v2.4 tag support -id3tag_add_v2_4_UTF8 @2027 -id3tag_v2_4_UTF8_only @2028 +id3tag_add_v2_4_UTF8 @2028 +id3tag_v2_4_UTF8_only @2029 Modified: trunk/lame/include/lame.h =================================================================== --- trunk/lame/include/lame.h 2023-12-12 21:07:37 UTC (rev 6526) +++ trunk/lame/include/lame.h 2023-12-14 09:12:21 UTC (rev 6527) @@ -1302,7 +1302,10 @@ /* experimental */ int CDECL id3tag_set_comment_utf16(lame_t gfp, char const *lang, unsigned short const *desc, unsigned short const *text); +/* experimental */ +int CDECL id3tag_set_textinfo_utf8(lame_t gfp, char const *id, unsigned short const *text); + /*********************************************************************** * * list of valid bitrates [kbps] & sample frequencies [Hz]. Modified: trunk/lame/libmp3lame/id3tag.c =================================================================== --- trunk/lame/libmp3lame/id3tag.c 2023-12-12 21:07:37 UTC (rev 6526) +++ trunk/lame/libmp3lame/id3tag.c 2023-12-14 09:12:21 UTC (rev 6527) @@ -640,6 +640,34 @@ static int +id3tag_set_genre_utf8(lame_t gfp, unsigned short const* text) +{ + lame_internal_flags* gfc = gfp->internal_flags; + int ret; + if (text == 0) { + return -3; + } + if (maybeLatin1(text)) { + char* latin1 = local_strdup_utf16_to_latin1(text); + int num = lookupGenre(latin1); + free(latin1); + if (num == -1) return -1; /* number out of range */ + if (num >= 0) { /* common genre found */ + gfc->tag_spec.flags |= CHANGED_FLAG; + gfc->tag_spec.genre_id3v1 = num; + copyV1ToV2(gfp, ID_GENRE, genre_names[num]); + return 0; + } + } + ret = id3v2_add_ucs2_lng(gfp, ID_GENRE, 0, text); + if (ret == 0) { + gfc->tag_spec.flags |= CHANGED_FLAG; + gfc->tag_spec.genre_id3v1 = GENRE_INDEX_OTHER; + } + return ret; +} + +static int id3tag_set_genre_utf16(lame_t gfp, unsigned short const* text) { lame_internal_flags* gfc = gfp->internal_flags; @@ -1075,6 +1103,46 @@ } int +id3tag_set_textinfo_utf8(lame_t gfp, char const *id, unsigned short const *text) +{ + uint32_t const frame_id = toID3v2TagId(id); + if (frame_id == 0) { + return -1; + } + if (is_lame_internal_flags_null(gfp)) { + return 0; + } + if (text == 0) { + return 0; + } + if (frame_id == ID_TXXX || frame_id == ID_WXXX || frame_id == ID_COMMENT) { + return id3tag_set_userinfo_ucs2(gfp, frame_id, text); + } + if (frame_id == ID_GENRE) { + return id3tag_set_genre_utf8(gfp, text); + } + if (frame_id == ID_PCST) { + return id3v2_add_ucs2_lng(gfp, frame_id, 0, text); + } + if (frame_id == ID_USER) { + return id3v2_add_ucs2_lng(gfp, frame_id, text, 0); + } + if (frame_id == ID_WFED) { + return id3v2_add_ucs2_lng(gfp, frame_id, text, 0); /* iTunes expects WFED to be a text frame */ + } + if (isFrameIdMatching(frame_id, FRAME_ID('T', 0, 0, 0)) + ||isFrameIdMatching(frame_id, FRAME_ID('W', 0, 0, 0))) { +#if 0 + if (isNumericString(frame_id)) { + return -2; /* must be Latin-1 encoded */ + } +#endif + return id3v2_add_ucs2_lng(gfp, frame_id, 0, text); + } + return -255; /* not supported by now */ +} + +int id3tag_set_textinfo_utf16(lame_t gfp, char const *id, unsigned short const *text) { uint32_t const frame_id = toID3v2TagId(id); |