From 07afb39a2b3655e0a445d4c839a8df35e135a9af Mon Sep 17 00:00:00 2001 From: hj kim Date: Wed, 20 May 2020 17:00:33 +0900 Subject: [PATCH 01/16] Fix invalid return of metadata_editor_append_picture() and adds debug logs. metadata_editor_set_path() can return METADATA_EDITOR_ERROR_NOT_SUPPORTED for not supported file, but other APIs should return METADATA_EDITOR_ERROR_INVALID_PARAMETER Change-Id: I13abc82156a0c0b98867ac9078563bc18198cbea --- src/metadata_editor.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 58d5fb9..219aaeb 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -716,7 +716,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * #endif default: - metadata_editor_error("Wrong file type"); + metadata_editor_error("Not supported file type [%d]", media_type); return METADATA_EDITOR_ERROR_NOT_SUPPORTED; } } catch (const std::bad_alloc &ex) { @@ -762,6 +762,7 @@ static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(metadata, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(metadata, tag2, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -788,6 +789,7 @@ static int __metadata_editor_get_mp4_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_getStringItem(metadata, "\xA9""lyr", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __MP4_getNumberOfPictures(metadata, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -823,6 +825,7 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(metadata, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -856,6 +859,7 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -889,6 +893,7 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -925,6 +930,7 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(metadata, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(metadata, tag2, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -958,7 +964,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata #endif default: - metadata_editor_error("Wrong file type [%d]", _metadata->filetype); + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -991,6 +997,7 @@ static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(metadata, tag1, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(metadata, tag2, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1016,6 +1023,7 @@ static int __metadata_editor_set_mp4_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_updateStringItem(metadata, "cond", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_updateStringItem(metadata, "\xA9""lyr", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1049,6 +1057,7 @@ static int __metadata_editor_set_flac_metadata(metadata_editor_s *metadata, meta case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1081,6 +1090,7 @@ static int __metadata_editor_set_ogg_vorbis_metadata(metadata_editor_s *metadata case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1113,6 +1123,7 @@ static int __metadata_editor_set_ogg_flac_metadata(metadata_editor_s *metadata, case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1147,6 +1158,7 @@ static int __metadata_editor_set_wav_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(metadata, NULL, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(metadata, tag2, value); default: + metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1180,7 +1192,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata #endif default: - metadata_editor_error("Wrong file type"); + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1223,7 +1235,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) } default: - metadata_editor_error("Wrong file type"); + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1375,7 +1387,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index return __get_wav_picture(_metadata, index, picture, size, mime_type); #endif default: - metadata_editor_error("Wrong file type"); + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1482,8 +1494,8 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const break; #endif default: { - metadata_editor_error("Wrong file type"); - ret = METADATA_EDITOR_ERROR_NOT_SUPPORTED; + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); + ret = METADATA_EDITOR_ERROR_INVALID_PARAMETER; break; } } @@ -1594,7 +1606,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in return __remove_wav_picture(_metadata, index); #endif default: - metadata_editor_error("Wrong file type"); + metadata_editor_error("Invalid file type [%d]", _metadata->filetype); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } -- 2.7.4 From 4f7cbca21afc05e71b1c63d0397535ea4981cead Mon Sep 17 00:00:00 2001 From: hj kim Date: Wed, 20 May 2020 18:45:16 +0900 Subject: [PATCH 02/16] check NULL before getting metadata toString() returns "", when String is NULL Change-Id: I8a8b1da78a4747725bdf6bc8a59e6b2277bd084e --- src/metadata_editor.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 219aaeb..10e8343 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -117,15 +117,17 @@ static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *ta metadata_editor_info("Reading data from ID3v1 tag"); - if (!strcmp(frameID, "TPE1")) /* artist */ + //check isNull(). toCString() returns "", when String is NULL. + //for "genre", taglib returns "", if genre is out or range. + if (!strcmp(frameID, "TPE1") && !(tag1->artist().isNull())) /* artist */ *value = g_strdup(tag1->artist().toCString(true)); - else if (!strcmp(frameID, "TALB")) /* album */ + else if (!strcmp(frameID, "TALB") && !(tag1->album().isNull())) /* album */ *value = g_strdup(tag1->album().toCString(true)); - else if (!strcmp(frameID, "COMM")) /* comment */ + else if (!strcmp(frameID, "COMM") && !(tag1->comment().isNull())) /* comment */ *value = g_strdup(tag1->comment().toCString(true)); - else if (!strcmp(frameID, "TCON")) /* genre */ + else if (!strcmp(frameID, "TCON") && !(tag1->genre().isNull()) && !(tag1->genre().isEmpty())) /* genre */ *value = g_strdup(tag1->genre().toCString(true)); - else if (!strcmp(frameID, "TIT2")) /* title */ + else if (!strcmp(frameID, "TIT2") && !(tag1->title().isNull())) /* title */ *value = g_strdup(tag1->title().toCString(true)); else if (!strcmp(frameID, "TRCK")) /* track */ *value = g_strdup_printf("%u", tag1->track()); @@ -278,7 +280,8 @@ static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, auto it = lst.begin(); auto frame = static_cast(*it); - *value = g_strdup(frame->text().toCString(true)); + if (!(frame->text().isNull())) + *value = g_strdup(frame->text().toCString(true)); return METADATA_EDITOR_ERROR_NONE; } -- 2.7.4 From 6ab63ff3293bcf00dc4c07e82b721ee6b4869156 Mon Sep 17 00:00:00 2001 From: hj kim Date: Thu, 21 May 2020 13:01:32 +0900 Subject: [PATCH 03/16] Bug fix of MP4 metadata when using auto keyword Change-Id: I9aac227c38061475c2ed07e15c073682428239f4 --- src/metadata_editor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 10e8343..da684d0 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -369,7 +369,7 @@ static int __MP4_getStringItem(metadata_editor_s *_metadata, const char *itemnam auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - auto itemMap = tag->itemListMap(); + auto &itemMap = tag->itemListMap(); auto it = itemMap.find(itemname); if (it != itemMap.end()) @@ -391,7 +391,7 @@ static int __MP4_getIntegerItem(metadata_editor_s *_metadata, const char *itemna auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - auto itemMap = tag->itemListMap(); + auto &itemMap = tag->itemListMap(); auto it = itemMap.find(itemname); if (it != itemMap.end()) *value = g_strdup_printf("%u", it->second.toInt()); @@ -413,7 +413,7 @@ static int __MP4_updateStringItem(metadata_editor_s *_metadata, const char *item metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); // Get map of items directly from tag and launch a search of specific item - auto itemMap = tag->itemListMap(); + auto &itemMap = tag->itemListMap(); // Check if it is a request for deletion if ((value == NULL) || value[0] == '\0') { metadata_editor_info("Request for deleting of item <%s>", itemname); @@ -440,7 +440,7 @@ static int __MP4_updateIntegerItem(metadata_editor_s *_metadata, const char *ite metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); // Get map of items directly from tag and launch a search of specific item - auto itemMap = tag->itemListMap(); + auto &itemMap = tag->itemListMap(); // Check if it is a request for deletion if ((value == NULL) || value[0] == '\0') { metadata_editor_info("Request for deleting of item <%s>", itemname); @@ -486,7 +486,7 @@ static int __xiph_getFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment * metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - auto fieldMap = xtag->fieldListMap(); + auto &fieldMap = xtag->fieldListMap(); auto it = fieldMap.find(fieldname); if ((xtag->contains(fieldname)) && (it != fieldMap.end())) -- 2.7.4 From bb27b4d8153a3cb91996bf884d3c3602942e273a Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 25 May 2020 15:24:08 +0900 Subject: [PATCH 04/16] Remove unnecessary parameter Change-Id: Ie1d7fc71dbb4fee4b49e0c0b0e0ac0043aa00f1e --- src/metadata_editor.cpp | 308 +++++++++++++++++++++--------------------------- 1 file changed, 134 insertions(+), 174 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index da684d0..576a400 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -94,12 +94,8 @@ static int __check_metadata_get_parameter(metadata_editor_s *metadata, char **va return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, char **value) +static int __ID3_getTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, 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); metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID"); if (tag2 && !(tag2->frameListMap()[frameID].isEmpty())) { @@ -139,12 +135,8 @@ static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *ta return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_setTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, const char *value) +static int __ID3_setTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, 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); 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"); @@ -203,12 +195,8 @@ static int __ID3_setTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *ta return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *frameID, char **value) +static int __ID3_getFrameByName(ID3v2::Tag *tag2, const char *frameID, 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); metadata_editor_retvm_if(!frameID, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid frameID"); metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame %s does not exist", frameID); @@ -219,12 +207,8 @@ static int __ID3_getFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_setFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *frameID, const char *value) +static int __ID3_setFrameByName(ID3v2::Tag *tag2, const char *frameID, 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); 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"); @@ -252,12 +236,8 @@ static int __ID3_setFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getNumberOfPictures(metadata_editor_s *_metadata, ID3v2::Tag *tag2, char **value) +static int __ID3_getNumberOfPictures(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); metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); *value = g_strdup_printf("%u", tag2->frameListMap()["APIC"].size()); @@ -265,12 +245,8 @@ static int __ID3_getNumberOfPictures(metadata_editor_s *_metadata, ID3v2::Tag *t return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, char **value) +static int __ID3_getLyricsFrame(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); metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); auto lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag @@ -286,12 +262,8 @@ static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *value) +static int __ID3_setTwixCommentFrame(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); metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion @@ -323,12 +295,8 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, ID3v1::Tag *t return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_setLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *value) +static int __ID3_setLyricsFrame(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); metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); auto lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag @@ -477,14 +445,10 @@ static int __MP4_getNumberOfPictures(metadata_editor_s *_metadata, char **value) } #if 0 -static int __xiph_getFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment *xtag, const char *fieldname, char **value) +static int __xiph_getFieldValue(Ogg::XiphComment *xtag, const char *fieldname, 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); - metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); auto &fieldMap = xtag->fieldListMap(); auto it = fieldMap.find(fieldname); @@ -497,14 +461,10 @@ static int __xiph_getFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment * return METADATA_EDITOR_ERROR_NONE; } -static int __xiph_updateFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment *xtag, const char *fieldname, const char *value) +static int __xiph_updateFieldValue(Ogg::XiphComment *xtag, const char *fieldname, 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); - metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); // Check if it is a request for deletion if ((value == NULL) || value[0] == '\0') { @@ -751,19 +711,19 @@ static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metad auto tag2 = _file->ID3v2Tag(); switch (attribute) { // Check which one of frame types was given to the function for processing - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "COMM", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(metadata, tag1, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(metadata, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(metadata, tag2, value); + 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); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_getTwixFrameByName(tag1, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_getTwixFrameByName(tag1, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getTwixFrameByName(tag1, tag2, "COMM", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(tag1, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(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; @@ -814,18 +774,18 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta 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 __xiph_getFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(xtag, "LYRICS", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(metadata, value); default: metadata_editor_error("Invalid attribute [%d]", attribute); @@ -849,18 +809,18 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata 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 __xiph_getFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(xtag, "LYRICS", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -883,18 +843,18 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, 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 __xiph_getFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(xtag, "LYRICS", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -919,19 +879,19 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad } switch (attribute) { // Check which one of frame types was given to the function for processing - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getFrameByName(metadata, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_getFrameByName(metadata, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getFrameByName(metadata, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_getFrameByName(metadata, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_getFrameByName(metadata, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getFrameByName(metadata, tag2, "COMM", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getFrameByName(metadata, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(metadata, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(metadata, tag2, value); + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getFrameByName(tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_getFrameByName(tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getFrameByName(tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_getFrameByName(tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_getFrameByName(tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getFrameByName(tag2, "COMM", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getFrameByName(tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(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; @@ -987,18 +947,18 @@ static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metad metadata_editor_retvm_if(tag2 == NULL, 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 - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(metadata, tag1, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(metadata, tag1, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(metadata, tag2, value); + 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); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(tag1, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setTwixFrameByName(tag1, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(tag1, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(tag1, 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; @@ -1047,18 +1007,18 @@ static int __metadata_editor_set_flac_metadata(metadata_editor_s *metadata, meta return METADATA_EDITOR_ERROR_OPERATION_FAILED; } switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(xtag, "LYRICS", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -1080,18 +1040,18 @@ static int __metadata_editor_set_ogg_vorbis_metadata(metadata_editor_s *metadata return METADATA_EDITOR_ERROR_OPERATION_FAILED; } switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(xtag, "LYRICS", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -1113,18 +1073,18 @@ static int __metadata_editor_set_ogg_flac_metadata(metadata_editor_s *metadata, return METADATA_EDITOR_ERROR_OPERATION_FAILED; } switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(metadata, xtag, "ARTIST", value); - case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(metadata, xtag, "TITLE", value); - case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(metadata, xtag, "ALBUM", value); - case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(metadata, xtag, "GENRE", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(metadata, xtag, "COMPOSER", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(metadata, xtag, "COPYRIGHT", value); - case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(metadata, xtag, "DATE", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(metadata, xtag, "DESCRIPTION", value); - case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(metadata, xtag, "COMMENT", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(metadata, xtag, "TRACKNUMBER", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(metadata, xtag, "CONDUCTOR", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(xtag, "LYRICS", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -1148,18 +1108,18 @@ static int __metadata_editor_set_wav_metadata(metadata_editor_s *metadata, metad } switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(metadata, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(metadata, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(metadata, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(metadata, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(metadata, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(metadata, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(metadata, NULL, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(metadata, tag2, value); + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_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; -- 2.7.4 From 9fa7126174846818b3a0d8a268b34a1e743225a3 Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 25 May 2020 15:54:10 +0900 Subject: [PATCH 05/16] Modify input parameter Use proper MP4:Tag instead of metadata_editor structure when get and set metadata. Change-Id: I2c255991ce19f65606580507c4aa188e9b119f22 --- src/metadata_editor.cpp | 114 +++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 74 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 576a400..99bc7d4 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -326,16 +326,10 @@ static int __ID3_setLyricsFrame(ID3v2::Tag *tag2, const char *value) return METADATA_EDITOR_ERROR_NONE; } -static int __MP4_getStringItem(metadata_editor_s *_metadata, const char *itemname, char **value) +static int __MP4_getStringItem(MP4::Tag *tag, const char *itemname, 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); - metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); - - auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); auto &itemMap = tag->itemListMap(); auto it = itemMap.find(itemname); @@ -348,16 +342,10 @@ static int __MP4_getStringItem(metadata_editor_s *_metadata, const char *itemnam return METADATA_EDITOR_ERROR_NONE; } -static int __MP4_getIntegerItem(metadata_editor_s *_metadata, const char *itemname, char **value) +static int __MP4_getIntegerItem(MP4::Tag *tag, const char *itemname, 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); - metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); - - auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); auto &itemMap = tag->itemListMap(); auto it = itemMap.find(itemname); @@ -369,16 +357,10 @@ static int __MP4_getIntegerItem(metadata_editor_s *_metadata, const char *itemna return METADATA_EDITOR_ERROR_NONE; } -static int __MP4_updateStringItem(metadata_editor_s *_metadata, const char *itemname, const char *value) +static int __MP4_updateStringItem(MP4::Tag *tag, const char *itemname, 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); - metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); - - auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); // Get map of items directly from tag and launch a search of specific item auto &itemMap = tag->itemListMap(); @@ -396,16 +378,10 @@ static int __MP4_updateStringItem(metadata_editor_s *_metadata, const char *item return METADATA_EDITOR_ERROR_NONE; } -static int __MP4_updateIntegerItem(metadata_editor_s *_metadata, const char *itemname, const char *value) +static int __MP4_updateIntegerItem(MP4::Tag *tag, const char *itemname, 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); - metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); - - auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); // Get map of items directly from tag and launch a search of specific item auto &itemMap = tag->itemListMap(); @@ -429,14 +405,8 @@ static int __MP4_updateIntegerItem(metadata_editor_s *_metadata, const char *ite } } -static int __MP4_getNumberOfPictures(metadata_editor_s *_metadata, char **value) +static int __MP4_getNumberOfPictures(MP4::Tag *tag, 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 tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); *value = g_strdup_printf("%u", tag->contains("covr") ? tag->item("covr").toCoverArtList().size() : 0); @@ -478,16 +448,12 @@ static int __xiph_updateFieldValue(Ogg::XiphComment *xtag, const char *fieldname return METADATA_EDITOR_ERROR_NONE; } -static int __FLAC_getNumberOfPictures(metadata_editor_s *_metadata, char **value) +static int __FLAC_getNumberOfPictures(FLAC::File *file, 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(_metadata->file); - - *value = g_strdup_printf("%u", _file->pictureList().size()); + if (file) + *value = g_strdup_printf("%u", file->pictureList().size()); + else + *value = g_strdup("0"); return METADATA_EDITOR_ERROR_NONE; } @@ -738,19 +704,19 @@ static int __metadata_editor_get_mp4_metadata(metadata_editor_s *metadata, metad metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_get_parameter() [%d]", ret); switch (attribute) { // Check which one of frame types was given to the function for processing - case METADATA_EDITOR_ATTR_ARTIST: return __MP4_getStringItem(metadata, "\xA9""ART", value); - case METADATA_EDITOR_ATTR_TITLE: return __MP4_getStringItem(metadata, "\xA9""nam", value); - case METADATA_EDITOR_ATTR_ALBUM: return __MP4_getStringItem(metadata, "\xA9""alb", value); - case METADATA_EDITOR_ATTR_GENRE: return __MP4_getStringItem(metadata, "\xA9""gen", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_getStringItem(metadata, "\xA9""wrt", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_getStringItem(metadata, "cprt", value); - case METADATA_EDITOR_ATTR_DATE: return __MP4_getStringItem(metadata, "\xA9""day", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_getStringItem(metadata, "desc", value); - case METADATA_EDITOR_ATTR_COMMENT: return __MP4_getStringItem(metadata, "\xA9""cmt", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_getIntegerItem(metadata, "trkn", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_getStringItem(metadata, "cond", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_getStringItem(metadata, "\xA9""lyr", value); - case METADATA_EDITOR_ATTR_PICTURE_NUM: return __MP4_getNumberOfPictures(metadata, value); + case METADATA_EDITOR_ATTR_ARTIST: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""ART", value); + case METADATA_EDITOR_ATTR_TITLE: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""nam", value); + case METADATA_EDITOR_ATTR_ALBUM: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""alb", value); + case METADATA_EDITOR_ATTR_GENRE: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""gen", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""wrt", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "cprt", value); + case METADATA_EDITOR_ATTR_DATE: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""day", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "desc", value); + case METADATA_EDITOR_ATTR_COMMENT: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""cmt", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_getIntegerItem(dynamic_cast(metadata->file->tag()), "trkn", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "cond", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_getStringItem(dynamic_cast(metadata->file->tag()), "\xA9""lyr", value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __MP4_getNumberOfPictures(dynamic_cast(metadata->file->tag()), value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -786,7 +752,7 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(xtag, "TRACKNUMBER", value); case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(xtag, "LYRICS", value); - case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(metadata, value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(_file, value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; @@ -973,18 +939,18 @@ static int __metadata_editor_set_mp4_metadata(metadata_editor_s *metadata, metad metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret); switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __MP4_updateStringItem(metadata, "\xA9""ART", value); - case METADATA_EDITOR_ATTR_TITLE: return __MP4_updateStringItem(metadata, "\xA9""nam", value); - case METADATA_EDITOR_ATTR_ALBUM: return __MP4_updateStringItem(metadata, "\xA9""alb", value); - case METADATA_EDITOR_ATTR_GENRE: return __MP4_updateStringItem(metadata, "\xA9""gen", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_updateStringItem(metadata, "\xA9""wrt", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_updateStringItem(metadata, "cprt", value); - case METADATA_EDITOR_ATTR_DATE: return __MP4_updateStringItem(metadata, "\xA9""day", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_updateStringItem(metadata, "desc", value); - case METADATA_EDITOR_ATTR_COMMENT: return __MP4_updateStringItem(metadata, "\xA9""cmt", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_updateIntegerItem(metadata, "trkn", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_updateStringItem(metadata, "cond", value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_updateStringItem(metadata, "\xA9""lyr", value); + case METADATA_EDITOR_ATTR_ARTIST: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""ART", value); + case METADATA_EDITOR_ATTR_TITLE: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""nam", value); + case METADATA_EDITOR_ATTR_ALBUM: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""alb", value); + case METADATA_EDITOR_ATTR_GENRE: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""gen", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""wrt", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "cprt", value); + case METADATA_EDITOR_ATTR_DATE: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""day", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "desc", value); + case METADATA_EDITOR_ATTR_COMMENT: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""cmt", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_updateIntegerItem(dynamic_cast(metadata->file->tag()), "trkn", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "cond", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_updateStringItem(dynamic_cast(metadata->file->tag()), "\xA9""lyr", value); default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; -- 2.7.4 From 8400780f013a7fe0b00dfccd88b680a0a1420f36 Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 25 May 2020 16:16:35 +0900 Subject: [PATCH 06/16] Bug fix of getting number of picture in tag if there is no tag, number should be "0". Change-Id: I6b048dac7ad51a1eba273de62593c0851fcbcf70 --- src/metadata_editor.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 99bc7d4..95ce276 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -238,9 +238,9 @@ static int __ID3_setFrameByName(ID3v2::Tag *tag2, const char *frameID, const cha static int __ID3_getNumberOfPictures(ID3v2::Tag *tag2, char **value) { - metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); + metadata_editor_retvm_if(!value, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid value"); - *value = g_strdup_printf("%u", tag2->frameListMap()["APIC"].size()); + *value = g_strdup_printf("%u", tag2 ? tag2->frameListMap()["APIC"].size() : 0); return METADATA_EDITOR_ERROR_NONE; } @@ -407,9 +407,12 @@ static int __MP4_updateIntegerItem(MP4::Tag *tag, const char *itemname, const ch static int __MP4_getNumberOfPictures(MP4::Tag *tag, char **value) { - metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!value, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid value"); - *value = g_strdup_printf("%u", tag->contains("covr") ? tag->item("covr").toCoverArtList().size() : 0); + if (tag && tag->contains("covr")) + *value = g_strdup_printf("%u", tag->item("covr").toCoverArtList().size()); + else + *value = g_strdup_printf("0"); return METADATA_EDITOR_ERROR_NONE; } @@ -720,7 +723,7 @@ static int __metadata_editor_get_mp4_metadata(metadata_editor_s *metadata, metad default: metadata_editor_error("Invalid attribute [%d]", attribute); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; -} + } } #if 0 -- 2.7.4 From 91d5be5a3469a64b0918de430b434ecc12c81b37 Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 25 May 2020 16:35:15 +0900 Subject: [PATCH 07/16] Revise the internal function name __ID3_setFrameByName() to __ID3v2_setFrameByName() because __ID3_setFrameByName() is used only for ID3v2 tag. Change-Id: I4bf870b5cdd1d9713101d594f7ff126e2ce03878 --- src/metadata_editor.cpp | 86 ++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 95ce276..a383d53 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -135,6 +135,35 @@ static int __ID3_getTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const ch return METADATA_EDITOR_ERROR_NONE; } +static int __ID3v2_setFrameByName(ID3v2::Tag *tag2, 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"); + + // 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); + + 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 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"); @@ -207,35 +236,6 @@ static int __ID3_getFrameByName(ID3v2::Tag *tag2, const char *frameID, char **va return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_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"); - - // 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); - - 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 METADATA_EDITOR_ERROR_NONE; -} - static int __ID3_getNumberOfPictures(ID3v2::Tag *tag2, char **value) { metadata_editor_retvm_if(!value, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid value"); @@ -920,12 +920,12 @@ static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(tag1, tag2, "TIT2", value); case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(tag1, tag2, "TALB", value); case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(tag1, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(tag2, "TCOP", 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 __ID3_setTwixFrameByName(tag1, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3v2_setFrameByName(tag2, "TIT3", value); case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(tag1, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3v2_setFrameByName(tag2, "TPE3", value); case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(tag1, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(tag2, value); default: @@ -1077,16 +1077,16 @@ static int __metadata_editor_set_wav_metadata(metadata_editor_s *metadata, metad } switch (attribute) { // Check which one of frame type was given for processing - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(tag2, "TPE3", value); + 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: -- 2.7.4 From 53256cbefa7f338c38439bf82c5ba8eb9a226ab8 Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 26 May 2020 16:34:27 +0900 Subject: [PATCH 08/16] Add macros for debugging and add debug logs Change-Id: I5dcd0b80f26b57d4a297898a413be863daf8062f --- include/metadata_editor_private.h | 11 +++++++++++ src/metadata_editor.cpp | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h index 9a96ed3..8d7eb1d 100755 --- a/include/metadata_editor_private.h +++ b/include/metadata_editor_private.h @@ -49,6 +49,10 @@ extern "C" { LOGD(""); \ } while (0) +#define metadata_editor_sec_debug(fmt, arg...) do { \ + SECURE_LOGD("" fmt "", ##arg); \ + } while (0) + #define metadata_editor_retvm_if(expr, val, fmt, arg...) do { \ if (expr) { \ LOGE("" fmt "", ##arg); \ @@ -56,6 +60,13 @@ extern "C" { } \ } while (0) +#define metadata_editor_retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + LOGE("" fmt "", ##arg); \ + return; \ + } \ + } while (0) + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index a383d53..74304c6 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -598,6 +598,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * metadata_editor_retvm_if(!_metadata, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid metadata"); metadata_editor_retvm_if(!path, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid path"); + metadata_editor_sec_debug("path : [%s]", path); + if (access(path, R_OK) < 0) { if (errno == EACCES || errno == EPERM) { metadata_editor_error("Permission denied"); @@ -618,6 +620,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; } + metadata_editor_debug("media_type : [%d]", media_type); + try { switch (media_type) { case METADATA_EDITOR_FORMAT_MP3: -- 2.7.4 From 0c7bb0e2516ebd2f718d792be8686bcbbaa6704c Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 25 May 2020 17:57:11 +0900 Subject: [PATCH 09/16] Improve __ID3_setTwixFrameByName() API Change-Id: Ib82b0d175e528718ec89e840f546937c1bd3a55a --- src/metadata_editor.cpp | 95 ++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 74304c6..7bf2748 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -135,63 +135,59 @@ static int __ID3_getTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const ch 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 @@ -205,25 +201,18 @@ static int __ID3_setTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const ch 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"); -- 2.7.4 From 1262021dc332a866e6f1f0877e9c4a2fcf974981 Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 26 May 2020 17:22:51 +0900 Subject: [PATCH 10/16] Unify Code for getting ID3tag to __ID3_getTwixFrameByName() Change-Id: I3dde3b8339f68e74ae5e69ca204497b3e0d6ac88 --- src/metadata_editor.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 7bf2748..93d79a4 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -213,18 +213,6 @@ static int __ID3_setTwixFrameByName(ID3v1::Tag *tag1, ID3v2::Tag *tag2, const ch 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"); - metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame %s does not exist", frameID); - - metadata_editor_info("The frame %s exists", frameID); - - *value = g_strdup(tag2->frameListMap()[frameID][0]->toString().toCString(true)); - - return METADATA_EDITOR_ERROR_NONE; -} - static int __ID3_getNumberOfPictures(ID3v2::Tag *tag2, char **value) { metadata_editor_retvm_if(!value, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid value"); @@ -677,13 +665,13 @@ static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metad case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(tag1, tag2, "TIT2", value); case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(tag1, tag2, "TALB", value); case METADATA_EDITOR_ATTR_GENRE: return __ID3_getTwixFrameByName(tag1, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(tag2, "TCOP", 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(tag1, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getTwixFrameByName(NULL, tag2, "TIT3", value); case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getTwixFrameByName(tag1, tag2, "COMM", value); case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(tag1, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(tag2, "TPE3", 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: @@ -841,17 +829,17 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad } switch (attribute) { // Check which one of frame types was given to the function for processing - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getFrameByName(tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_getFrameByName(tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getFrameByName(tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_getFrameByName(tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_getFrameByName(tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getFrameByName(tag2, "COMM", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getFrameByName(tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(tag2, "TPE3", value); + 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: -- 2.7.4 From 17c5e9eba32112c7670792d28bcfbe9caa05765a Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 26 May 2020 17:02:40 +0900 Subject: [PATCH 11/16] Unify Getting and Setting metadata related code for MP3 and Wav MP3 and Wav could have metadata in ID3tag. but Wav only can save metadata in ID3v2. Change-Id: I4da4d7cec1a94222d2bcf11f3d688e8c4a32ff79 --- src/metadata_editor.cpp | 105 +++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 68 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 93d79a4..69b798c 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -648,19 +648,9 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * 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(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); @@ -680,6 +670,19 @@ static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metad } } +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(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; @@ -828,24 +831,7 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad 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 @@ -882,21 +868,11 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata } } -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); @@ -913,6 +889,21 @@ static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metad 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(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) @@ -1048,32 +1039,10 @@ static int __metadata_editor_set_wav_metadata(metadata_editor_s *metadata, metad 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(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 -- 2.7.4 From a8978a36b53d21f0cc84e4a27b09e9527c600ed0 Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 29 May 2020 14:14:32 +0900 Subject: [PATCH 12/16] Check dynamic_cast result before using it Change-Id: I6b32ee6ce5e9202194dfe47add16a493ee442fa3 --- src/metadata_editor.cpp | 58 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 69b798c..90af341 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -718,8 +718,9 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta 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 tags pointers - auto _file = (FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->xiphComment(false); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -753,8 +754,9 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata 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 tags pointers - auto _file = (Ogg::Vorbis::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -787,8 +789,9 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, 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 tags pointers - auto _file = (Ogg::FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); @@ -821,10 +824,10 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad 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 = (RIFF::WAV::File*)metadata->file; - auto tag2 = _file->tag(); + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto tag2 = _file->tag(); if (tag2 == NULL) { // Check if we have a valid tag for processing metadata_editor_error("Error. ID3v2 tag does not exist. Can not proceed metadata extraction"); *value = NULL; @@ -940,8 +943,9 @@ static int __metadata_editor_set_flac_metadata(metadata_editor_s *metadata, meta 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 = (FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->xiphComment(true); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -973,8 +977,9 @@ static int __metadata_editor_set_ogg_vorbis_metadata(metadata_editor_s *metadata 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 = (Ogg::Vorbis::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -1006,8 +1011,9 @@ static int __metadata_editor_set_ogg_flac_metadata(metadata_editor_s *metadata, 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 = (Ogg::FLAC::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating"); @@ -1089,7 +1095,9 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: { - auto _file = (MPEG::File*)_metadata->file; + auto _file = dynamic_cast(_metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto tag1 = _file->ID3v1Tag(); if (!tag1 || tag1->isEmpty()) { // If no ID3v1 tag - prevent its creation @@ -1174,7 +1182,10 @@ static int __get_APIC(ID3v2::Tag *tag, int index, void **picture, int *size, cha static int __get_mp3_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - return __get_APIC(dynamic_cast(metadata->file)->ID3v2Tag(), index, picture, size, mime_type); + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + + return __get_APIC(_file->ID3v2Tag(), index, picture, size, mime_type); } static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) @@ -1210,7 +1221,9 @@ static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **pict #if 0 static int __get_flac_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - auto _file = (FLAC::File*) metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto lst = _file->pictureList(); if (lst.isEmpty()) { @@ -1238,7 +1251,8 @@ static int __get_flac_picture(metadata_editor_s *metadata, int index, void **pic static int __get_wav_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { - auto _file = (RIFF::WAV::File*)metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); return __get_APIC(_file->tag(), index, picture, size, mime_type); } @@ -1322,7 +1336,9 @@ static int __append_mp4_picture(metadata_editor_s *metadata, const char *picture #if 0 static int __append_flac_picture(metadata_editor_s *metadata, const char *picture, size_t size, const char *mime_type) { - auto _file = (FLAC::File*) metadata->file; + auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto frontCover = new FLAC::Picture; metadata_editor_debug_fenter(); @@ -1441,6 +1457,8 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) static int __remove_flac_picture(metadata_editor_s *metadata, int index) { auto _file = dynamic_cast(metadata->file); + metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); + auto lst = _file->pictureList(); if (lst.isEmpty()) { -- 2.7.4 From ef448de9418e466b0ba1fb787f6e43b046012424 Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 1 Jun 2020 15:36:28 +0900 Subject: [PATCH 13/16] Check file validity before using it Change-Id: Id39a29a9a7042af3bb2e23c3cd10edad4d022ff0 --- src/metadata_editor.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 90af341..4d8efdc 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -566,13 +566,8 @@ extern "C" int metadata_editor_create(metadata_editor_h *metadata) return METADATA_EDITOR_ERROR_NONE; } -extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) +static int __check_file_validity(const char *path) { - int media_type = METADATA_EDITOR_FORMAT_NOTYPE; - metadata_editor_s *_metadata = (metadata_editor_s*)metadata; - File *_file = NULL; - - metadata_editor_retvm_if(!_metadata, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid metadata"); metadata_editor_retvm_if(!path, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid path"); metadata_editor_sec_debug("path : [%s]", path); @@ -587,6 +582,21 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } } + return METADATA_EDITOR_ERROR_NONE; +} + +extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) +{ + int ret = METADATA_EDITOR_ERROR_NONE; + int media_type = METADATA_EDITOR_FORMAT_NOTYPE; + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + File *_file = NULL; + + metadata_editor_retvm_if(!_metadata, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid metadata"); + + ret = __check_file_validity(path); + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "Invalid path"); + media_type = __metadata_editor_get_file_type(path); if (_metadata->file) { @@ -1370,8 +1380,11 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "fail to __check_metadata_set_parameter() [%d]", ret); metadata_editor_retvm_if(!path, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid path"); + ret = __check_file_validity(path); + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "Invalid path"); + ret = __metadata_editor_get_picture_info(path, &picture, &size, &mime_type); - metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it"); //FixMe!. It should return proper error! + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it"); switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: -- 2.7.4 From 28d7b48990465cd3be88cb2292675dfe4cb7d26d Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 1 Jun 2020 16:01:11 +0900 Subject: [PATCH 14/16] Fix Wrong return values 1. return METADATA_EDITOR_ERROR_INVALID_PARAMETER if there is no tag when get or remove picture. because it means, picture index is wrong. 2. return METADATA_EDITOR_ERROR_NONE if there is no tag when get metadata. Change-Id: I831005c8b1116c421d03b7618b6503192bff3af2 --- src/metadata_editor.cpp | 52 +++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 4d8efdc..c7bda60 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -224,7 +224,7 @@ static int __ID3_getNumberOfPictures(ID3v2::Tag *tag2, char **value) static int __ID3_getLyricsFrame(ID3v2::Tag *tag2, char **value) { - metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); + metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_NONE, "[No-Error] No tag"); auto lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame USLT does not exist"); @@ -305,7 +305,7 @@ static int __ID3_setLyricsFrame(ID3v2::Tag *tag2, const char *value) static int __MP4_getStringItem(MP4::Tag *tag, const char *itemname, char **value) { - metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_NONE, "[No-Error] No tag"); metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); auto &itemMap = tag->itemListMap(); @@ -321,7 +321,7 @@ static int __MP4_getStringItem(MP4::Tag *tag, const char *itemname, char **value static int __MP4_getIntegerItem(MP4::Tag *tag, const char *itemname, char **value) { - metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_NONE, "[No-Error] No tag"); metadata_editor_retvm_if(!itemname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid itemname"); auto &itemMap = tag->itemListMap(); @@ -397,7 +397,7 @@ static int __MP4_getNumberOfPictures(MP4::Tag *tag, char **value) #if 0 static int __xiph_getFieldValue(Ogg::XiphComment *xtag, const char *fieldname, char **value) { - metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_NONE, "[No-Error] No tag"); metadata_editor_retvm_if(!fieldname, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid fieldname"); auto &fieldMap = xtag->fieldListMap(); @@ -732,11 +732,7 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); auto xtag = _file->xiphComment(false); - if (!xtag) { // Check if we have a valid tag for processing - metadata_editor_error("Tag does not exist"); - *value = NULL; - 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 __xiph_getFieldValue(xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); @@ -768,11 +764,7 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); auto xtag = _file->tag(); - if (!xtag) { // Check if we have a valid tag for processing - metadata_editor_error("Tag does not exist"); - *value = NULL; - 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 __xiph_getFieldValue(xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); @@ -803,11 +795,7 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); auto xtag = _file->tag(); - if (!xtag) { // Check if we have a valid tag for processing - metadata_editor_error("Tag does not exist"); - *value = NULL; - 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 __xiph_getFieldValue(xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(xtag, "TITLE", value); @@ -838,11 +826,7 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad metadata_editor_retvm_if(!_file, METADATA_EDITOR_ERROR_OPERATION_FAILED, "fail to dynamic_cast"); auto tag2 = _file->tag(); - if (tag2 == NULL) { // Check if we have a valid tag for processing - metadata_editor_error("Error. ID3v2 tag does not exist. Can not proceed metadata extraction"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(!tag2, METADATA_EDITOR_ERROR_NONE, "[No-Error] No tag"); return __get_ID3_tag(attribute, NULL, tag2, value); } @@ -1160,14 +1144,14 @@ static char * __get_mime_type_from_cover_art(const MP4::CoverArt& cover_art) static int __get_APIC(ID3v2::Tag *tag, int index, void **picture, int *size, char **mime_type) { - metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. No ID3v2 tag in file."); + metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Tag does not exist"); auto lst = tag->frameListMap()["APIC"]; // Check if there are pictures in the tag if (lst.isEmpty()) { metadata_editor_error("No pictures in file"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } // Check if index is correct or not @@ -1201,11 +1185,11 @@ static int __get_mp3_picture(metadata_editor_s *metadata, int index, void **pict static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **picture, int *size, char **mime_type) { auto tag = dynamic_cast(metadata->file->tag()); - metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Tag does not exist"); if (!(tag->contains("covr"))) { metadata_editor_error("No item in file. No pictures in file"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } auto lst = tag->item("covr").toCoverArtList(); @@ -1238,7 +1222,7 @@ static int __get_flac_picture(metadata_editor_s *metadata, int index, void **pic if (lst.isEmpty()) { metadata_editor_error("No pictures in FLAC file"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } // Check if the index is in range of CoverArtList Item @@ -1384,7 +1368,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "Invalid path"); ret = __metadata_editor_get_picture_info(path, &picture, &size, &mime_type); - metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it"); + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, ret, "File does not exist or you have no rights to open it"); switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: @@ -1419,10 +1403,10 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const static int __remove_APIC(ID3v2::Tag *tag, int index) { - metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); + metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Tag does not exist"); auto lst = tag->frameListMap()["APIC"]; - metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_OPERATION_FAILED, "No pictures in file"); + metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "No pictures in file"); if ((index < 0) || ((uint)index >= lst.size())) { metadata_editor_error("Index of picture is out of range"); @@ -1445,7 +1429,7 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) if (!(tag->contains("covr"))) { metadata_editor_error("No item in file. No pictures in file"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } auto lst = tag->item("covr").toCoverArtList(); @@ -1476,7 +1460,7 @@ static int __remove_flac_picture(metadata_editor_s *metadata, int index) if (lst.isEmpty()) { metadata_editor_error("No pictures in file. Nothing to delete"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } // Check if the index is in range of CoverArtList Item -- 2.7.4 From 0c4328f388fe470a45017c37e3087861be251593 Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 26 May 2020 15:35:37 +0900 Subject: [PATCH 15/16] Version up Change-Id: I8c054dadf932acfaa4347d972f36bf85c55f2792 --- packaging/capi-media-metadata-editor.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index a1b40b2..c188b36 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,6 +1,6 @@ Name: capi-media-metadata-editor Summary: A metadata editor library in Tizen Native API -Version: 0.1.8 +Version: 0.1.9 Release: 0 Group: Multimedia/API License: Apache-2.0 -- 2.7.4 From fcc9994fa7e1ddf1e996581e598434689a62154a Mon Sep 17 00:00:00 2001 From: hj kim Date: Tue, 2 Jun 2020 11:55:50 +0900 Subject: [PATCH 16/16] Reinforce description for supported formats Change-Id: If38b51e7cdeac6222f5f5e3da1fb3338318f31ba --- include/metadata_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/metadata_editor.h b/include/metadata_editor.h index 8b47b50..b8e890d 100755 --- a/include/metadata_editor.h +++ b/include/metadata_editor.h @@ -30,7 +30,7 @@ extern "C" { * @{ * * @file metadata_editor.h - * @brief This file contains the API for metadata of several popular audio formats and related structure and enumeration. \n + * @brief This file contains functions for editing metadata of MP3 and MP4 files. \n * Description of metadata: title, album, artist, author, genre and description etc. \n */ -- 2.7.4