String id3::v2::getStringAtIndex(const ID3_Frame* frame, ID3_FieldID fldName, size_t nIndex) { if (!frame) { return ""; } String text; ID3_Field* fp = frame->GetField(fldName); if (fp && fp->GetNumTextItems() < nIndex) { ID3_TextEnc enc = fp->GetEncoding(); fp->SetEncoding(ID3TE_ASCII); text = fp->GetRawTextItem(nIndex); fp->SetEncoding(enc); } return text; }
void play_debug_meta(char* filename){ ID3_Tag tag(filename); ID3_Tag::Iterator* iter = tag.CreateIterator(); ID3_Frame* frame = NULL; char buf[1000]; // Iconv conversion descriptor: UTF-16 -> UTF-8 iconv_t cd = iconv_open("UTF8","UTF16BE"); while (NULL != (frame = iter->GetNext())) { char* val = NULL; field_text(&val, frame); printf("Frame: type %d %s %s:\n", frame->GetID(), frame->GetTextID(), frame->GetDescription()); ID3_Frame::Iterator* fieldIter = frame->CreateIterator(); ID3_Field* field = NULL; while (NULL != (field = fieldIter->GetNext())) { printf(" Field: type "); ID3_FieldType type = field->GetType(); switch(type) { case ID3FTY_NONE: printf("none"); break; case ID3FTY_INTEGER: printf("int"); break; case ID3FTY_BINARY: printf("binary"); break; case ID3FTY_TEXTSTRING: field->Get(buf, 1000); printf("text with %d items, encoding ", field->GetNumTextItems()); switch(field->GetEncoding()){ case ID3TE_UTF16: printf("UTF-16"); if ( cd != (iconv_t) -1 ) { char* in = (char*) field->GetRawUnicodeText(); size_t insize = field->Size(); char* bufptr = buf; size_t bufsize = 1000; size_t rc = 0; // Initialize iconv state if( iconv(cd, NULL, NULL, &bufptr, &bufsize) == (size_t) -1 ){ printf("iconv init Failed\n"); } if ( (rc = iconv(cd, &in, &insize, &bufptr, &bufsize)) != (size_t) -1 ) { *bufptr = '\0'; printf(": '%s' (%d chars)\n", buf, rc); } else { printf("<conversion using iconv failed>"); perror("iconv"); } } break; case ID3TE_UTF16BE: printf("UTF-16BE"); printf(": '%s'", buf); break; case ID3TE_UTF8: printf("UTF-8"); printf(": '%s'", buf); break; case ID3TE_NONE: printf("none"); printf(": '%s'", buf); break; case ID3TE_ISO8859_1: printf("ISO-8859-1/ASCII"); printf(": '%s'", buf); break; } break; } printf("\n"); } delete fieldIter; delete [] val; } delete iter; iconv_close(cd); }