Ejemplo n.º 1
0
ID3_Frame* ID3_AddComment(ID3_Tag *tag, const char *text,
                          const char *desc, const char* lang, bool replace)
{
  ID3_Frame* frame = NULL;
  if (NULL != tag  &&
      NULL != text &&
      NULL != desc &&
      strlen(text) > 0)
  {
    bool bAdd = true;
    if (replace)
    {
      ID3_RemoveComments(tag, desc);
    }
    else
    {
      // See if there is already a comment with this description
      ID3_Tag::Iterator* iter = tag->CreateIterator();
      ID3_Frame* frame = NULL;
      while ((frame = iter->GetNext()) != NULL)
      {
        if (frame->GetID() == ID3FID_COMMENT)
        {
          char *tmp_desc = ID3_GetString(frame, ID3FN_DESCRIPTION);
          if (strcmp(tmp_desc, desc) == 0)
          {
            bAdd = false;
          }
          delete [] tmp_desc;
          if (!bAdd)
          {
            break;
          }
        }
      }
      delete iter;
    }
    if (bAdd)
    {
      frame = new ID3_Frame(ID3FID_COMMENT);
      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;
}
Ejemplo n.º 2
0
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;
}