00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #if defined HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032
00033 #include <string.h>
00034 #include <stdlib.h>
00035 #include <ctype.h>
00036 #include <stdio.h>
00037
00038 #include "misc_support.h"
00039 #include "field.h"
00040 #include "utils.h"
00041
00042 using namespace dami;
00043
00044 char *ID3_GetString(const ID3_Frame *frame, ID3_FieldID fldName)
00045 {
00046 char *text = NULL;
00047 if (NULL != frame)
00048 {
00049 ID3_Field* fld = frame->GetField(fldName);
00050 ID3_TextEnc enc = fld->GetEncoding();
00051 fld->SetEncoding(ID3TE_ASCII);
00052 size_t nText = fld->Size();
00053 text = new char[nText + 1];
00054 fld->Get(text, nText + 1);
00055 fld->SetEncoding(enc);
00056 }
00057 return text;
00058 }
00059
00060 char *ID3_GetString(const ID3_Frame *frame, ID3_FieldID fldName, size_t nIndex)
00061 {
00062 char *text = NULL;
00063 if (NULL != frame)
00064 {
00065 size_t nText = frame->GetField(fldName)->Size();
00066 text = new char[nText + 1];
00067 frame->GetField(fldName)->Get(text, nText + 1, nIndex);
00068 }
00069 return text;
00070 }
00071
00072 void ID3_FreeString(char *str)
00073 {
00074 if(str != NULL)
00075 delete [] str;
00076 }
00077
00078 char *ID3_GetArtist(const ID3_Tag *tag)
00079 {
00080 char *sArtist = NULL;
00081 if (NULL == tag)
00082 {
00083 return sArtist;
00084 }
00085
00086 ID3_Frame *frame = NULL;
00087 if ((frame = tag->Find(ID3FID_LEADARTIST)) ||
00088 (frame = tag->Find(ID3FID_BAND)) ||
00089 (frame = tag->Find(ID3FID_CONDUCTOR)) ||
00090 (frame = tag->Find(ID3FID_COMPOSER)))
00091 {
00092 sArtist = ID3_GetString(frame, ID3FN_TEXT);
00093 }
00094 return sArtist;
00095 }
00096
00097 ID3_Frame* ID3_AddArtist(ID3_Tag *tag, const char *text, bool replace)
00098 {
00099 ID3_Frame* frame = NULL;
00100 if (NULL != tag && NULL != text && strlen(text) > 0)
00101 {
00102 if (replace)
00103 {
00104 ID3_RemoveArtists(tag);
00105 }
00106 if (replace ||
00107 (tag->Find(ID3FID_LEADARTIST) == NULL &&
00108 tag->Find(ID3FID_BAND) == NULL &&
00109 tag->Find(ID3FID_CONDUCTOR) == NULL &&
00110 tag->Find(ID3FID_COMPOSER) == NULL))
00111 {
00112 frame = new ID3_Frame(ID3FID_LEADARTIST);
00113 if (frame)
00114 {
00115 frame->GetField(ID3FN_TEXT)->Set(text);
00116 tag->AttachFrame(frame);
00117 }
00118 }
00119 }
00120
00121 return frame;
00122 }
00123
00124 size_t ID3_RemoveArtists(ID3_Tag *tag)
00125 {
00126 size_t num_removed = 0;
00127 ID3_Frame *frame = NULL;
00128
00129 if (NULL == tag)
00130 {
00131 return num_removed;
00132 }
00133
00134 while ((frame = tag->Find(ID3FID_LEADARTIST)))
00135 {
00136 frame = tag->RemoveFrame(frame);
00137 delete frame;
00138 num_removed++;
00139 }
00140 while ((frame = tag->Find(ID3FID_BAND)))
00141 {
00142 frame = tag->RemoveFrame(frame);
00143 delete frame;
00144 num_removed++;
00145 }
00146 while ((frame = tag->Find(ID3FID_CONDUCTOR)))
00147 {
00148 frame = tag->RemoveFrame(frame);
00149 delete frame;
00150 num_removed++;
00151 }
00152 while ((frame = tag->Find(ID3FID_COMPOSER)))
00153 {
00154 frame = tag->RemoveFrame(frame);
00155 delete frame;
00156 num_removed++;
00157 }
00158
00159 return num_removed;
00160 }
00161
00162 char *ID3_GetAlbum(const ID3_Tag *tag)
00163 {
00164 char *sAlbum = NULL;
00165 if (NULL == tag)
00166 {
00167 return sAlbum;
00168 }
00169
00170 ID3_Frame *frame = tag->Find(ID3FID_ALBUM);
00171 if (frame != NULL)
00172 {
00173 sAlbum = ID3_GetString(frame, ID3FN_TEXT);
00174 }
00175 return sAlbum;
00176 }
00177
00178 ID3_Frame* ID3_AddAlbum(ID3_Tag *tag, const char *text, bool replace)
00179 {
00180 ID3_Frame* frame = NULL;
00181 if (NULL != tag && NULL != text && strlen(text) > 0)
00182 {
00183 if (replace)
00184 {
00185 ID3_RemoveAlbums(tag);
00186 }
00187 if (replace || tag->Find(ID3FID_ALBUM) == NULL)
00188 {
00189 frame = new ID3_Frame(ID3FID_ALBUM);
00190 if (frame)
00191 {
00192 frame->GetField(ID3FN_TEXT)->Set(text);
00193 tag->AttachFrame(frame);
00194 }
00195 }
00196 }
00197
00198 return frame;
00199 }
00200
00201 size_t ID3_RemoveAlbums(ID3_Tag *tag)
00202 {
00203 size_t num_removed = 0;
00204 ID3_Frame *frame = NULL;
00205
00206 if (NULL == tag)
00207 {
00208 return num_removed;
00209 }
00210
00211 while ((frame = tag->Find(ID3FID_ALBUM)))
00212 {
00213 frame = tag->RemoveFrame(frame);
00214 delete frame;
00215 num_removed++;
00216 }
00217
00218 return num_removed;
00219 }
00220
00221 char *ID3_GetTitle(const ID3_Tag *tag)
00222 {
00223 char *sTitle = NULL;
00224 if (NULL == tag)
00225 {
00226 return sTitle;
00227 }
00228
00229 ID3_Frame *frame = tag->Find(ID3FID_TITLE);
00230 if (frame != NULL)
00231 {
00232 sTitle = ID3_GetString(frame, ID3FN_TEXT);
00233 }
00234 return sTitle;
00235 }
00236
00237 ID3_Frame* ID3_AddTitle(ID3_Tag *tag, const char *text, bool replace)
00238 {
00239 ID3_Frame* frame = NULL;
00240 if (NULL != tag && NULL != text && strlen(text) > 0)
00241 {
00242 if (replace)
00243 {
00244 ID3_RemoveTitles(tag);
00245 }
00246 if (replace || tag->Find(ID3FID_TITLE) == NULL)
00247 {
00248 frame = new ID3_Frame(ID3FID_TITLE);
00249 if (frame)
00250 {
00251 frame->GetField(ID3FN_TEXT)->Set(text);
00252 tag->AttachFrame(frame);
00253 }
00254 }
00255 }
00256
00257 return frame;
00258 }
00259
00260 size_t ID3_RemoveTitles(ID3_Tag *tag)
00261 {
00262 size_t num_removed = 0;
00263 ID3_Frame *frame = NULL;
00264
00265 if (NULL == tag)
00266 {
00267 return num_removed;
00268 }
00269
00270 while ((frame = tag->Find(ID3FID_TITLE)))
00271 {
00272 frame = tag->RemoveFrame(frame);
00273 delete frame;
00274 num_removed++;
00275 }
00276
00277 return num_removed;
00278 }
00279
00280 char *ID3_GetYear(const ID3_Tag *tag)
00281 {
00282 char *sYear = NULL;
00283 if (NULL == tag)
00284 {
00285 return sYear;
00286 }
00287
00288 ID3_Frame *frame = tag->Find(ID3FID_YEAR);
00289 if (frame != NULL)
00290 {
00291 sYear = ID3_GetString(frame, ID3FN_TEXT);
00292 }
00293 return sYear;
00294 }
00295
00296 ID3_Frame* ID3_AddYear(ID3_Tag *tag, const char *text, bool replace)
00297 {
00298 ID3_Frame* frame = NULL;
00299 if (NULL != tag && NULL != text && strlen(text) > 0)
00300 {
00301 if (replace)
00302 {
00303 ID3_RemoveYears(tag);
00304 }
00305 if (replace || tag->Find(ID3FID_YEAR) == NULL)
00306 {
00307 frame = new ID3_Frame(ID3FID_YEAR);
00308 if (NULL != frame)
00309 {
00310 frame->GetField(ID3FN_TEXT)->Set(text);
00311 tag->AttachFrame(frame);
00312 }
00313 }
00314 }
00315
00316 return frame;
00317 }
00318
00319 size_t ID3_RemoveYears(ID3_Tag *tag)
00320 {
00321 size_t num_removed = 0;
00322 ID3_Frame *frame = NULL;
00323
00324 if (NULL == tag)
00325 {
00326 return num_removed;
00327 }
00328
00329 while ((frame = tag->Find(ID3FID_YEAR)))
00330 {
00331 frame = tag->RemoveFrame(frame);
00332 delete frame;
00333 num_removed++;
00334 }
00335
00336 return num_removed;
00337 }
00338
00339 char *ID3_GetComment(const ID3_Tag *tag, const char* desc)
00340 {
00341 char *comment = NULL;
00342 if (NULL == tag)
00343 {
00344 return comment;
00345 }
00346
00347 ID3_Frame* frame = NULL;
00348 if (desc)
00349 {
00350 frame = tag->Find(ID3FID_COMMENT, ID3FN_DESCRIPTION, desc);
00351 }
00352 else
00353 {
00354 frame = tag->Find(ID3FID_COMMENT);
00355 }
00356
00357 if (frame)
00358 {
00359 comment = ID3_GetString(frame, ID3FN_TEXT);
00360 }
00361 return comment;
00362 }
00363
00364 ID3_Frame* ID3_AddComment(ID3_Tag *tag, const char *text, bool replace)
00365 {
00366 return ID3_AddComment(tag, text, "", replace);
00367 }
00368
00369 ID3_Frame* ID3_AddComment(ID3_Tag *tag, const char *text,
00370 const char *desc, bool replace)
00371 {
00372 return ID3_AddComment(tag, text, desc, "XXX", replace);
00373 }
00374
00375 ID3_Frame* ID3_AddComment(ID3_Tag *tag, const char *text,
00376 const char *desc, const char* lang, bool replace)
00377 {
00378 ID3_Frame* frame = NULL;
00379 if (NULL != tag &&
00380 NULL != text &&
00381 NULL != desc &&
00382 strlen(text) > 0)
00383 {
00384 bool bAdd = true;
00385 if (replace)
00386 {
00387 ID3_RemoveComments(tag, desc);
00388 }
00389 else
00390 {
00391
00392 ID3_Tag::Iterator* iter = tag->CreateIterator();
00393 ID3_Frame* frame = NULL;
00394 while ((frame = iter->GetNext()) != NULL)
00395 {
00396 if (frame->GetID() == ID3FID_COMMENT)
00397 {
00398 char *tmp_desc = ID3_GetString(frame, ID3FN_DESCRIPTION);
00399 if (strcmp(tmp_desc, desc) == 0)
00400 {
00401 bAdd = false;
00402 }
00403 delete [] tmp_desc;
00404 if (!bAdd)
00405 {
00406 break;
00407 }
00408 }
00409 }
00410 delete iter;
00411 }
00412 if (bAdd)
00413 {
00414 frame = new ID3_Frame(ID3FID_COMMENT);
00415 if (NULL != frame)
00416 {
00417 frame->GetField(ID3FN_LANGUAGE)->Set(lang);
00418 frame->GetField(ID3FN_DESCRIPTION)->Set(desc);
00419 frame->GetField(ID3FN_TEXT)->Set(text);
00420 tag->AttachFrame(frame);
00421 }
00422 }
00423 }
00424 return frame;
00425 }
00426
00427
00428
00429 size_t ID3_RemoveComments(ID3_Tag *tag, const char *desc)
00430 {
00431 size_t num_removed = 0;
00432
00433 if (NULL == tag)
00434 {
00435 return num_removed;
00436 }
00437
00438 ID3_Tag::Iterator* iter = tag->CreateIterator();
00439 ID3_Frame* frame = NULL;
00440 while ((frame = iter->GetNext()) != NULL)
00441 {
00442 if (frame->GetID() == ID3FID_COMMENT)
00443 {
00444 bool remove = false;
00445
00446 if (NULL == desc)
00447 {
00448 remove = true;
00449 }
00450 else
00451 {
00452
00453
00454 char *tmp_desc = ID3_GetString(frame, ID3FN_DESCRIPTION);
00455 remove = (strcmp(tmp_desc, desc) == 0);
00456 delete [] tmp_desc;
00457 }
00458 if (remove)
00459 {
00460 frame = tag->RemoveFrame(frame);
00461 delete frame;
00462 num_removed++;
00463 }
00464 }
00465 }
00466 delete iter;
00467
00468 return num_removed;
00469 }
00470
00471 char *ID3_GetTrack(const ID3_Tag *tag)
00472 {
00473 char *sTrack = NULL;
00474 if (NULL == tag)
00475 {
00476 return sTrack;
00477 }
00478
00479 ID3_Frame *frame = tag->Find(ID3FID_TRACKNUM);
00480 if (frame != NULL)
00481 {
00482 sTrack = ID3_GetString(frame, ID3FN_TEXT);
00483 }
00484 return sTrack;
00485 }
00486
00487 size_t ID3_GetTrackNum(const ID3_Tag *tag)
00488 {
00489 char *sTrack = ID3_GetTrack(tag);
00490 size_t nTrack = 0;
00491 if (NULL != sTrack)
00492 {
00493 nTrack = atoi(sTrack);
00494 delete [] sTrack;
00495 }
00496 return nTrack;
00497 }
00498
00499 ID3_Frame* ID3_AddTrack(ID3_Tag *tag, uchar trk, uchar ttl, bool replace)
00500 {
00501 ID3_Frame* frame = NULL;
00502 if (NULL != tag && trk > 0)
00503 {
00504 if (replace)
00505 {
00506 ID3_RemoveTracks(tag);
00507 }
00508 if (replace || NULL == tag->Find(ID3FID_TRACKNUM))
00509 {
00510 frame = new ID3_Frame(ID3FID_TRACKNUM);
00511 if (frame)
00512 {
00513 char *sTrack = NULL;
00514 if (0 == ttl)
00515 {
00516 sTrack = new char[4];
00517 sprintf(sTrack, "%lu", (luint) trk);
00518 }
00519 else
00520 {
00521 sTrack = new char[8];
00522 sprintf(sTrack, "%lu/%lu", (luint) trk, (luint) ttl);
00523 }
00524
00525 frame->GetField(ID3FN_TEXT)->Set(sTrack);
00526 tag->AttachFrame(frame);
00527
00528 delete [] sTrack;
00529 }
00530 }
00531 }
00532
00533 return frame;
00534 }
00535
00536 size_t ID3_RemoveTracks(ID3_Tag *tag)
00537 {
00538 size_t num_removed = 0;
00539 ID3_Frame *frame = NULL;
00540
00541 if (NULL == tag)
00542 {
00543 return num_removed;
00544 }
00545
00546 while ((frame = tag->Find(ID3FID_TRACKNUM)))
00547 {
00548 frame = tag->RemoveFrame(frame);
00549 delete frame;
00550 num_removed++;
00551 }
00552
00553 return num_removed;
00554 }
00555
00556 char *ID3_GetGenre(const ID3_Tag *tag)
00557 {
00558 char *sGenre = NULL;
00559 if (NULL == tag)
00560 {
00561 return sGenre;
00562 }
00563
00564 ID3_Frame *frame = tag->Find(ID3FID_CONTENTTYPE);
00565 if (frame != NULL)
00566 {
00567 sGenre = ID3_GetString(frame, ID3FN_TEXT);
00568 }
00569
00570 return sGenre;
00571 }
00572
00573 size_t ID3_GetGenreNum(const ID3_Tag *tag)
00574 {
00575 char *sGenre = ID3_GetGenre(tag);
00576 size_t ulGenre = 0xFF;
00577 if (NULL == sGenre)
00578 {
00579 return ulGenre;
00580 }
00581
00582
00583
00584 if (sGenre[0] == '(')
00585 {
00586 char *pCur = &sGenre[1];
00587 while (isdigit(*pCur))
00588 {
00589 pCur++;
00590 }
00591 if (*pCur == ')')
00592 {
00593
00594 ulGenre = dami::min(0xFF, atoi(&sGenre[1]));
00595 }
00596 }
00597
00598 delete [] sGenre;
00599 return ulGenre;
00600 }
00601
00602 ID3_Frame* ID3_AddGenre(ID3_Tag *tag, size_t genre, bool replace)
00603 {
00604 ID3_Frame* frame = NULL;
00605 if (NULL != tag && 0xFF != genre)
00606 {
00607 if (replace)
00608 {
00609 ID3_RemoveGenres(tag);
00610 }
00611 if (replace || NULL == tag->Find(ID3FID_CONTENTTYPE))
00612 {
00613 frame = new ID3_Frame(ID3FID_CONTENTTYPE);
00614 if (NULL != frame)
00615 {
00616 char sGenre[6];
00617 sprintf(sGenre, "(%lu)", (luint) genre);
00618
00619 frame->GetField(ID3FN_TEXT)->Set(sGenre);
00620 tag->AttachFrame(frame);
00621 }
00622 }
00623 }
00624
00625 return frame;
00626 }
00627
00628 size_t ID3_RemoveGenres(ID3_Tag *tag)
00629 {
00630 size_t num_removed = 0;
00631 ID3_Frame *frame = NULL;
00632
00633 if (NULL == tag)
00634 {
00635 return num_removed;
00636 }
00637
00638 while ((frame = tag->Find(ID3FID_CONTENTTYPE)))
00639 {
00640 frame = tag->RemoveFrame(frame);
00641 delete frame;
00642 num_removed++;
00643 }
00644
00645 return num_removed;
00646 }
00647
00648 char *ID3_GetLyrics(const ID3_Tag *tag)
00649 {
00650 char *sLyrics = NULL;
00651 if (NULL == tag)
00652 {
00653 return sLyrics;
00654 }
00655
00656 ID3_Frame *frame = tag->Find(ID3FID_UNSYNCEDLYRICS);
00657 if (frame != NULL)
00658 {
00659 sLyrics = ID3_GetString(frame, ID3FN_TEXT);
00660 }
00661 return sLyrics;
00662 }
00663
00664 ID3_Frame* ID3_AddLyrics(ID3_Tag *tag, const char *text, bool replace)
00665 {
00666 return ID3_AddLyrics(tag, text, "", replace);
00667 }
00668
00669 ID3_Frame* ID3_AddLyrics(ID3_Tag *tag, const char *text, const char* desc,
00670 bool replace)
00671 {
00672 return ID3_AddLyrics(tag, text, desc, "XXX", replace);
00673 }
00674
00675 ID3_Frame* ID3_AddLyrics(ID3_Tag *tag, const char *text, const char* desc,
00676 const char* lang, bool replace)
00677 {
00678 ID3_Frame* frame = NULL;
00679 if (NULL != tag && strlen(text) > 0)
00680 {
00681 if (replace)
00682 {
00683 ID3_RemoveLyrics(tag);
00684 }
00685 if (replace || tag->Find(ID3FID_UNSYNCEDLYRICS) == NULL)
00686 {
00687 frame = new ID3_Frame(ID3FID_UNSYNCEDLYRICS);
00688 if (NULL != frame)
00689 {
00690 frame->GetField(ID3FN_LANGUAGE)->Set(lang);
00691 frame->GetField(ID3FN_DESCRIPTION)->Set(desc);
00692 frame->GetField(ID3FN_TEXT)->Set(text);
00693 tag->AttachFrame(frame);
00694 }
00695 }
00696 }
00697
00698 return frame;
00699 }
00700
00701 size_t ID3_RemoveLyrics(ID3_Tag *tag)
00702 {
00703 size_t num_removed = 0;
00704 ID3_Frame *frame = NULL;
00705
00706 if (NULL == tag)
00707 {
00708 return num_removed;
00709 }
00710
00711 while ((frame = tag->Find(ID3FID_UNSYNCEDLYRICS)))
00712 {
00713 frame = tag->RemoveFrame(frame);
00714 delete frame;
00715 num_removed++;
00716 }
00717
00718 return num_removed;
00719 }
00720
00721 char *ID3_GetLyricist(const ID3_Tag *tag)
00722 {
00723 char *sLyricist = NULL;
00724 if (NULL == tag)
00725 {
00726 return sLyricist;
00727 }
00728
00729 ID3_Frame *frame = tag->Find(ID3FID_LYRICIST);
00730 if (frame != NULL)
00731 {
00732 sLyricist = ID3_GetString(frame, ID3FN_TEXT);
00733 }
00734 return sLyricist;
00735 }
00736
00737 ID3_Frame* ID3_AddLyricist(ID3_Tag *tag, const char *text, bool replace)
00738 {
00739 ID3_Frame* frame = NULL;
00740 if (NULL != tag && NULL != text && strlen(text) > 0)
00741 {
00742 if (replace)
00743 {
00744 ID3_RemoveLyricist(tag);
00745 }
00746 if (replace || (tag->Find(ID3FID_LYRICIST) == NULL))
00747 {
00748 frame = new ID3_Frame(ID3FID_LYRICIST);
00749 if (frame)
00750 {
00751 frame->GetField(ID3FN_TEXT)->Set(text);
00752 tag->AttachFrame(frame);
00753 }
00754 }
00755 }
00756
00757 return frame;
00758 }
00759
00760 size_t ID3_RemoveLyricist(ID3_Tag *tag)
00761 {
00762 size_t num_removed = 0;
00763 ID3_Frame *frame = NULL;
00764
00765 if (NULL == tag)
00766 {
00767 return num_removed;
00768 }
00769
00770 while ((frame = tag->Find(ID3FID_LYRICIST)))
00771 {
00772 frame = tag->RemoveFrame(frame);
00773 delete frame;
00774 num_removed++;
00775 }
00776
00777 return num_removed;
00778 }
00779
00780 ID3_Frame* ID3_AddSyncLyrics(ID3_Tag *tag, const uchar *data, size_t datasize,
00781 ID3_TimeStampFormat format, bool replace)
00782 {
00783 return ID3_AddSyncLyrics(tag, data, datasize, format, "", replace);
00784 }
00785
00786 ID3_Frame* ID3_AddSyncLyrics(ID3_Tag *tag, const uchar *data, size_t datasize,
00787 ID3_TimeStampFormat format, const char *desc,
00788 bool replace)
00789 {
00790 return ID3_AddSyncLyrics(tag, data, datasize, format, desc, "XXX", replace);
00791 }
00792
00793 ID3_Frame* ID3_AddSyncLyrics(ID3_Tag *tag, const uchar *data, size_t datasize,
00794 ID3_TimeStampFormat format, const char *desc,
00795 const char *lang, bool replace)
00796 {
00797 return ID3_AddSyncLyrics(tag, data, datasize, format, desc, lang,
00798 ID3CT_LYRICS, replace);
00799 }
00800
00801 ID3_Frame* ID3_AddSyncLyrics(ID3_Tag *tag, const uchar *data, size_t datasize,
00802 ID3_TimeStampFormat format, const char *desc,
00803 const char *lang, ID3_ContentType type,
00804 bool replace)
00805 {
00806 ID3_Frame* frame = NULL;
00807
00808 if ((NULL == lang) || (NULL == desc))
00809 {
00810 return NULL;
00811 }
00812
00813
00814 ID3_Frame* frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, lang);
00815 if (!frmExist)
00816 {
00817 frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, desc);
00818 }
00819
00820 if (NULL != tag && NULL != data)
00821 {
00822 if (replace && frmExist)
00823 {
00824 frmExist = tag->RemoveFrame (frmExist);
00825 delete frmExist;
00826 frmExist = NULL;
00827 }
00828
00829
00830 if (frmExist)
00831 {
00832 return NULL;
00833 }
00834
00835 ID3_Frame* frame = new ID3_Frame(ID3FID_SYNCEDLYRICS);
00836
00837 frame->GetField(ID3FN_LANGUAGE)->Set(lang);
00838 frame->GetField(ID3FN_DESCRIPTION)->Set(desc);
00839 frame->GetField(ID3FN_TIMESTAMPFORMAT)->Set(format);
00840 frame->GetField(ID3FN_CONTENTTYPE)->Set(type);
00841 frame->GetField(ID3FN_DATA)->Set(data, datasize);
00842 tag->AttachFrame(frame);
00843 }
00844
00845 return frame;
00846 }
00847
00848 ID3_Frame *ID3_GetSyncLyricsInfo(const ID3_Tag *tag, const char *desc,
00849 const char *lang,
00850 ID3_TimeStampFormat& format,
00851 ID3_ContentType& type, size_t& size)
00852 {
00853
00854 ID3_Frame* frmExist = NULL;
00855 if (NULL != lang)
00856 {
00857
00858 frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, lang);
00859 }
00860 else if (NULL != desc)
00861 {
00862
00863 frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, desc);
00864 }
00865 else
00866 {
00867
00868 frmExist = tag->Find(ID3FID_SYNCEDLYRICS);
00869 }
00870
00871 if (!frmExist)
00872 {
00873 return NULL;
00874 }
00875
00876
00877 format = static_cast<ID3_TimeStampFormat>(frmExist->GetField(ID3FN_TIMESTAMPFORMAT)->Get ());
00878
00879
00880 type = static_cast<ID3_ContentType>(frmExist->GetField(ID3FN_CONTENTTYPE)->Get ());
00881
00882
00883 size = frmExist->GetField (ID3FN_DATA)->Size ();
00884
00885
00886 return frmExist;
00887 }
00888
00889 ID3_Frame *ID3_GetSyncLyrics(const ID3_Tag *tag, const char *lang,
00890 const char *desc, const uchar *pData, size_t& size)
00891 {
00892
00893 ID3_Frame* frmExist = NULL;
00894 if (NULL != lang)
00895 {
00896
00897 frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_LANGUAGE, lang);
00898 }
00899 else if (NULL != desc)
00900 {
00901
00902 frmExist = tag->Find(ID3FID_SYNCEDLYRICS, ID3FN_DESCRIPTION, desc);
00903 }
00904 else
00905 {
00906
00907 frmExist = tag->Find(ID3FID_SYNCEDLYRICS);
00908 }
00909
00910 if (NULL == frmExist)
00911 {
00912 return NULL;
00913 }
00914
00915
00916 size = dami::min(size, frmExist->GetField(ID3FN_DATA)->Size());
00917
00918
00919 pData = frmExist->GetField (ID3FN_DATA)->GetRawBinary();
00920
00921
00922 return frmExist;
00923 }
00924