From: hj kim Date: Wed, 13 May 2020 05:25:43 +0000 (+0900) Subject: Bug fix and improve __ID3_getTwixFrameByName() X-Git-Tag: submit/tizen/20200602.021203~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e09ee756b265412ff0448adfee31defa3cd2cd14;p=platform%2Fcore%2Fapi%2Fmetadata-editor.git Bug fix and improve __ID3_getTwixFrameByName() It's not an error situation even though there is no tag to find String::toCString(true) convert code to UTF8. and String::toCString(false) convert to Latin. We need UTF8 so "true" should be set to toCString(). Change-Id: Ifa7d94946bf5e6eee89cb87545a4b924db9be16d --- diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 726160d..3cd51fe 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -83,97 +83,50 @@ static int __check_metadata_get_parameter(metadata_editor_s *metadata, char **va return METADATA_EDITOR_ERROR_NONE; } -// *** This is an auxiliary function that is used to get the frame value *** // -// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // -static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { +static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, TagLib::ID3v1::Tag *tag1, TagLib::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"); - *value = NULL; - - // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist - if (!tag2 || tag2->frameListMap()[frameID].isEmpty()) { - metadata_editor_info("The frame %s in ID3v2 tag is empty", frameID); - // Check if the tag ID3v1 is also empty or does not exist - if (!tag1 || tag1->isEmpty()) { - metadata_editor_info("The frame %s in ID3v1 tag is empty as well", frameID); - return METADATA_EDITOR_ERROR_NONE; - } else { // if not - read the frame you need there - metadata_editor_info("Reading data from ID3v1 tag"); - - TagLib::String str; - uint length; - bool found = false; - - if (!strcmp(frameID, "TPE1")) { /* artist */ - str = tag1->artist(); - found = true; - } else if (!strcmp(frameID, "TALB")) { /* album */ - str = tag1->album(); - found = true; - } else if (!strcmp(frameID, "COMM")) { /* comment */ - str = tag1->comment(); - found = true; - } else if (!strcmp(frameID, "TCON")) { /* genre */ - str = tag1->genre(); - found = true; - } else if (!strcmp(frameID, "TIT2")) { /* title */ - str = tag1->title(); - found = true; - } - - /* Check if we have already found the frame */ - if (found) { - bool isUTF = false; - if (!str.isLatin1()) isUTF = true; - metadata_editor_info("String is %sUTF", (isUTF ? "" : "not ")); - length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string"); - *value = strndup(str.toCString(isUTF), length); - return METADATA_EDITOR_ERROR_NONE; - } - - char buf[META_MAX_BUF_LEN] = {0, }; - - if (!strcmp(frameID, "TRCK")) { /* track */ - snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->track()); - found = true; - } else if (!strcmp(frameID, "TDRC")) { /* data (year) */ - snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->year()); - found = true; - } - - if (found) { - length = strlen(buf); - metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string"); - *value = strndup(buf, length); - return METADATA_EDITOR_ERROR_NONE; - } - - /* The desired frame was not found */ - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - } else { // or frame has data to read + if (tag2 && !(tag2->frameListMap()[frameID].isEmpty())) { metadata_editor_info("The frame %s exists in ID3v2 tag", frameID); + *value = g_strdup(tag2->frameListMap()[frameID][0]->toString().toCString(true)); + return METADATA_EDITOR_ERROR_NONE; + } - // This string is used to copy the value in the frame - TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); - bool isUTF = false; - - if (!str.isLatin1()) isUTF = true; - metadata_editor_info("String is %sUTF", (isUTF ? "" : "not ")); - uint length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string"); - - *value = strndup(str.toCString(isUTF), length); + metadata_editor_info("The frame %s in ID3v2 tag is empty", frameID); + if (!tag1 || tag1->isEmpty()) { + metadata_editor_info("The frame %s in ID3v1 tag is empty as well", frameID); return METADATA_EDITOR_ERROR_NONE; } + + metadata_editor_info("Reading data from ID3v1 tag"); + + if (!strcmp(frameID, "TPE1")) /* artist */ + *value = g_strdup(tag1->artist().toCString(true)); + else if (!strcmp(frameID, "TALB")) /* album */ + *value = g_strdup(tag1->album().toCString(true)); + else if (!strcmp(frameID, "COMM")) /* comment */ + *value = g_strdup(tag1->comment().toCString(true)); + else if (!strcmp(frameID, "TCON")) /* genre */ + *value = g_strdup(tag1->genre().toCString(true)); + else if (!strcmp(frameID, "TIT2")) /* title */ + *value = g_strdup(tag1->title().toCString(true)); + else if (!strcmp(frameID, "TRCK")) /* track */ + *value = g_strdup_printf("%u", tag1->track()); + else if (!strcmp(frameID, "TDRC")) /* data (year) */ + *value = g_strdup_printf("%u", tag1->year()); + else + metadata_editor_debug("The desired frame was not found"); + + return METADATA_EDITOR_ERROR_NONE; } + // *** This is an auxiliary function that is used to write the new value to the frame *** // // *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) {