return METADATA_EDITOR_ERROR_NONE;
}
-static int __ID3v2_setFrameByName(ID3v2::Tag *tag2, const char *frameID, const char *value)
+static void __ID3v1_setFrameByName(ID3v1::Tag *tag1, const char *frameID, const char *value)
{
- metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
- metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID");
+ metadata_editor_retm_if(!tag1, "[No-Error] No ID3v1 tag to update"); //ID3v1 is optional
+ metadata_editor_retm_if(tag1->isEmpty(), "[No-Error] ID3v1 tag is empty");
- // If the pointer is NULL or c-string is empty - handle as request for deletion
if (!value || (*value == '\0')) {
metadata_editor_info("Request for frame %s deletion", frameID);
- tag2->removeFrames(frameID);
- return METADATA_EDITOR_ERROR_NONE;
- }
- // Check if the ID3v2 tag exists
- if (tag2->frameListMap()[frameID].isEmpty()) {
- metadata_editor_info("The frame %s does not exist. Creating", frameID);
- // This is a common frame type for textural frames except comment frame
- auto fr = new ID3v2::TextIdentificationFrame(frameID);
+ if (!strcmp(frameID, "TPE1"))
+ tag1->setArtist("");
+ else if (!strcmp(frameID, "TALB"))
+ tag1->setAlbum("");
+ else if (!strcmp(frameID, "TCON"))
+ tag1->setGenre("");
+ else if (!strcmp(frameID, "TIT2"))
+ tag1->setTitle("");
+ else if (!strcmp(frameID, "TRCK"))
+ tag1->setTrack(0);
+ else if (!strcmp(frameID, "TDRC"))
+ tag1->setYear(0);
- fr->setTextEncoding(String::UTF8);
- fr->setText(String(value, String::UTF8));
- tag2->addFrame(fr);
- } else { // if not - just modify the data in the existing frame
- metadata_editor_info("The frame %s exists. Changing", frameID);
- tag2->frameListMap()[frameID][0]->setText(String(value, String::UTF8));
+ return;
}
- return METADATA_EDITOR_ERROR_NONE;
+ if (!strcmp(frameID, "TPE1"))
+ tag1->setArtist(value);
+ else if (!strcmp(frameID, "TALB"))
+ tag1->setAlbum(value);
+ else if (!strcmp(frameID, "TCON")) // Genre in ID3v1 is enumeration, so can not write it with "value"
+ tag1->setGenre("");
+ else if (!strcmp(frameID, "TIT2"))
+ tag1->setTitle(value);
+ else if (!strcmp(frameID, "TRCK"))
+ tag1->setTrack(atoi(value));
+ else if (!strcmp(frameID, "TDRC"))
+ tag1->setYear(atoi(value));
+
+ return;
}
-static int __ID3_setTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, const char *value)
+static int __ID3v2_setFrameByName(ID3v2::Tag *tag2, const char *frameID, const char *value)
{
- metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID");
metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
+ metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID");
// If the pointer is NULL or c-string is empty - handle as request for deletion
if (!value || (*value == '\0')) {
metadata_editor_info("Request for frame %s deletion", frameID);
tag2->removeFrames(frameID);
- if (tag1 && !tag1->isEmpty()) {
- if (!strcmp(frameID, "TPE1"))
- tag1->setArtist("");
- else if (!strcmp(frameID, "TALB"))
- tag1->setAlbum("");
- else if (!strcmp(frameID, "TCON"))
- tag1->setGenre("");
- else if (!strcmp(frameID, "TIT2"))
- tag1->setTitle("");
- else if (!strcmp(frameID, "TRCK"))
- tag1->setTrack(0);
- else if (!strcmp(frameID, "TDRC"))
- tag1->setYear(0);
- }
-
return METADATA_EDITOR_ERROR_NONE;
}
- // Check if the frame is empty (must create the frame before writing the data)
+ // Check if the ID3v2 tag exists
if (tag2->frameListMap()[frameID].isEmpty()) {
metadata_editor_info("The frame %s does not exist. Creating", frameID);
// This is a common frame type for textural frames except comment frame
tag2->frameListMap()[frameID][0]->setText(String(value, String::UTF8));
}
- if (tag1 && !tag1->isEmpty()) { // Check if ID3v1 tag exists. Must copy data if yes.
- metadata_editor_info("ID3v1 tag also exists. Copying frame");
- if (!strcmp(frameID, "TPE1"))
- tag1->setArtist(value);
- else if (!strcmp(frameID, "TALB"))
- tag1->setAlbum(value);
- else if (!strcmp(frameID, "TCON")) // Genre in ID3v1 is enumeration, so can not write it with "value"
- tag1->setGenre("");
- else if (!strcmp(frameID, "TIT2"))
- tag1->setTitle(value);
- else if (!strcmp(frameID, "TRCK"))
- tag1->setTrack(atoi(value));
- else if (!strcmp(frameID, "TDRC"))
- tag1->setYear(atoi(value));
- }
-
return METADATA_EDITOR_ERROR_NONE;
}
+static int __ID3_setTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, const char *value)
+{
+ metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID");
+ if (tag1 && !(tag1->isEmpty()))
+ __ID3v1_setFrameByName(tag1, frameID, value);
+
+ return __ID3v2_setFrameByName(tag2, frameID, value);
+}
+
static int __ID3_getFrameByName(ID3v2::Tag *tag2, const char *frameID, char **value)
{
metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID");