From: hj kim Date: Mon, 11 May 2020 06:57:33 +0000 (+0900) Subject: Bug fix of getting number of pictures. it should return '0' if there is no picture. X-Git-Tag: submit/tizen/20200602.021203~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F232993%2F7;p=platform%2Fcore%2Fapi%2Fmetadata-editor.git Bug fix of getting number of pictures. it should return '0' if there is no picture. Change-Id: Ia43d59c27ccc176edba963f31f0940fba7ffb6b7 --- diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 28bbe59..29b4010 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -30,7 +30,6 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value); static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value); static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value); -static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value); static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value); static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value); static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value); @@ -38,11 +37,9 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value); static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value); static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value); -static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value); #if 0 static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value); static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value); -static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value); #endif typedef enum { METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ @@ -303,23 +300,16 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag return METADATA_EDITOR_ERROR_NONE; } -// *** This function is used to receive the number of pictures stored in ID3v2 tag of file *** // -static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) { +static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::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"); - TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // link to picture frames in tag - // Check if the frames exist - metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_NONE, "No pictures in file"); + *value = g_strdup_printf("%u", tag2->frameListMap()["APIC"].size()); - metadata_editor_info("APIC frames exist in file"); - char buf[META_MAX_BUF_LEN] = {0, }; - // Convert the number of frames (lst.size()) to c-string - snprintf(buf, META_MAX_BUF_LEN, "%u", lst.size()); - *value = strndup(buf, strlen(buf)); return METADATA_EDITOR_ERROR_NONE; } @@ -547,30 +537,19 @@ static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* ite } } -// *** This function is used to find the number of pictures stored in MP4 file *** // -static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { +static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, 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); - TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; - TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); + auto tag = dynamic_cast(_metadata->file->tag()); + 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 - TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); - TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); - if (it != itemMap.end()) { // Item was found - char buf[META_MAX_BUF_LEN] = {0, }; - snprintf(buf, META_MAX_BUF_LEN, "%u", it->second.toCoverArtList().size()); // Convert integer value of size to its c-string representation - if (strlen(buf) > 0) - *value = g_strdup(buf); - return METADATA_EDITOR_ERROR_NONE; - } else { // Item was not found - metadata_editor_info("No item in file"); - return METADATA_EDITOR_ERROR_NONE; - } + *value = g_strdup_printf("%u", tag->contains("covr") ? tag->item("covr").toCoverArtList().size() : 0); + + return METADATA_EDITOR_ERROR_NONE; } #if 0 // *** This function is used to extract string from Xiph Comment field *** // @@ -624,25 +603,17 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi return METADATA_EDITOR_ERROR_NONE; } -// *** This function is used to receive the number of pictures in FLAC file *** // -static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { +static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, 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); TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; - if (_file->pictureList().isEmpty()) { - metadata_editor_info("No pictures in FLAC file"); - return METADATA_EDITOR_ERROR_NONE; - } - uint number = _file->pictureList().size(); - metadata_editor_info("There are %u picture(s) in file", number); - char buf[META_MAX_BUF_LEN] = {0, }; - snprintf(buf, META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation - uint length = strlen(buf); - metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string"); - *value = strndup(buf, length); + + *value = g_strdup_printf("%u", _file->pictureList().size()); + return METADATA_EDITOR_ERROR_NONE; } #endif @@ -1411,15 +1382,12 @@ static int __get_APIC(TagLib::ID3v2::Tag* tag, int index, void **picture, int *s static int __get_mp3_picture(metadata_editor_s* metadata, int index, void **picture, int *size, char **mime_type) { - TagLib::MPEG::File* _file = (TagLib::MPEG::File*)metadata->file; - - return __get_APIC(_file->ID3v2Tag(), index, picture, size, mime_type); + return __get_APIC(dynamic_cast(metadata->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) { - TagLib::MP4::File* _file = (TagLib::MP4::File*) metadata->file; - TagLib::MP4::Tag* tag = _file->tag(); + auto tag = dynamic_cast(metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist");