From: jiyong.min Date: Tue, 12 May 2020 23:34:34 +0000 (+0900) Subject: Use namespace TagLib X-Git-Tag: submit/tizen/20200602.021203~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F66%2F233166%2F12;p=platform%2Fcore%2Fapi%2Fmetadata-editor.git Use namespace TagLib Change-Id: I2bcd614a3aabe1c10766934658d10b0ea8936fa4 --- diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h index 3889ab9..0359416 100755 --- a/include/metadata_editor_private.h +++ b/include/metadata_editor_private.h @@ -25,25 +25,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; #ifdef __cplusplus extern "C" { @@ -82,11 +63,6 @@ extern "C" { } \ } while (0) -typedef struct { - TagLib::File* file; - int filetype; -} metadata_editor_s; - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 216c0f7..1c08288 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -23,9 +23,35 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace TagLib; + #define MIME_TYPE_JPEG "image/jpeg" #define MIME_TYPE_PNG "image/png" +typedef struct { + File* file; + int filetype; +} metadata_editor_s; + typedef enum { METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ METADATA_EDITOR_FORMAT_MP4, /**< MP4 File */ @@ -68,7 +94,7 @@ 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, TagLib::ID3v1::Tag *tag1, TagLib::ID3v2::Tag *tag2, const char *frameID, char **value) +static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, char **value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -111,7 +137,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s *_metadata, TagLib::ID3v1: return METADATA_EDITOR_ERROR_NONE; } -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_setTwixFrameByName(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *frameID, const char *value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -146,14 +172,14 @@ static int __ID3_setTwixFrameByName(metadata_editor_s *_metadata, TagLib::ID3v1: 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 TagLib::ID3v2::TextIdentificationFrame(frameID); + auto fr = new ID3v2::TextIdentificationFrame(frameID); - fr->setTextEncoding(TagLib::String::UTF8); - fr->setText(TagLib::String(value, TagLib::String::UTF8)); + 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(TagLib::String(value, TagLib::String::UTF8)); + tag2->frameListMap()[frameID][0]->setText(String(value, String::UTF8)); } if (tag1 && !tag1->isEmpty()) { // Check if ID3v1 tag exists. Must copy data if yes. @@ -175,7 +201,7 @@ static int __ID3_setTwixFrameByName(metadata_editor_s *_metadata, TagLib::ID3v1: return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getFrameByName(metadata_editor_s *_metadata, TagLib::ID3v2::Tag *tag2, const char *frameID, char **value) +static int __ID3_getFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *frameID, char **value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -191,7 +217,7 @@ static int __ID3_getFrameByName(metadata_editor_s *_metadata, TagLib::ID3v2::Tag return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_setFrameByName(metadata_editor_s *_metadata, TagLib::ID3v2::Tag *tag2, const char *frameID, const char *value) +static int __ID3_setFrameByName(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *frameID, const char *value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -211,20 +237,20 @@ static int __ID3_setFrameByName(metadata_editor_s *_metadata, TagLib::ID3v2::Tag 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 TagLib::ID3v2::TextIdentificationFrame(frameID); + auto fr = new ID3v2::TextIdentificationFrame(frameID); - fr->setTextEncoding(TagLib::String::UTF8); - fr->setText(TagLib::String(value, TagLib::String::UTF8)); + 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(TagLib::String(value, TagLib::String::UTF8)); + tag2->frameListMap()[frameID][0]->setText(String(value, String::UTF8)); } return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getNumberOfPictures(metadata_editor_s *_metadata, TagLib::ID3v2::Tag *tag2, char **value) +static int __ID3_getNumberOfPictures(metadata_editor_s *_metadata, ID3v2::Tag *tag2, char **value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -237,7 +263,7 @@ static int __ID3_getNumberOfPictures(metadata_editor_s *_metadata, TagLib::ID3v2 return METADATA_EDITOR_ERROR_NONE; } -static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, TagLib::ID3v2::Tag *tag2, char **value) +static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, char **value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -245,20 +271,19 @@ static int __ID3_getLyricsFrame(metadata_editor_s *_metadata, TagLib::ID3v2::Tag 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()["USLT"]; + ID3v2::FrameList 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"); metadata_editor_info("The frame USLT exists"); - TagLib::ID3v2::FrameList::Iterator it = lst.begin(); - auto frame = static_cast(*it); + ID3v2::FrameList::Iterator it = lst.begin(); + auto frame = static_cast(*it); *value = g_strdup(frame->text().toCString(true)); return METADATA_EDITOR_ERROR_NONE; } -// *** Comment frame is different from other string-type frames. It uses CommentsFrame instead of TextIdentificationFrame *** // -static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, TagLib::ID3v1::Tag *tag1, TagLib::ID3v2::Tag *tag2, const char *value) +static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, ID3v1::Tag *tag1, ID3v2::Tag *tag2, const char *value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -277,14 +302,14 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, TagLib::ID3v1 // If the comment frame is empty - create the frame and add it to the list if (tag2->frameListMap()["COMM"].isEmpty()) { metadata_editor_info("The frame COMM does not exist. Creating"); - auto fr = new TagLib::ID3v2::CommentsFrame; + auto fr = new ID3v2::CommentsFrame; - fr->setText(TagLib::String(value, TagLib::String::UTF8)); - fr->setTextEncoding(TagLib::String::UTF8); + fr->setText(String(value, String::UTF8)); + fr->setTextEncoding(String::UTF8); tag2->addFrame(fr); } else { // If the frame already exists - just modify its value metadata_editor_info("The frame COMM exists. Changing"); - tag2->frameListMap()["COMM"][0]->setText(TagLib::String(value, TagLib::String::UTF8)); + tag2->frameListMap()["COMM"][0]->setText(String(value, String::UTF8)); } if (tag1 && !tag1->isEmpty()) { // Copy the value to ID3v1 tag comment @@ -295,8 +320,7 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s *_metadata, TagLib::ID3v1 return METADATA_EDITOR_ERROR_NONE; } -// *** Lyrics frame is different from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** // -static int __ID3_setLyricsFrame(metadata_editor_s *_metadata, TagLib::ID3v2::Tag *tag2, const char *value) +static int __ID3_setLyricsFrame(metadata_editor_s *_metadata, ID3v2::Tag *tag2, const char *value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -304,7 +328,7 @@ static int __ID3_setLyricsFrame(metadata_editor_s *_metadata, TagLib::ID3v2::Tag 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"); - TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag + ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // 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 USLT deletion"); @@ -315,17 +339,17 @@ static int __ID3_setLyricsFrame(metadata_editor_s *_metadata, TagLib::ID3v2::Tag if (lst.isEmpty()) { // No lyrics - create the frame and add it to the ID3v2 tag metadata_editor_info("The frame USLT does not exist. Creating"); - auto frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame; + auto frame = new ID3v2::UnsynchronizedLyricsFrame; - frame->setTextEncoding(TagLib::String::UTF8); - frame->setText(TagLib::String(value, TagLib::String::UTF8)); + frame->setTextEncoding(String::UTF8); + frame->setText(String(value, String::UTF8)); tag2->addFrame(frame); } else { // the lyrics frames exist - change the existing one metadata_editor_info("USLT frames exist in file. Changing"); - TagLib::ID3v2::FrameList::Iterator it = lst.begin(); - auto frame = static_cast(*it); - frame->setTextEncoding(TagLib::String::UTF8); - frame->setText(TagLib::String(value, TagLib::String::UTF8)); + ID3v2::FrameList::Iterator it = lst.begin(); + auto frame = static_cast(*it); + frame->setTextEncoding(String::UTF8); + frame->setText(String(value, String::UTF8)); } return METADATA_EDITOR_ERROR_NONE; @@ -339,11 +363,11 @@ static int __MP4_getStringItem(metadata_editor_s *_metadata, const char *itemnam 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()); + auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); - TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); + MP4::ItemListMap& itemMap = tag->itemListMap(); + MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); if (it != itemMap.end()) *value = g_strdup(it->second.toStringList()[0].toCString(true)); @@ -361,12 +385,11 @@ static int __MP4_getIntegerItem(metadata_editor_s *_metadata, const char *itemna 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()); + auto tag = dynamic_cast(_metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); - TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); - + MP4::ItemListMap& itemMap = tag->itemListMap(); + MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); if (it != itemMap.end()) *value = g_strdup_printf("%u", it->second.toInt()); else @@ -383,21 +406,21 @@ static int __MP4_updateStringItem(metadata_editor_s *_metadata, const char *item 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()); + 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(); + MP4::ItemListMap& 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); - TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); + MP4::ItemListMap::Iterator it = itemMap.find(itemname); if (it != itemMap.end()) itemMap.erase(it); return METADATA_EDITOR_ERROR_NONE; } metadata_editor_info("The item <%s> will be added", itemname); - itemMap[itemname] = TagLib::MP4::Item(TagLib::String(value, TagLib::String::UTF8)); + itemMap[itemname] = MP4::Item(String(value, String::UTF8)); return METADATA_EDITOR_ERROR_NONE; } @@ -410,15 +433,15 @@ static int __MP4_updateIntegerItem(metadata_editor_s *_metadata, const char *ite 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()); + 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(); + MP4::ItemListMap& 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); - TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); + MP4::ItemListMap::Iterator it = itemMap.find(itemname); if (it != itemMap.end()) itemMap.erase(it); return METADATA_EDITOR_ERROR_NONE; @@ -427,7 +450,7 @@ static int __MP4_updateIntegerItem(metadata_editor_s *_metadata, const char *ite if (isdigit(value[0])) { metadata_editor_info("The item <%s> will be added", itemname); int number = atoi(value); - itemMap[itemname] = TagLib::MP4::Item(number); + itemMap[itemname] = MP4::Item(number); return METADATA_EDITOR_ERROR_NONE; } else { // Notify that string is not a number to process metadata_editor_error("Error. String does not contain a number"); @@ -442,7 +465,7 @@ static int __MP4_getNumberOfPictures(metadata_editor_s *_metadata, char **value) 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()); + 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); @@ -451,7 +474,7 @@ 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_getFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment *xtag, const char *fieldname, char **value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -460,8 +483,8 @@ static int __xiph_getFieldValue(metadata_editor_s *_metadata, TagLib::Ogg::XiphC 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"); - const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); - TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); + const Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); + Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); if ((xtag->contains(fieldname)) && (it != fieldMap.end())) *value = g_strdup(it->second[0].toCString(true)); @@ -471,8 +494,7 @@ static int __xiph_getFieldValue(metadata_editor_s *_metadata, TagLib::Ogg::XiphC return METADATA_EDITOR_ERROR_NONE; } -// *** This function is used to write string into Xiph Comment fields *** // -static int __xiph_updateFieldValue(metadata_editor_s *_metadata, TagLib::Ogg::XiphComment *xtag, const char *fieldname, const char *value) +static int __xiph_updateFieldValue(metadata_editor_s *_metadata, Ogg::XiphComment *xtag, const char *fieldname, const char *value) { int ret = METADATA_EDITOR_ERROR_NONE; @@ -489,7 +511,7 @@ static int __xiph_updateFieldValue(metadata_editor_s *_metadata, TagLib::Ogg::Xi } metadata_editor_info("The field %s will be added", fieldname); // "true" is used to remove other strings of the same "fieldname" first - xtag->addField(fieldname, TagLib::String(value, TagLib::String::UTF8), true); + xtag->addField(fieldname, String(value, String::UTF8), true); return METADATA_EDITOR_ERROR_NONE; } @@ -500,7 +522,7 @@ static int __FLAC_getNumberOfPictures(metadata_editor_s *_metadata, char **value 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; + FLAC::File *_file = dynamic_cast _metadata->file; *value = g_strdup_printf("%u", _file->pictureList().size()); @@ -656,7 +678,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * { int media_type = METADATA_EDITOR_FORMAT_NOTYPE; metadata_editor_s *_metadata = (metadata_editor_s*)metadata; - TagLib::File *_file = NULL; + 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"); @@ -684,29 +706,29 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * try { switch (media_type) { case METADATA_EDITOR_FORMAT_MP3: - _file = new TagLib::MPEG::File(path); + _file = new MPEG::File(path); break; case METADATA_EDITOR_FORMAT_MP4: - _file = new TagLib::MP4::File(path); + _file = new MP4::File(path); break; #if 0 case METADATA_EDITOR_FORMAT_FLAC: - _file = new TagLib::FLAC::File(path); + _file = new FLAC::File(path); break; case METADATA_EDITOR_FORMAT_OGG_VORBIS: - _file = new TagLib::Ogg::Vorbis::File(path); + _file = new Ogg::Vorbis::File(path); break; case METADATA_EDITOR_FORMAT_OGG_FLAC: - _file = new TagLib::Ogg::FLAC::File(path); + _file = new Ogg::FLAC::File(path); break; case METADATA_EDITOR_FORMAT_WAV: // Allocate the file object in memory to work with it later on - _file = new TagLib::RIFF::WAV::File(path); + _file = new RIFF::WAV::File(path); break; #endif @@ -738,9 +760,9 @@ static int __metadata_editor_get_mp3_metadata(metadata_editor_s *metadata, metad 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 - TagLib::MPEG::File *_file = (TagLib::MPEG::File*)metadata->file; - TagLib::ID3v1::Tag *tag1 = _file->ID3v1Tag(); - TagLib::ID3v2::Tag *tag2 = _file->ID3v2Tag(); + MPEG::File *_file = dynamic_cast(metadata->file); + ID3v1::Tag *tag1 = _file->ID3v1Tag(); + ID3v2::Tag *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); @@ -796,8 +818,8 @@ static int __metadata_editor_get_flac_metadata(metadata_editor_s *metadata, meta 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 - TagLib::FLAC::File *_file = (TagLib::FLAC::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->xiphComment(false); + FLAC::File *_file = (FLAC::File*)metadata->file; + Ogg::XiphComment *xtag = _file->xiphComment(false); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); *value = NULL; @@ -830,8 +852,8 @@ static int __metadata_editor_get_ogg_vorbis_metadata(metadata_editor_s *metadata 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 - TagLib::Ogg::Vorbis::File *_file = (TagLib::Ogg::Vorbis::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->tag(); + Ogg::Vorbis::File *_file = (Ogg::Vorbis::File*)metadata->file; + Ogg::XiphComment *xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); *value = NULL; @@ -863,8 +885,8 @@ static int __metadata_editor_get_ogg_flac_metadata(metadata_editor_s *metadata, 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 - TagLib::Ogg::FLAC::File *_file = (TagLib::Ogg::FLAC::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->tag(); + Ogg::FLAC::File *_file = (Ogg::FLAC::File*)metadata->file; + Ogg::XiphComment *xtag = _file->tag(); if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist"); *value = NULL; @@ -896,8 +918,8 @@ static int __metadata_editor_get_wav_metadata(metadata_editor_s *metadata, metad 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 - TagLib::RIFF::WAV::File *_file = (TagLib::RIFF::WAV::File*)metadata->file; - TagLib::ID3v2::Tag *tag2 = _file->tag(); + RIFF::WAV::File *_file = (RIFF::WAV::File*)metadata->file; + ID3v2::Tag *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"); @@ -966,9 +988,9 @@ static int __metadata_editor_set_mp3_metadata(metadata_editor_s *metadata, metad 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 - TagLib::MPEG::File *_file = (TagLib::MPEG::File*)metadata->file; - TagLib::ID3v1::Tag *tag1 = _file->ID3v1Tag(); - TagLib::ID3v2::Tag *tag2 = _file->ID3v2Tag(true); + MPEG::File *_file = (MPEG::File*)metadata->file; + ID3v1::Tag *tag1 = _file->ID3v1Tag(); + ID3v2::Tag *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"); @@ -1024,8 +1046,8 @@ static int __metadata_editor_set_flac_metadata(metadata_editor_s *metadata, meta 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 - TagLib::FLAC::File *_file = (TagLib::FLAC::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->xiphComment(true); + FLAC::File *_file = (FLAC::File*)metadata->file; + Ogg::XiphComment *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"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1056,8 +1078,8 @@ static int __metadata_editor_set_ogg_vorbis_metadata(metadata_editor_s *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 - TagLib::Ogg::Vorbis::File *_file = (TagLib::Ogg::Vorbis::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->tag(); + Ogg::Vorbis::File *_file = (Ogg::Vorbis::File*)metadata->file; + Ogg::XiphComment *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"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1088,8 +1110,8 @@ static int __metadata_editor_set_ogg_flac_metadata(metadata_editor_s *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 - TagLib::Ogg::FLAC::File *_file = (TagLib::Ogg::FLAC::File*)metadata->file; - TagLib::Ogg::XiphComment *xtag = _file->tag(); + Ogg::FLAC::File *_file = (Ogg::FLAC::File*)metadata->file; + Ogg::XiphComment *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"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1120,8 +1142,8 @@ static int __metadata_editor_set_wav_metadata(metadata_editor_s *metadata, metad 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 - TagLib::RIFF::WAV::File *_file = (TagLib::RIFF::WAV::File*)metadata->file; - TagLib::ID3v2::Tag *tag2 = _file->tag(); + RIFF::WAV::File *_file = (RIFF::WAV::File*)metadata->file; + ID3v2::Tag *tag2 = _file->tag(); // Check if the valid tag pointer exist if (tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating"); @@ -1190,14 +1212,14 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: { - TagLib::MPEG::File *_file = (TagLib::MPEG::File*)_metadata->file; - TagLib::ID3v1::Tag *tag1 = _file->ID3v1Tag(); + MPEG::File *_file = (MPEG::File*)_metadata->file; + ID3v1::Tag *tag1 = _file->ID3v1Tag(); if (!tag1 || tag1->isEmpty()) { // If no ID3v1 tag - prevent its creation - if (_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE)) + if (_file->save(MPEG::File::ID3v2 | MPEG::File::APE)) return METADATA_EDITOR_ERROR_NONE; } else { // otherwise - save all tags in file - if (_file->save(TagLib::MPEG::File::AllTags)) + if (_file->save(MPEG::File::AllTags)) return METADATA_EDITOR_ERROR_NONE; } @@ -1223,7 +1245,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) } } -static char * __get_mime_type(const TagLib::String& mime_type) +static char * __get_mime_type(const String& mime_type) { if (mime_type == MIME_TYPE_JPEG || mime_type == MIME_TYPE_PNG) return g_strdup(mime_type.toCString()); @@ -1231,21 +1253,21 @@ static char * __get_mime_type(const TagLib::String& mime_type) return NULL; } -static char * __get_mime_type_from_cover_art(const TagLib::MP4::CoverArt& cover_art) +static char * __get_mime_type_from_cover_art(const MP4::CoverArt& cover_art) { - if (cover_art.format() == TagLib::MP4::CoverArt::JPEG) + if (cover_art.format() == MP4::CoverArt::JPEG) return g_strdup(MIME_TYPE_JPEG); - else if (cover_art.format() == TagLib::MP4::CoverArt::PNG) + else if (cover_art.format() == MP4::CoverArt::PNG) return g_strdup(MIME_TYPE_PNG); return NULL; } -static int __get_APIC(TagLib::ID3v2::Tag *tag, int index, void **picture, int *size, char **mime_type) +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."); - TagLib::ID3v2::FrameList lst = tag->frameListMap()["APIC"]; + ID3v2::FrameList lst = tag->frameListMap()["APIC"]; // Check if there are pictures in the tag if (lst.isEmpty()) { @@ -1261,7 +1283,7 @@ static int __get_APIC(TagLib::ID3v2::Tag *tag, int index, void **picture, int *s metadata_editor_info("There are %u pictures in file. Start of picture number %d extraction", lst.size(), index); - auto pictureFrame = static_cast(lst[index]); + auto pictureFrame = static_cast(lst[index]); uint pictureSize = pictureFrame->picture().size(); metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); @@ -1275,12 +1297,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) { - return __get_APIC(dynamic_cast(metadata->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) { - auto tag = dynamic_cast(metadata->file->tag()); + auto tag = dynamic_cast(metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); if (!(tag->contains("covr"))) { @@ -1288,7 +1310,7 @@ static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **pict return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - TagLib::MP4::CoverArtList lst = tag->item("covr").toCoverArtList(); + MP4::CoverArtList lst = tag->item("covr").toCoverArtList(); // Check if the index is in range of CoverArtList Item if ((index < 0) || ((uint)index >= lst.size())) { @@ -1296,7 +1318,7 @@ static int __get_mp4_picture(metadata_editor_s *metadata, int index, void **pict return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } - auto pictureFrame = static_cast(lst[index]); + auto pictureFrame = static_cast(lst[index]); int pictureSize = pictureFrame.data().size(); metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); @@ -1311,8 +1333,8 @@ 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) { - TagLib::FLAC::File *_file = (TagLib::FLAC::File*) metadata->file; - TagLib::List lst = _file->pictureList(); + FLAC::File *_file = (FLAC::File*) metadata->file; + List lst = _file->pictureList(); if (lst.isEmpty()) { metadata_editor_error("No pictures in FLAC file"); @@ -1325,7 +1347,7 @@ static int __get_flac_picture(metadata_editor_s *metadata, int index, void **pic return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } - auto pictureFrame = static_cast(lst[index]); + auto pictureFrame = static_cast(lst[index]); int pictureSize = pictureFrame->data().size(); metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); @@ -1339,7 +1361,7 @@ 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) { - TagLib::RIFF::WAV::File *_file = (TagLib::RIFF::WAV::File*)metadata->file; + RIFF::WAV::File *_file = (RIFF::WAV::File*)metadata->file; return __get_APIC(_file->tag(), index, picture, size, mime_type); } @@ -1375,16 +1397,16 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index } } -static int __append_APIC(TagLib::ID3v2::Tag *tag, void *picture, size_t size, const char *mime_type) +static int __append_APIC(ID3v2::Tag *tag, void *picture, size_t size, const char *mime_type) { metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. No ID3v2 tag in file."); - auto pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); + auto pictureFrame = new ID3v2::AttachedPictureFrame(); metadata_editor_info("New APIC frame will be added to the ID3v2 tag"); - pictureFrame->setPicture(TagLib::ByteVector((char*)picture, size)); - pictureFrame->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover); + pictureFrame->setPicture(ByteVector((char*)picture, size)); + pictureFrame->setType(ID3v2::AttachedPictureFrame::FrontCover); pictureFrame->setMimeType(mime_type); tag->addFrame(pictureFrame); @@ -1394,27 +1416,27 @@ static int __append_APIC(TagLib::ID3v2::Tag *tag, void *picture, size_t size, co } static int __append_mp3_picture(metadata_editor_s *metadata, void *picture ,size_t size, const char *mime_type) { - return __append_APIC(dynamic_cast(metadata->file)->ID3v2Tag(true), picture, size, mime_type); + return __append_APIC(dynamic_cast(metadata->file)->ID3v2Tag(true), picture, size, mime_type); } static int __append_mp4_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type) { - auto tag = dynamic_cast(metadata->file->tag()); + auto tag = dynamic_cast(metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); - TagLib::MP4::CoverArtList lst; - TagLib::MP4::CoverArt::Format format = TagLib::MP4::CoverArt::Unknown; + MP4::CoverArtList lst; + MP4::CoverArt::Format format = MP4::CoverArt::Unknown; if (strncmp(mime_type, MIME_TYPE_JPEG, strlen(MIME_TYPE_JPEG)) == 0) - format = TagLib::MP4::CoverArt::JPEG; + format = MP4::CoverArt::JPEG; else if (strncmp(mime_type, MIME_TYPE_PNG, strlen(MIME_TYPE_PNG)) == 0) - format = TagLib::MP4::CoverArt::PNG; + format = MP4::CoverArt::PNG; if (tag->contains("covr")) { metadata_editor_info("The item exists. Adding picture"); lst = tag->item("covr").toCoverArtList(); } - lst.append(TagLib::MP4::CoverArt(format, TagLib::ByteVector((char*)picture, size))); + lst.append(MP4::CoverArt(format, ByteVector((char*)picture, size))); tag->setItem("covr", lst); return METADATA_EDITOR_ERROR_NONE; @@ -1423,13 +1445,13 @@ static int __append_mp4_picture(metadata_editor_s *metadata, void *picture, size #if 0 static int __append_flac_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type) { - TagLib::FLAC::File *_file = (TagLib::FLAC::File*) metadata->file; - auto frontCover = new TagLib::FLAC::Picture; + FLAC::File *_file = (FLAC::File*) metadata->file; + auto frontCover = new FLAC::Picture; metadata_editor_debug_fenter(); - frontCover->setData(TagLib::ByteVector((char*)picture, size)); - frontCover->setType(TagLib::FLAC::Picture::FrontCover); + frontCover->setData(ByteVector((char*)picture, size)); + frontCover->setType(FLAC::Picture::FrontCover); frontCover->setMimeType(mime_type); _file->addPicture(frontCover); @@ -1439,7 +1461,7 @@ static int __append_flac_picture(metadata_editor_s *metadata, void *picture, siz static int __append_wav_picture(metadata_editor_s *metadata, void *picture, size_t size, const char *mime_type) { - return __append_APIC(dynamic_cast(metadata->file->tag()), picture, size, mime_type); + return __append_APIC(dynamic_cast(metadata->file->tag()), picture, size, mime_type); } #endif @@ -1489,11 +1511,11 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const return ret; } -static int __remove_APIC(TagLib::ID3v2::Tag *tag, int index) +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"); - TagLib::ID3v2::FrameList lst = tag->frameListMap()["APIC"]; + ID3v2::FrameList lst = tag->frameListMap()["APIC"]; metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_OPERATION_FAILED, "No pictures in file"); if ((index < 0) || ((uint)index >= lst.size())) { @@ -1507,12 +1529,12 @@ static int __remove_APIC(TagLib::ID3v2::Tag *tag, int index) } static int __remove_mp3_picture(metadata_editor_s *metadata, int index) { - return __remove_APIC(dynamic_cast(metadata->file)->ID3v2Tag(true), index); + return __remove_APIC(dynamic_cast(metadata->file)->ID3v2Tag(true), index); } static int __remove_mp4_picture(metadata_editor_s *metadata, int index) { - auto tag = dynamic_cast(metadata->file->tag()); + auto tag = dynamic_cast(metadata->file->tag()); metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); if (!(tag->contains("covr"))) { @@ -1520,7 +1542,7 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - TagLib::MP4::CoverArtList lst = tag->item("covr").toCoverArtList(); + MP4::CoverArtList lst = tag->item("covr").toCoverArtList(); // Check if the index is in range of CoverArtList Item if ((index < 0) || ((uint)index >= lst.size())) { @@ -1529,12 +1551,9 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) } metadata_editor_info("The picture number %d will be deleted", index); - int i = 0; - for (TagLib::MP4::CoverArtList::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { - if (i != index) continue; - lst.erase(picIt); - break; - } + auto picIt = lst.begin(); + std::advance(picIt, index); + lst.erase(picIt); tag->setItem("covr", lst); //?? FIX ME! @@ -1544,8 +1563,8 @@ static int __remove_mp4_picture(metadata_editor_s *metadata, int index) #if 0 static int __remove_flac_picture(metadata_editor_s *metadata, int index) { - TagLib::FLAC::File *_file = (TagLib::FLAC::File*) metadata->file; - TagLib::List lst = _file->pictureList(); + FLAC::File *_file = dynamic_cast metadata->file; + List lst = _file->pictureList(); if (lst.isEmpty()) { metadata_editor_error("No pictures in file. Nothing to delete"); @@ -1559,19 +1578,14 @@ static int __remove_flac_picture(metadata_editor_s *metadata, int index) } metadata_editor_info("The picture number %d will be deleted", index); - int i = 0; - for (TagLib::List::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { - if (i != index) continue; - _file->removePicture(*picIt, true); - break; - } + _file->removePicture(lst[index], true); return METADATA_EDITOR_ERROR_NONE; } static int __remove_wav_picture(metadata_editor_s *metadata, int index) { - return __remove_APIC(dynamic_cast(metadata->file->tag()), index); + return __remove_APIC(dynamic_cast(metadata->file->tag()), index); } #endif