Skip to content
Browse files

[fix] - refactored and cleaned up e09cb07 into libid3tag

  • Loading branch information...
1 parent 09efaf4 commit c772f04fe094ccd2a687b0b8d5608ed8d41605be @Memphiz Memphiz committed Dec 11, 2011
Showing with 26 additions and 13 deletions.
  1. +26 −13 lib/libid3tag/libid3tag/metadata.c
View
39 lib/libid3tag/libid3tag/metadata.c
@@ -298,27 +298,40 @@ const id3_ucs4_t* id3_metadata_getcomment(const struct id3_tag* tag, enum id3_fi
{
union id3_field const *field;
struct id3_frame const *frame;
- const id3_ucs4_t* ucs4 = 0;
+ const id3_ucs4_t* ucs4 = id3_ucs4_empty;
int commentNumber = 0;
// return the first non-empty comment
do
{
frame = id3_tag_findframe(tag, ID3_FRAME_COMMENT, commentNumber++);
- if (frame == 0)
- return id3_ucs4_empty;
- *encoding = id3_field_gettextencoding(id3_frame_field(frame, 0));
-
- field = id3_frame_field(frame, 3);
- if (field == 0)
- return id3_ucs4_empty;
+ if (frame && frame->nfields == 4)
+ {
+ //get short description
+ ucs4 = id3_field_getstring(id3_frame_field(frame, 2));
+
+ // Multiple values are allowed per comment field, but storing different comment
+ // frames requires a different description for each frame. The first COMM frame
+ // encountered without a description will be used as the comment field.
+ // Source http://puddletag.sourceforge.net/source/id3.html
+ if (ucs4 && *ucs4 == 0)//if short description on this frame is empty - consider this the wanted comment frame
+ {
+ //fetch encoding of the frame
+ *encoding = id3_field_gettextencoding(id3_frame_field(frame, 0));
+
+ //finally fetch the comment
+ field = id3_frame_field(frame, 3);
+ if (field == 0)
+ break;
- ucs4 = id3_field_getfullstring(field);
- if (!ucs4)
- return id3_ucs4_empty;
+ ucs4 = id3_field_getfullstring(field);
+ //done
+ break;
+ }
+ }
}
- while (*ucs4 == 0);
+ while (frame);
return ucs4;
}
@@ -330,7 +343,7 @@ int id3_metadata_setcomment(struct id3_tag* tag, id3_ucs4_t* value)
frame = id3_tag_findframe(tag, ID3_FRAME_COMMENT, 0);
if (frame == 0)
{
- frame = id3_frame_new(ID3_FRAME_COMMENT);
+ frame = id3_frame_new(ID3_FRAME_COMMENT);
id3_tag_attachframe(tag, frame);
}

0 comments on commit c772f04

Please sign in to comment.
Something went wrong with that request. Please try again.