STDMETHODIMP CID3Field::get_Binary(BSTR *pVal) { // TODO: Add your implementation code here if (pVal == NULL) return E_POINTER; try { *pVal = NULL; const uchar *pData = m_Field->GetRawBinary(); if (pData == NULL) return E_FAIL; ID3_Frame *pFrame = ((CID3Frame*)m_FrameParent)->GetID3Frame(); if (pFrame->GetID() == ID3FID_PICTURE) { *pVal = _bstr_t((LPCTSTR)pData).copy(); } else { *pVal = SysAllocStringByteLen((const char *)pData,m_Field->Size()); } } catch (...) { return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED); } return S_OK; }
void GetTestTag(void) { ID3_Tag myTag("dummy.tag"); ID3_Frame *myFrame; if (myFrame = myTag.Find(ID3FID_PICTURE)) { cout << "Found a picture frame!\r\n" << endl; char *dada = "output.jpg"; myFrame->Field(ID3FN_DATA).ToFile(dada); } if (myFrame = myTag.Find(ID3FID_USERTEXT, ID3FN_DESCRIPTION, "example #1")) { cout << "Found a user text frame!\r\n" << endl; char textBuff[1024]; myFrame->Field(ID3FN_DESCRIPTION).Get(textBuff, 1024); cout << "Desc: " << textBuff << endl; myFrame->Field(ID3FN_TEXT).Get(textBuff, 1024); cout << "Text: " << textBuff << endl; } for (luint i = 0; i < myTag.NumFrames(); i++) if (myFrame = myTag[i]) cout << "Frame " << i << " has ID " << (luint) myFrame->GetID() << endl; return; }
int main( int argc, char *argv[]) { ID3D_INIT_DOUT(); ID3D_INIT_WARNING(); ID3D_INIT_NOTICE(); ID3_Tag tag; ID3_Frame frame; tag.Link("test-230-compressed.tag"); tag.Strip(ID3TT_ALL); tag.Clear(); frame.SetID(ID3FID_USERTEXT); frame.GetField(ID3FN_DESCRIPTION)->Set("compression example"); frame.GetField(ID3FN_TEXT)->Set("This sample user text frame came from an ID3v2-3.0 tag. The frame has the 'compression' bit set in it's frame header. This is the new method for compressing frames, which supercedes the 2.01 Compressed Data Metaframe."); frame.SetCompression(true); tag.AddFrame(frame); tag.SetPadding(false); tag.SetUnsync(false); tag.Update(ID3TT_ID3V2); return 0; }
ID3_Frame *ID3_GetSyncLyrics(const ID3_Tag* tag, const char* lang, const char* desc, const uchar* &pData, size_t& size) { // check if a SYLT frame of this language or descriptor exists ID3_Frame* frmExist = NULL; if (NULL != lang) { // search through language frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, lang); } else if (NULL != desc) { // search through descriptor frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, desc); } else { // both language and description not specified, search the first SYLT frame frmExist = tag->Find(ID3FID_SYNCEDLYRICS); } if (NULL == frmExist) { return NULL; } // get the lyrics size size = dami::min(size, frmExist->GetField(ID3FN_DATA)->Size()); // get the lyrics data pData = frmExist->GetField (ID3FN_DATA)->GetRawBinary(); // return the frame pointer for further uses return frmExist; }
//following routine courtesy of John George size_t ID3_GetPictureDataOfPicType(ID3_Tag* tag, const char* TempPicPath, ID3_PictureType pictype) { if (NULL == tag) return 0; else { ID3_Frame* frame = NULL; ID3_Tag::Iterator* iter = tag->CreateIterator(); while (NULL != (frame = iter->GetNext() )) { if(frame->GetID() == ID3FID_PICTURE) { if(frame->GetField(ID3FN_PICTURETYPE)->Get() == (uint32)pictype) break; } } delete iter; if (frame != NULL) { ID3_Field* myField = frame->GetField(ID3FN_DATA); if (myField != NULL) { myField->ToFile(TempPicPath); return (size_t)myField->Size(); } else return 0; } else return 0; } }
//following routine courtesy of John George size_t ID3_RemovePictureType(ID3_Tag* tag, ID3_PictureType pictype) { size_t bremoved = 0; ID3_Frame* frame = NULL; if (NULL == tag) return bremoved; ID3_Tag::Iterator* iter = tag->CreateIterator(); while (NULL != (frame = iter->GetNext())) { if (frame->GetID() == ID3FID_PICTURE) { if (frame->GetField(ID3FN_PICTURETYPE)->Get() == (uint32)pictype) break; } } delete iter; if (NULL != frame) { frame = tag->RemoveFrame(frame); delete frame; bremoved = 1; } return bremoved; }
// Remove all comments from the tag with the given description size_t id3::v2::removeComments(ID3_TagImpl& tag, String desc) { size_t numRemoved = 0; for (ID3_TagImpl::iterator iter = tag.begin(); iter != tag.end(); ++iter) { ID3_Frame* frame = *iter; if (frame == NULL) { continue; } if (frame->GetID() == ID3FID_COMMENT) { // See if the description we have matches the description of the // current comment. If so, remove the comment String tmpDesc = getString(frame, ID3FN_DESCRIPTION); if (tmpDesc == desc) { frame = tag.RemoveFrame(frame); delete frame; numRemoved++; } } } return numRemoved; }
ID3_Frame* id3::v2::setLyrics(ID3_TagImpl& tag, String text, String desc, String lang) { ID3_Frame* frame = NULL; // See if there is already a comment with this description for (ID3_TagImpl::iterator iter = tag.begin(); iter != tag.end(); ++iter) { frame = *iter; if (frame == NULL) { continue; } if (frame->GetID() == ID3FID_COMMENT) { String tmpDesc = getString(frame, ID3FN_DESCRIPTION); if (tmpDesc == desc) { break; } } frame = NULL; } if (frame == NULL) { frame = new ID3_Frame(ID3FID_UNSYNCEDLYRICS); if(!tag.AttachFrame(frame)) return NULL; } frame->GetField(ID3FN_LANGUAGE)->Set(lang.c_str()); frame->GetField(ID3FN_DESCRIPTION)->Set(desc.c_str()); frame->GetField(ID3FN_TEXT)->Set(text.c_str()); return frame; }
//following routine courtesy of John George char* ID3_GetDescriptionOfPicType(ID3_Tag* tag, ID3_PictureType pictype) { char* sPicDescription = NULL; if (NULL == tag) return sPicDescription; ID3_Frame* frame = NULL; ID3_Tag::Iterator* iter = tag->CreateIterator(); while (NULL != (frame = iter->GetNext())) { if(frame->GetID() == ID3FID_PICTURE) { if(frame->GetField(ID3FN_PICTURETYPE)->Get() == (uint32)pictype) break; } } delete iter; if (frame != NULL) { sPicDescription = ID3_GetString(frame, ID3FN_DESCRIPTION); } return sPicDescription; }
ID3_Frame* ID3_AddArtist(ID3_Tag *tag, const char *text, bool replace) { ID3_Frame* frame = NULL; if (NULL != tag && NULL != text && strlen(text) > 0) { if (replace) { ID3_RemoveArtists(tag); } if (replace || (tag->Find(ID3FID_LEADARTIST) == NULL && tag->Find(ID3FID_BAND) == NULL && tag->Find(ID3FID_CONDUCTOR) == NULL && tag->Find(ID3FID_COMPOSER) == NULL)) { frame = new ID3_Frame(ID3FID_LEADARTIST); if (frame) { frame->GetField(ID3FN_TEXT)->Set(text); tag->AttachFrame(frame); } } } return frame; }
ID3_Frame* ID3_AddLyrics(ID3_Tag *tag, const char *text, const char* desc, const char* lang, bool replace) { ID3_Frame* frame = NULL; if (NULL != tag && strlen(text) > 0) { if (replace) { ID3_RemoveLyrics(tag); } if (replace || tag->Find(ID3FID_UNSYNCEDLYRICS) == NULL) { frame = new ID3_Frame(ID3FID_UNSYNCEDLYRICS); if (NULL != frame) { frame->GetField(ID3FN_LANGUAGE)->Set(lang); frame->GetField(ID3FN_DESCRIPTION)->Set(desc); frame->GetField(ID3FN_TEXT)->Set(text); tag->AttachFrame(frame); } } } return frame; }
ID3_Frame* ID3_AddGenre(ID3_Tag *tag, size_t ucGenre, bool bReplace) { ID3_Frame* pFrame = NULL; if (NULL != tag && 0xFF != ucGenre) { if (bReplace) { ID3_RemoveGenres(tag); } if (bReplace || NULL == tag->Find(ID3FID_CONTENTTYPE)) { pFrame = new ID3_Frame(ID3FID_CONTENTTYPE); if (NULL != pFrame) { char sGenre[6]; sprintf(sGenre, "(%lu)", (luint) ucGenre); pFrame->Field(ID3FN_TEXT) = sGenre; tag->AttachFrame(pFrame); } } } return pFrame; }
void Genre_addGenre(ID3_Tag & id3, const char * genre) { ID3_Frame* frame = NULL; if (genre) { ID3_RemoveGenres(&id3); if (NULL == id3.Find(ID3FID_CONTENTTYPE)) { frame = new ID3_Frame(ID3FID_CONTENTTYPE); if (NULL != frame) { // int g = Genre_getInt(genre); // char sGenre[100]; // if (g > 0) { // sprintf(sGenre, "(%d)", g); // } else { // sprintf(sGenre, "%s", genre); // } frame->GetField(ID3FN_TEXT)->Set(genre); id3.AttachFrame(frame); } } } return; }
ID3_Frame *ID3_Tag::Find( ID3_FrameID id, ID3_FieldID fld, wchar_t *data ) { ID3_Frame *frame = NULL; ID3_Elem *cur = findCursor; bool done = false; if ( cur == NULL ) findCursor = cur = frameList; while ( ! done && cur ) { if ( cur->frame && ( cur->frame->GetID() == id ) ) { frame = cur->frame; if ( data && wcslen ( data ) && BS_ISSET ( frame->fieldBits, fld ) ) { wchar_t *buffer; luint size; size = frame->Field ( fld ).BinSize(); #ifdef _DEBUG //ASSERT( size < MAX_ALLOC ); // PL #endif buffer = new wchar_t[size]; { frame->Field ( fld ).Get(buffer, size); if(wcscmp(buffer, data) != 0 ) { frame = NULL; cur = cur->next; } delete[] buffer; } } if ( frame ) { findCursor = cur->next; break; } } else cur = cur->next; if ( cur == NULL ) cur = frameList; if ( cur == findCursor ) done = true; } return frame; }
BString id3::v2::getSyncLyrics(const ID3_TagImpl& tag, String lang, String desc) { // check if a SYLT frame of this language or descriptor exists ID3_Frame* frame = NULL; (frame = tag.Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, lang.c_str())) || (frame = tag.Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, desc.c_str())) || (frame = tag.Find(ID3FID_SYNCEDLYRICS)); // get the lyrics size ID3_Field* fld = frame->GetField(ID3FN_DATA); return BString(reinterpret_cast<const BString::value_type *>(fld->GetRawBinary()), fld->Size()); }
ID3_Frame* id3::v2::setFrameText(ID3_TagImpl& tag, ID3_FrameID id, String text) { ID3_Frame* frame = tag.Find(id); if (!frame) { frame = new ID3_Frame(id); if(!tag.AttachFrame(frame)) return NULL; } frame->GetField(ID3FN_TEXT)->Set(text.c_str()); return frame; }
void CID3LibWrapper::getFrameText( enum ID3_FrameID eFrameId, std::string& sVal ) const{ ID3_Frame* pframe = myTag.Find(eFrameId); if(NULL != pframe){ ID3_Field* pField = pframe->GetField(ID3FN_TEXT); if(NULL != pField){ const_cast<CID3LibWrapper*>(this)->getFieldText(pField, sVal); //testFrame(pframe, pField); } } }
ID3_Frame* ID3_AddComment(ID3_Tag *tag, const char *sComment, const char *sDescription, bool bReplace) { ID3_Frame* pFrame = NULL; if (NULL != tag && NULL != sComment && NULL != sDescription && strlen(sComment) > 0) { bool bAdd = true; if (bReplace) { ID3_RemoveComments(tag, sDescription); } else { // See if there is already a comment with this description for (size_t nCount = 0; nCount < tag->NumFrames(); nCount++) { pFrame = tag->GetFrameNum(nCount); if (pFrame->GetID() == ID3FID_COMMENT) { char *sDesc = ID3_GetString(pFrame, ID3FN_DESCRIPTION); if (strcmp(sDesc, sDescription) == 0) { bAdd = false; } delete [] sDesc; if (!bAdd) { break; } } } } if (bAdd) { pFrame = new ID3_Frame(ID3FID_COMMENT); if (NULL != pFrame) { pFrame->Field(ID3FN_LANGUAGE) = "eng"; pFrame->Field(ID3FN_DESCRIPTION) = sDescription; pFrame->Field(ID3FN_TEXT) = sComment; tag->AttachFrame(pFrame); } } } return pFrame; }
QString PlaybackControls::getComment(QString file) { QString field; ID3_Tag mTag(file.toStdString().c_str()); ID3_Frame* myFrame = mTag.Find(ID3FID_COMMENT); if (myFrame) { ID3_Field* myField = myFrame->GetField(ID3FN_TEXT); if (myField) { field = myField->GetRawText(); } } return field; }
ID3_Frame* ID3_AddMCDI(ID3_Tag *tag, const char *text, bool bReplace) { ID3_Frame* pFrame = NULL; if (NULL != tag && NULL != text && strlen(text) > 0) { if (bReplace) { ID3_RemoveMCDI(tag); } if (bReplace || tag->Find(ID3FID_CDID) == NULL) { pFrame = new ID3_Frame( ID3FID_CDID ); if (pFrame) { const int nMaxTagLength = 804; size_t nStrLen = strlen( text ); uchar *temp = new uchar[ nMaxTagLength + 1 ]; memset( temp, sizeof( temp ), 0 ); if ( NULL == temp ) { // AF ID3_THROW( ID3E_NoMemory ); } memset( temp, 0x00, sizeof( temp ) ); //fixes 99 tracks bug if( nStrLen > nMaxTagLength / 2 ) { nStrLen = nMaxTagLength / 2; } // mbstoucs( (unicode_t *)temp, text, nStrLen + 1 ); pFrame->Field(ID3FN_DATA).Set( temp, nMaxTagLength ); // delete[] temp; tag->AttachFrame( pFrame ); } } } return pFrame; }
QPixmap PlaybackControls::getPicture(QString file) { QPixmap field; ID3_Tag mTag(file.toStdString().c_str()); ID3_Frame* myFrame = mTag.Find(ID3FID_PICTURE); if (myFrame) { ID3_Field* myField = myFrame->GetField(ID3FN_DATA); if (myField) { const uchar *test = myField->GetRawBinary(); field.loadFromData(test, myField->Size()); } } return field; }
ID3_Frame* ID3_AddSyncLyrics(ID3_Tag *tag, const char *lang, const char *desc, const uchar *text, size_t textsize, bool bReplace) { ID3_Frame* pFrame = NULL; // language and descriptor should be mandatory if ((NULL == lang) || (NULL == desc)) { return NULL; } // check if a SYLT frame of this language or descriptor already exists ID3_Frame* pFrameExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, (char *) lang); if (!pFrameExist) { pFrameExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, (char *) desc); } if (NULL != tag && NULL != text) { if (bReplace && pFrameExist) { tag->RemoveFrame (pFrameExist); pFrameExist = NULL; } // if the frame still exist, cannot continue if (pFrameExist) { return NULL; } ID3_Frame* pFrame = new ID3_Frame(ID3FID_SYNCEDLYRICS); if (NULL == pFrame) { ID3_THROW(ID3E_NoMemory); } pFrame->Field(ID3FN_LANGUAGE) = lang; pFrame->Field(ID3FN_DESCRIPTION) = desc; pFrame->Field(ID3FN_DATA).Set(text, textsize); tag->AttachFrame(pFrame); } return pFrame; }
int CMP4Tag::ReadAacTag(char *Filename) { char *buf=NULL; ID3_Tag id3Tag; ID3_Frame *Frame; if(!id3Tag.Link(Filename)) { char buf[25+MAX_PATH+1]; sprintf(buf,"ReadAacTag: can't open \"%s\"",Filename); MessageBox(NULL,buf,NULL,MB_OK); return 1; } GET_FIELD_STR(id3Tag,ID3FID_ENCODEDBY,ID3FN_TEXT,copyright); GET_FIELD_STR(id3Tag,ID3FID_LEADARTIST,ID3FN_TEXT,artist); GET_FIELD_STR(id3Tag,ID3FID_COMPOSER,ID3FN_TEXT,writer); GET_FIELD_STR(id3Tag,ID3FID_TITLE,ID3FN_TEXT,title); GET_FIELD_STR(id3Tag,ID3FID_ALBUM,ID3FN_TEXT,album); GET_FIELD_STR(id3Tag,ID3FID_TRACKNUM,ID3FN_TEXT,buf); if(buf) trackno=atoi(buf); FREE_ARRAY(buf); GET_FIELD_STR(id3Tag,ID3FID_YEAR,ID3FN_TEXT,year); GET_FIELD_STR(id3Tag,ID3FID_CONTENTTYPE,ID3FN_TEXT,genre); GET_FIELD_STR(id3Tag,ID3FID_COMMENT,ID3FN_TEXT,comment); if(Frame=id3Tag.Find(ID3FID_PICTURE)) { art.size=Frame->Field(ID3FN_DATA).Size(); FREE_ARRAY(art.data); if(art.data=(char *)malloc(art.size)) memcpy(art.data,Frame->Field(ID3FN_DATA).GetBinary(),art.size); GET_FIELD_STR(id3Tag,ID3FID_PICTURE,ID3FN_MIMETYPE,art.mimeType); GET_FIELD_STR(id3Tag,ID3FID_PICTURE,ID3FN_DESCRIPTION,art.description); GET_FIELD_STR(id3Tag,ID3FID_PICTURE,ID3FN_IMAGEFORMAT,art.format); art.pictureType=Frame->Field(ID3FN_PICTURETYPE).Get(); /* FILE *f=fopen("D:\\prova.jpg","wb"); fwrite(artFile,1,artSize,f); fclose(f);*/ } return 0; }
void ID3_AddAlbum ( ID3_Tag *tag, char *text ) { if ( tag->Find ( ID3FID_ALBUM ) == NULL && strlen ( text ) > 0 ) { ID3_Frame *albumFrame; if ( albumFrame = new ID3_Frame ) { albumFrame->SetID ( ID3FID_ALBUM ); albumFrame->Field ( ID3FN_TEXT ) = text; tag->AddFrame ( albumFrame, true ); } else ID3_THROW ( ID3E_NoMemory ); } return; }
void ID3_AddTitle ( ID3_Tag *tag, char *text ) { if ( tag->Find ( ID3FID_TITLE ) == NULL && strlen ( text ) > 0 ) { ID3_Frame *titleFrame; if ( titleFrame = new ID3_Frame ) { titleFrame->SetID ( ID3FID_TITLE ); titleFrame->Field ( ID3FN_TEXT ) = text; tag->AddFrame ( titleFrame, true ); } else ID3_THROW ( ID3E_NoMemory ); } return; }
//following routine courtesy of John George bool ID3_HasPicture(const ID3_Tag* tag) { if (NULL == tag) return false; else { ID3_Frame* frame = tag->Find(ID3FID_PICTURE); if (frame != NULL) { ID3_Field* myField = frame->GetField(ID3FN_DATA); if (myField != NULL) return true; else return false; } else return false; } }
ID3_Frame* id3::v2::setComment(ID3_TagImpl& tag, String text, String desc, String lang) { ID3D_NOTICE( "id3::v2::setComment: trying to find frame with description = " << desc ); ID3_Frame* frame = NULL; // See if there is already a comment with this description for (ID3_TagImpl::iterator iter = tag.begin(); iter != tag.end(); ++iter) { frame = *iter; if (frame == NULL) { continue; } if (frame->GetID() == ID3FID_COMMENT) { String tmpDesc = getString(frame, ID3FN_DESCRIPTION); if (tmpDesc == desc) { ID3D_NOTICE( "id3::v2::setComment: found frame with description = " << desc ); break; } } frame = NULL; } if (frame == NULL) { ID3D_NOTICE( "id3::v2::setComment: creating new comment frame" ); frame = new ID3_Frame(ID3FID_COMMENT); if(!tag.AttachFrame(frame)) return NULL; } if (!frame) { ID3D_WARNING( "id3::v2::setComment: ack! no frame" ); } else { frame->GetField(ID3FN_LANGUAGE)->Set(lang.c_str()); frame->GetField(ID3FN_DESCRIPTION)->Set(desc.c_str()); frame->GetField(ID3FN_TEXT)->Set(text.c_str()); } return frame; }
void ID3_AddLyrics( ID3_Tag *tag, char *text ) { if ( tag->Find ( ID3FID_UNSYNCEDLYRICS ) == NULL && strlen ( text ) > 0 ) { ID3_Frame *lyricsFrame; if ( lyricsFrame = new ID3_Frame ) { lyricsFrame->SetID ( ID3FID_UNSYNCEDLYRICS ); lyricsFrame->Field ( ID3FN_LANGUAGE ) = "eng"; lyricsFrame->Field ( ID3FN_TEXT ) = text; tag->AddFrame ( lyricsFrame, true ); } else ID3_THROW ( ID3E_NoMemory ); } return; }
//following routine courtesy of John George ID3_Frame* ID3_AddPicture(ID3_Tag* tag, const char* TempPicPath, const char* MimeType, bool replace) { ID3_Frame* frame = NULL; if (NULL != tag ) { if (replace) ID3_RemovePictures(tag); if (replace || NULL == tag->Find(ID3FID_PICTURE)) { frame = new ID3_Frame(ID3FID_PICTURE); if (NULL != frame) { frame->GetField(ID3FN_DATA)->FromFile(TempPicPath); frame->GetField(ID3FN_MIMETYPE)->Set(MimeType); tag->AttachFrame(frame); } } } return frame; }
// Remove all comments with the given description (remove all comments if // desc is NULL) size_t ID3_RemoveComments(ID3_Tag *tag, const char *desc) { size_t num_removed = 0; if (NULL == tag) { return num_removed; } ID3_Tag::Iterator* iter = tag->CreateIterator(); ID3_Frame* frame = NULL; while ((frame = iter->GetNext()) != NULL) { if (frame->GetID() == ID3FID_COMMENT) { bool remove = false; // A null description means remove all comments if (NULL == desc) { remove = true; } else { // See if the description we have matches the description of the // current comment. If so, set the "remove the comment" flag to true. char *tmp_desc = ID3_GetString(frame, ID3FN_DESCRIPTION); remove = (strcmp(tmp_desc, desc) == 0); delete [] tmp_desc; } if (remove) { frame = tag->RemoveFrame(frame); delete frame; num_removed++; } } } delete iter; return num_removed; }