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);
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 */
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;
}
}
}
-// *** 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<TagLib::MP4::Tag*>(_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 <covr> 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 *** //
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
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<TagLib::MPEG::File*>(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<TagLib::MP4::Tag*>(metadata->file->tag());
metadata_editor_retvm_if(!tag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist");