diff options
-rw-r--r-- | doc/idest.texi | 2 | ||||
-rw-r--r-- | src/idop.c | 68 | ||||
-rw-r--r-- | src/main.c | 5 |
3 files changed, 51 insertions, 24 deletions
diff --git a/doc/idest.texi b/doc/idest.texi index 2b65ab7..f9934c7 100644 --- a/doc/idest.texi +++ b/doc/idest.texi | |||
@@ -491,3 +491,3 @@ If the input tags also contain malformed 8-bit encodings | |||
491 | @example | 491 | @example |
492 | $ idest --broken-8bit-encoding=iso-8859-1 --fixup *.mp3 | 492 | $ idest --broken-8bit-charset=iso-8859-1 --fixup *.mp3 |
493 | @end example | 493 | @end example |
@@ -190,4 +190,10 @@ safe_id3_file_update_and_close(struct id3_file *file) | |||
190 | 190 | ||
191 | static int | 191 | enum frame_recode_option { |
192 | frame_encoding_is_8bit(struct id3_frame const *frame) | 192 | FRAME_RECODE_NONE, /* Nothing to recode */ |
193 | FRAME_RECODE_UTF8, /* Convert all frames to UTF-8 encoding */ | ||
194 | FRAME_RECODE_BROKEN /* Convert broken 8-bit encodings */ | ||
195 | }; | ||
196 | |||
197 | enum frame_recode_option | ||
198 | frame_recode_detect(struct id3_frame const *frame) | ||
193 | { | 199 | { |
@@ -196,7 +202,20 @@ frame_encoding_is_8bit(struct id3_frame const *frame) | |||
196 | if (!frame) | 202 | if (!frame) |
197 | return 0; | 203 | return FRAME_RECODE_NONE; |
198 | field = id3_frame_field(frame, 0); | 204 | field = id3_frame_field(frame, 0); |
199 | if (!field) | 205 | if (!field) |
200 | return 0; | 206 | return FRAME_RECODE_NONE; |
201 | return id3_field_gettextencoding(field) == ID3_FIELD_TEXTENCODING_ISO_8859_1; | 207 | switch (id3_field_gettextencoding(field)) { |
208 | case ID3_FIELD_TEXTENCODING_ISO_8859_1: | ||
209 | if (broken_8bit_charset) | ||
210 | return FRAME_RECODE_BROKEN; | ||
211 | /* fall through */ | ||
212 | case ID3_FIELD_TEXTENCODING_UTF_16: | ||
213 | case ID3_FIELD_TEXTENCODING_UTF_16BE: | ||
214 | return FRAME_RECODE_UTF8; | ||
215 | |||
216 | case ID3_FIELD_TEXTENCODING_UTF_8: | ||
217 | default: | ||
218 | break; | ||
219 | } | ||
220 | return FRAME_RECODE_NONE; | ||
202 | } | 221 | } |
@@ -214,3 +233,3 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4, struct id3_frame const *frame) | |||
214 | { | 233 | { |
215 | if (broken_8bit_charset && frame_encoding_is_8bit(frame)) { | 234 | if (frame_recode_detect(frame) == FRAME_RECODE_BROKEN) { |
216 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); | 235 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); |
@@ -557,5 +576,2 @@ fixup_charset(struct id3_tag *tag) | |||
557 | 576 | ||
558 | if (!broken_8bit_charset) | ||
559 | return; | ||
560 | |||
561 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { | 577 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { |
@@ -573,17 +589,23 @@ fixup_charset(struct id3_tag *tag) | |||
573 | 589 | ||
574 | if (!frame_encoding_is_8bit(frame)) | 590 | switch (frame_recode_detect(frame)) { |
575 | continue; | 591 | case FRAME_RECODE_NONE: |
576 | 592 | break; | |
577 | ed_item_zero(&itm); | 593 | |
578 | itm.name = xstrdup(frame->id); | 594 | case FRAME_RECODE_UTF8: |
579 | memcpy(itm.id, frame->id, 4); | 595 | if (strcasecmp(charset, "UTF-8") != 0) |
580 | if (ft->decode(&itm, frame)) { | 596 | break; |
581 | error(0, 0, "%s: decoding to %s failed", | 597 | case FRAME_RECODE_BROKEN: |
582 | frame->id, charset); | 598 | ed_item_zero(&itm); |
583 | continue; | 599 | itm.name = xstrdup(frame->id); |
600 | memcpy(itm.id, frame->id, 4); | ||
601 | if (ft->decode(&itm, frame)) { | ||
602 | error(0, 0, "%s: decoding to %s failed", | ||
603 | frame->id, charset); | ||
604 | continue; | ||
605 | } | ||
606 | if (!input_list) | ||
607 | input_list = ed_list_create(); | ||
608 | gl_list_add_last(input_list, ed_item_dup(&itm)); | ||
609 | ed_item_free_content(&itm); | ||
584 | } | 610 | } |
585 | if (!input_list) | ||
586 | input_list = ed_list_create(); | ||
587 | gl_list_add_last(input_list, ed_item_dup(&itm)); | ||
588 | ed_item_free_content(&itm); | ||
589 | } | 611 | } |
@@ -199,2 +199,7 @@ main(int argc, char **argv) | |||
199 | default_version_option = IDEST_ID3V_1|IDEST_ID3V_2; | 199 | default_version_option = IDEST_ID3V_1|IDEST_ID3V_2; |
200 | if (fixup_option) { | ||
201 | if (charset) | ||
202 | error(1, 0, "--charset cannot be used with --fixup"); | ||
203 | charset = "UTF-8"; | ||
204 | } | ||
200 | 205 | ||