diff options
-rw-r--r-- | doc/idest.texi | 2 | ||||
-rw-r--r-- | src/idop.c | 44 | ||||
-rw-r--r-- | src/main.c | 5 |
3 files changed, 39 insertions, 12 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 @example -$ idest --broken-8bit-encoding=iso-8859-1 --fixup *.mp3 +$ idest --broken-8bit-charset=iso-8859-1 --fixup *.mp3 @end example @@ -190,4 +190,10 @@ safe_id3_file_update_and_close(struct id3_file *file) -static int -frame_encoding_is_8bit(struct id3_frame const *frame) +enum frame_recode_option { + FRAME_RECODE_NONE, /* Nothing to recode */ + FRAME_RECODE_UTF8, /* Convert all frames to UTF-8 encoding */ + FRAME_RECODE_BROKEN /* Convert broken 8-bit encodings */ +}; + +enum frame_recode_option +frame_recode_detect(struct id3_frame const *frame) { @@ -196,7 +202,20 @@ frame_encoding_is_8bit(struct id3_frame const *frame) if (!frame) - return 0; + return FRAME_RECODE_NONE; field = id3_frame_field(frame, 0); if (!field) - return 0; - return id3_field_gettextencoding(field) == ID3_FIELD_TEXTENCODING_ISO_8859_1; + return FRAME_RECODE_NONE; + switch (id3_field_gettextencoding(field)) { + case ID3_FIELD_TEXTENCODING_ISO_8859_1: + if (broken_8bit_charset) + return FRAME_RECODE_BROKEN; + /* fall through */ + case ID3_FIELD_TEXTENCODING_UTF_16: + case ID3_FIELD_TEXTENCODING_UTF_16BE: + return FRAME_RECODE_UTF8; + + case ID3_FIELD_TEXTENCODING_UTF_8: + default: + break; + } + return FRAME_RECODE_NONE; } @@ -214,3 +233,3 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4, struct id3_frame const *frame) { - if (broken_8bit_charset && frame_encoding_is_8bit(frame)) { + if (frame_recode_detect(frame) == FRAME_RECODE_BROKEN) { char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); @@ -557,5 +576,2 @@ fixup_charset(struct id3_tag *tag) - if (!broken_8bit_charset) - return; - for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { @@ -573,5 +589,10 @@ fixup_charset(struct id3_tag *tag) - if (!frame_encoding_is_8bit(frame)) - continue; + switch (frame_recode_detect(frame)) { + case FRAME_RECODE_NONE: + break; + case FRAME_RECODE_UTF8: + if (strcasecmp(charset, "UTF-8") != 0) + break; + case FRAME_RECODE_BROKEN: ed_item_zero(&itm); @@ -590,2 +611,3 @@ fixup_charset(struct id3_tag *tag) } +} @@ -199,2 +199,7 @@ main(int argc, char **argv) default_version_option = IDEST_ID3V_1|IDEST_ID3V_2; + if (fixup_option) { + if (charset) + error(1, 0, "--charset cannot be used with --fixup"); + charset = "UTF-8"; + } |