summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/frametab.gperf7
-rw-r--r--src/idest.h3
-rw-r--r--src/idop.c59
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
@@ -42,7 +42,7 @@ decode_qv(struct ed_item *item, struct id3_frame const *frame,
42 field = id3_frame_field(frame, n + i); 42 field = id3_frame_field(frame, n + i);
43 if (!field) 43 if (!field)
44 break; 44 break;
45 item->qv[i] = field_to_string(field, 0); 45 item->qv[i] = field_to_string(field, frame);
46 } 46 }
47 return 0; 47 return 0;
48} 48}
@@ -346,15 +346,14 @@ text_encode(struct id3_frame *frame, struct ed_item const *item)
346static int 346static int
347text_decode(struct ed_item *item, struct id3_frame const *frame) 347text_decode(struct ed_item *item, struct id3_frame const *frame)
348{ 348{
349 int isgenre = strcmp(frame->id, ID3_FRAME_GENRE) == 0;
350 union id3_field *field; 349 union id3_field *field;
351 char *str; 350 char *str;
352 int rc; 351 int rc;
353 352
354 field = id3_frame_field(frame, 1); 353 field = id3_frame_field(frame, 1);
355 if (!field) 354 if (!field)
356 return IDEST_ERR_NOFIELD; 355 return IDEST_ERR_NOFIELD;
357 str = field_to_string(field, isgenre); 356 str = field_to_string(field, frame);
358 rc = utf8_convert(idest_conv_decode, str, &item->value); 357 rc = utf8_convert(idest_conv_decode, str, &item->value);
359 free(str); 358 free(str);
360 if (rc) 359 if (rc)
diff --git a/src/idest.h b/src/idest.h
index 2c10077..787cdad 100644
--- a/src/idest.h
+++ b/src/idest.h
@@ -92,11 +92,10 @@ int guess_file_tag_options(struct id3_file *file, int *modified);
92int set_frame_value(struct id3_frame *frame, const struct ed_item *item); 92int set_frame_value(struct id3_frame *frame, const struct ed_item *item);
93void set_tags(const char *name); 93void set_tags(const char *name);
94void del_tags(const char *name); 94void del_tags(const char *name);
95char *idest_ucs4_cvt(id3_ucs4_t const *ucs4);
96void query_tags(const char *name); 95void query_tags(const char *name);
97void info_id3(const char *name); 96void info_id3(const char *name);
98 97
99char *field_to_string(union id3_field *field, int isgenre); 98char *field_to_string(union id3_field *field, struct id3_frame const *frame);
100int field_binary_from_string(union id3_field *field, const char *str); 99int field_binary_from_string(union id3_field *field, const char *str);
101char *field_binary_to_string(union id3_field *field); 100char *field_binary_to_string(union id3_field *field);
102 101
diff --git a/src/idop.c b/src/idop.c
index 063ff78..c3a3ce2 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -188,10 +188,31 @@ safe_id3_file_update_and_close(struct id3_file *file)
188 sigprocmask(SIG_SETMASK, &oldset, NULL); 188 sigprocmask(SIG_SETMASK, &oldset, NULL);
189} 189}
190 190
191static int
192frame_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
204static int
205frame_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
191char * 212char *
192idest_ucs4_cvt(id3_ucs4_t const *ucs4) 213idest_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;
197 int rc = utf8_convert(idest_conv_recode, tempval, &output); 218 int rc = utf8_convert(idest_conv_recode, tempval, &output);
@@ -205,7 +226,8 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4)
205} 226}
206 227
207static void 228static void
208add_stringlist(gl_list_t list, union id3_field *field, int isgenre, 229add_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{
211 unsigned i, nstrings = id3_field_getnstrings(field); 233 unsigned i, nstrings = id3_field_getnstrings(field);
@@ -218,9 +240,9 @@ add_stringlist(gl_list_t list, union id3_field *field, int isgenre,
218 ucs4 = id3_field_getstrings(field, i); 240 ucs4 = id3_field_getstrings(field, i);
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);
226 } 248 }
@@ -284,7 +306,7 @@ field_binary_from_string(union id3_field *field, const char *str)
284} 306}
285 307
286char * 308char *
287field_to_string(union id3_field *field, int isgenre) 309field_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;
290 char *ret = NULL; 312 char *ret = NULL;
@@ -312,13 +334,13 @@ field_to_string(union id3_field *field, int isgenre)
312 334
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
324 case ID3_FIELD_TYPE_STRINGLIST: { 346 case ID3_FIELD_TYPE_STRINGLIST: {
@@ -328,7 +350,7 @@ field_to_string(union id3_field *field, int isgenre)
328 const void *p; 350 const void *p;
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;
334 itr = gl_list_iterator(list); 356 itr = gl_list_iterator(list);
@@ -528,15 +550,19 @@ update_frames(struct id3_tag *tag)
528} 550}
529 551
530static void 552static void
531collect_text_frames(struct id3_tag *tag) 553fixup_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)
542 error(0, 0, 568 error(0, 0,
@@ -545,6 +571,9 @@ collect_text_frames(struct id3_tag *tag)
545 continue; 571 continue;
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);
550 memcpy(itm.id, frame->id, 4); 579 memcpy(itm.id, frame->id, 4);
@@ -560,14 +589,6 @@ collect_text_frames(struct id3_tag *tag)
560 } 589 }
561} 590}
562 591
563static void
564fixup_charset(struct id3_tag *tag)
565{
566 if (!broken_8bit_charset)
567 return;
568 collect_text_frames(tag);
569}
570
571void 592void
572set_tags(const char *name) 593set_tags(const char *name)
573{ 594{

Return to:

Send suggestions and report system problems to the System administrator.