diff options
Diffstat (limited to 'src/idop.c')
-rw-r--r-- | src/idop.c | 59 |
1 files changed, 40 insertions, 19 deletions
@@ -189,8 +189,29 @@ safe_id3_file_update_and_close(struct id3_file *file) | |||
189 | } | 189 | } |
190 | 190 | ||
191 | static int | ||
192 | frame_encoding_is_8bit(struct id3_frame const *frame) | ||
193 | { | ||
194 | union id3_field const *field; | ||
195 | |||
196 | if (!frame) | ||
197 | return 0; | ||
198 | field = id3_frame_field(frame, 0); | ||
199 | if (!field) | ||
200 | return 0; | ||
201 | return id3_field_gettextencoding(field) == ID3_FIELD_TEXTENCODING_ISO_8859_1; | ||
202 | } | ||
203 | |||
204 | static int | ||
205 | frame_is_genre(struct id3_frame const *frame) | ||
206 | { | ||
207 | if (!frame) | ||
208 | return 0; | ||
209 | return strcmp(frame->id, ID3_FRAME_GENRE) == 0; | ||
210 | } | ||
211 | |||
191 | char * | 212 | char * |
192 | idest_ucs4_cvt(id3_ucs4_t const *ucs4) | 213 | idest_ucs4_cvt(id3_ucs4_t const *ucs4, struct id3_frame const *frame) |
193 | { | 214 | { |
194 | if (broken_8bit_charset) { | 215 | if (broken_8bit_charset && frame_encoding_is_8bit(frame)) { |
195 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); | 216 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); |
196 | char *output; | 217 | char *output; |
@@ -206,5 +227,6 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4) | |||
206 | 227 | ||
207 | static void | 228 | static void |
208 | add_stringlist(gl_list_t list, union id3_field *field, int isgenre, | 229 | add_stringlist(gl_list_t list, union id3_field *field, |
230 | struct id3_frame const *frame, | ||
209 | size_t *psize) | 231 | size_t *psize) |
210 | { | 232 | { |
@@ -219,7 +241,7 @@ add_stringlist(gl_list_t list, union id3_field *field, int isgenre, | |||
219 | if (!ucs4) | 241 | if (!ucs4) |
220 | continue; | 242 | continue; |
221 | if (isgenre) | 243 | if (frame_is_genre(frame)) |
222 | ucs4 = id3_genre_name(ucs4); | 244 | ucs4 = id3_genre_name(ucs4); |
223 | str = idest_ucs4_cvt(ucs4); | 245 | str = idest_ucs4_cvt(ucs4, frame); |
224 | size += strlen(str); | 246 | size += strlen(str); |
225 | gl_list_add_last(list, str); | 247 | gl_list_add_last(list, str); |
@@ -285,5 +307,5 @@ field_binary_from_string(union id3_field *field, const char *str) | |||
285 | 307 | ||
286 | char * | 308 | char * |
287 | field_to_string(union id3_field *field, int isgenre) | 309 | field_to_string(union id3_field *field, struct id3_frame const *frame) |
288 | { | 310 | { |
289 | id3_ucs4_t const *ucs4; | 311 | id3_ucs4_t const *ucs4; |
@@ -313,11 +335,11 @@ field_to_string(union id3_field *field, int isgenre) | |||
313 | case ID3_FIELD_TYPE_STRING: | 335 | case ID3_FIELD_TYPE_STRING: |
314 | ucs4 = id3_field_getstring(field);; | 336 | ucs4 = id3_field_getstring(field);; |
315 | if (ucs4) | 337 | if (ucs4) |
316 | ret = idest_ucs4_cvt(ucs4); | 338 | ret = idest_ucs4_cvt(ucs4, frame); |
317 | break; | 339 | break; |
318 | 340 | ||
319 | case ID3_FIELD_TYPE_STRINGFULL: | 341 | case ID3_FIELD_TYPE_STRINGFULL: |
320 | ucs4 = id3_field_getfullstring(field); | 342 | ucs4 = id3_field_getfullstring(field); |
321 | ret = idest_ucs4_cvt(ucs4); | 343 | ret = idest_ucs4_cvt(ucs4, frame); |
322 | break; | 344 | break; |
323 | 345 | ||
@@ -329,5 +351,5 @@ field_to_string(union id3_field *field, int isgenre) | |||
329 | 351 | ||
330 | list = new_string_list(true); | 352 | list = new_string_list(true); |
331 | add_stringlist(list, field, isgenre, &sz); | 353 | add_stringlist(list, field, frame, &sz); |
332 | ret = xmalloc(sz + 1); | 354 | ret = xmalloc(sz + 1); |
333 | ret[0] = 0; | 355 | ret[0] = 0; |
@@ -529,13 +551,17 @@ update_frames(struct id3_tag *tag) | |||
529 | 551 | ||
530 | static void | 552 | static void |
531 | collect_text_frames(struct id3_tag *tag) | 553 | fixup_charset(struct id3_tag *tag) |
532 | { | 554 | { |
533 | struct id3_frame *frame; | 555 | struct id3_frame *frame; |
534 | unsigned i; | 556 | unsigned i; |
535 | 557 | ||
558 | if (!broken_8bit_charset) | ||
559 | return; | ||
560 | |||
536 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { | 561 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { |
537 | struct ed_item itm; | 562 | struct ed_item itm; |
538 | const struct idest_frametab *ft = | 563 | const struct idest_frametab *ft = |
539 | idest_frame_lookup(frame->id); | 564 | idest_frame_lookup(frame->id); |
565 | |||
540 | if (!ft) { | 566 | if (!ft) { |
541 | if (verbose_option) | 567 | if (verbose_option) |
@@ -546,4 +572,7 @@ collect_text_frames(struct id3_tag *tag) | |||
546 | } | 572 | } |
547 | 573 | ||
574 | if (!frame_encoding_is_8bit(frame)) | ||
575 | continue; | ||
576 | |||
548 | ed_item_zero(&itm); | 577 | ed_item_zero(&itm); |
549 | itm.name = xstrdup(frame->id); | 578 | itm.name = xstrdup(frame->id); |
@@ -561,12 +590,4 @@ collect_text_frames(struct id3_tag *tag) | |||
561 | } | 590 | } |
562 | 591 | ||
563 | static void | ||
564 | fixup_charset(struct id3_tag *tag) | ||
565 | { | ||
566 | if (!broken_8bit_charset) | ||
567 | return; | ||
568 | collect_text_frames(tag); | ||
569 | } | ||
570 | |||
571 | void | 592 | void |
572 | set_tags(const char *name) | 593 | set_tags(const char *name) |