return METADATA_EDITOR_ERROR_NONE;
}
-static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, char **value)
+static int __get_ID3_tag(metadata_editor_attr_e attribute, ID3v1::Tag *tag1, ID3v2::Tag *tag2, char **value)
{
- int ret = METADATA_EDITOR_ERROR_NONE;
-
- ret = __check_metadata_get_parameter(metadata, value);
- metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret);
-
- // Bring the pointer to actual file type and make tag pointers
- auto _file = dynamic_cast<MPEG::File*>(metadata->file);
- auto tag1 = _file->ID3v1Tag();
- auto tag2 = _file->ID3v2Tag();
-
- switch (attribute) { // Check which one of frame types was given to the function for processing
+ switch (attribute) {
case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getTwixFrameByName(tag1, tag2, "TPE1", value);
case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(tag1, tag2, "TIT2", value);
case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(tag1, tag2, "TALB", value);
}
}
+static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, char **value)
+{
+ int ret = METADATA_EDITOR_ERROR_NONE;
+
+ ret = __check_metadata_get_parameter(metadata, value);
+ metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret);
+
+ auto _file = dynamic_cast<MPEG::File*>(metadata->file);
+ metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast");
+
+ return __get_ID3_tag(attribute, _file->ID3v1Tag(), _file->ID3v2Tag(), value);
+}
+
static int __metadata_editor_get_mp4_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, char **value)
{
int ret = METADATA_EDITOR_ERROR_NONE;
return METADATA_EDITOR_ERROR_OPERATION_FAILED;
}
- switch (attribute) { // Check which one of frame types was given to the function for processing
- case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getTwixFrameByName(NULL, tag2, "TPE1", value);
- case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(NULL, tag2, "TIT2", value);
- case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(NULL, tag2, "TALB", value);
- case METADATA_EDITOR_ATTR_GENRE: return __ID3_getTwixFrameByName(NULL, tag2, "TCON", value);
- case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getTwixFrameByName(NULL, tag2, "TCOM", value);
- case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getTwixFrameByName(NULL, tag2, "TCOP", value);
- case METADATA_EDITOR_ATTR_DATE: return __ID3_getTwixFrameByName(NULL, tag2, "TDRC", value);
- case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getTwixFrameByName(NULL, tag2, "TIT3", value);
- case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getTwixFrameByName(NULL, tag2, "COMM", value);
- case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(NULL, tag2, "TRCK", value);
- case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getTwixFrameByName(NULL, tag2, "TPE3", value);
- case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(tag2, value);
- case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(tag2, value);
- default:
- metadata_editor_error("Invalid attribute [%d]", attribute);
- return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
- }
+ return __get_ID3_tag(attribute, NULL, tag2, value);
}
#endif
}
}
-static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, const char *value)
+static int __set_ID3_tag(metadata_editor_attr_e attribute, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *value)
{
- int ret = METADATA_EDITOR_ERROR_NONE;
-
- ret = __check_metadata_set_parameter(metadata);
- metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret);
-
- // Bring the pointer to actual file type and make tags pointers
- auto _file = (MPEG::File*)metadata->file;
- auto tag1 = _file->ID3v1Tag();
- auto tag2 = _file->ID3v2Tag(true);
-
- metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
+ metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
- switch (attribute) { // Check which one of frame type was given for processing
+ switch (attribute) {
case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(tag1, tag2, "TPE1", value);
case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(tag1, tag2, "TIT2", value);
case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(tag1, tag2, "TALB", value);
metadata_editor_error("Invalid attribute [%d]", attribute);
return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
}
+
+ return METADATA_EDITOR_ERROR_NONE;
+}
+
+static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, const char *value)
+{
+ int ret = METADATA_EDITOR_ERROR_NONE;
+
+ ret = __check_metadata_set_parameter(metadata);
+ metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret);
+
+ auto _file = dynamic_cast<MPEG::File*>(metadata->file);
+ metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast");
+
+ return __set_ID3_tag(attribute, _file->ID3v1Tag(), _file->ID3v2Tag(true), value);
}
static int __metadata_editor_set_mp4_metadata(metadata_editor_s *metadata, metadata_editor_attr_e attribute, const char *value)
ret = __check_metadata_set_parameter(metadata);
metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret);
- // Bring the pointer to actual file type and make tags pointers
- auto _file = (RIFF::WAV::File*)metadata->file;
- auto tag2 = _file->tag();
- // Check if the valid tag pointer exist
- if (!tag2) {
- metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating");
- return METADATA_EDITOR_ERROR_OPERATION_FAILED;
- }
+ auto _file = dynamic_cast<RIFF::WAV::File*>(metadata->file);
+ metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast");
- switch (attribute) { // Check which one of frame type was given for processing
- case METADATA_EDITOR_ATTR_ARTIST: return __ID3v2_setFrameByName(tag2, "TPE1", value);
- case METADATA_EDITOR_ATTR_TITLE: return __ID3v2_setFrameByName(tag2, "TIT2", value);
- case METADATA_EDITOR_ATTR_ALBUM: return __ID3v2_setFrameByName(tag2, "TALB", value);
- case METADATA_EDITOR_ATTR_GENRE: return __ID3v2_setFrameByName(tag2, "TCON", value);
- case METADATA_EDITOR_ATTR_AUTHOR: return __ID3v2_setFrameByName(tag2, "TCOM", value);
- case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3v2_setFrameByName(tag2, "TCOP", value);
- case METADATA_EDITOR_ATTR_DATE: return __ID3v2_setFrameByName(tag2, "TDRC", value);
- case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3v2_setFrameByName(tag2, "TIT3", value);
- case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3v2_setFrameByName(tag2, "TRCK", value);
- case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3v2_setFrameByName(tag2, "TPE3", value);
- case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(NULL, tag2, value);
- case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(tag2, value);
- default:
- metadata_editor_error("Invalid attribute [%d]", attribute);
- return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
- }
+ return __set_ID3_tag(attribute, NULL, _file->tag(), value);
}
#endif