diff options
-rw-r--r-- | src/frametab.gperf | 7 | ||||
-rw-r--r-- | src/idest.h | 3 | ||||
-rw-r--r-- | src/idop.c | 59 |
3 files changed, 44 insertions, 25 deletions
diff --git a/src/frametab.gperf b/src/frametab.gperf index 7863d08..c02b771 100644 --- a/src/frametab.gperf +++ b/src/frametab.gperf @@ -44,3 +44,3 @@ decode_qv(struct ed_item *item, struct id3_frame const *frame, break; - item->qv[i] = field_to_string(field, 0); + item->qv[i] = field_to_string(field, frame); } @@ -348,3 +348,2 @@ text_decode(struct ed_item *item, struct id3_frame const *frame) { - int isgenre = strcmp(frame->id, ID3_FRAME_GENRE) == 0; union id3_field *field; @@ -352,3 +351,3 @@ text_decode(struct ed_item *item, struct id3_frame const *frame) int rc; - + field = id3_frame_field(frame, 1); @@ -356,3 +355,3 @@ text_decode(struct ed_item *item, struct id3_frame const *frame) return IDEST_ERR_NOFIELD; - str = field_to_string(field, isgenre); + str = field_to_string(field, frame); rc = utf8_convert(idest_conv_decode, str, &item->value); diff --git a/src/idest.h b/src/idest.h index 2c10077..787cdad 100644 --- a/src/idest.h +++ b/src/idest.h @@ -94,3 +94,2 @@ void set_tags(const char *name); void del_tags(const char *name); -char *idest_ucs4_cvt(id3_ucs4_t const *ucs4); void query_tags(const char *name); @@ -98,3 +97,3 @@ void info_id3(const char *name); -char *field_to_string(union id3_field *field, int isgenre); +char *field_to_string(union id3_field *field, struct id3_frame const *frame); int field_binary_from_string(union id3_field *field, const char *str); @@ -190,6 +190,27 @@ safe_id3_file_update_and_close(struct id3_file *file) +static int +frame_encoding_is_8bit(struct id3_frame const *frame) +{ + union id3_field const *field; + + if (!frame) + return 0; + field = id3_frame_field(frame, 0); + if (!field) + return 0; + return id3_field_gettextencoding(field) == ID3_FIELD_TEXTENCODING_ISO_8859_1; +} + +static int +frame_is_genre(struct id3_frame const *frame) +{ + if (!frame) + return 0; + return strcmp(frame->id, ID3_FRAME_GENRE) == 0; +} + char * -idest_ucs4_cvt(id3_ucs4_t const *ucs4) +idest_ucs4_cvt(id3_ucs4_t const *ucs4, struct id3_frame const *frame) { - if (broken_8bit_charset) { + if (broken_8bit_charset && frame_encoding_is_8bit(frame)) { char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); @@ -207,3 +228,4 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4) static void -add_stringlist(gl_list_t list, union id3_field *field, int isgenre, +add_stringlist(gl_list_t list, union id3_field *field, + struct id3_frame const *frame, size_t *psize) @@ -220,5 +242,5 @@ add_stringlist(gl_list_t list, union id3_field *field, int isgenre, continue; - if (isgenre) + if (frame_is_genre(frame)) ucs4 = id3_genre_name(ucs4); - str = idest_ucs4_cvt(ucs4); + str = idest_ucs4_cvt(ucs4, frame); size += strlen(str); @@ -286,3 +308,3 @@ field_binary_from_string(union id3_field *field, const char *str) char * -field_to_string(union id3_field *field, int isgenre) +field_to_string(union id3_field *field, struct id3_frame const *frame) { @@ -314,4 +336,4 @@ field_to_string(union id3_field *field, int isgenre) ucs4 = id3_field_getstring(field);; - if (ucs4) - ret = idest_ucs4_cvt(ucs4); + if (ucs4) + ret = idest_ucs4_cvt(ucs4, frame); break; @@ -320,3 +342,3 @@ field_to_string(union id3_field *field, int isgenre) ucs4 = id3_field_getfullstring(field); - ret = idest_ucs4_cvt(ucs4); + ret = idest_ucs4_cvt(ucs4, frame); break; @@ -330,3 +352,3 @@ field_to_string(union id3_field *field, int isgenre) list = new_string_list(true); - add_stringlist(list, field, isgenre, &sz); + add_stringlist(list, field, frame, &sz); ret = xmalloc(sz + 1); @@ -530,3 +552,3 @@ update_frames(struct id3_tag *tag) static void -collect_text_frames(struct id3_tag *tag) +fixup_charset(struct id3_tag *tag) { @@ -535,2 +557,5 @@ collect_text_frames(struct id3_tag *tag) + if (!broken_8bit_charset) + return; + for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { @@ -539,2 +564,3 @@ collect_text_frames(struct id3_tag *tag) idest_frame_lookup(frame->id); + if (!ft) { @@ -547,2 +573,5 @@ collect_text_frames(struct id3_tag *tag) + if (!frame_encoding_is_8bit(frame)) + continue; + ed_item_zero(&itm); @@ -562,10 +591,2 @@ collect_text_frames(struct id3_tag *tag) -static void -fixup_charset(struct id3_tag *tag) -{ - if (!broken_8bit_charset) - return; - collect_text_frames(tag); -} - void |