#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <glib.h>
static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value);
static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value);
TagLib::MP4::ItemListMap& itemMap = tag->itemListMap();
TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr");
if (it != itemMap.end()) { // Item was found
- uint number = it->second.toCoverArtList().size(); // Get the size of CoverList (i.e. number of pictures in file)
- 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
- int length = strlen(buf);
- metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string");
- *value = strndup(buf, length);
+ 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");
if (!tag1 || tag1->isEmpty()) { // If no ID3v1 tag - prevent its creation
if (_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE))
return METADATA_EDITOR_ERROR_NONE;
- else
- return METADATA_EDITOR_ERROR_OPERATION_FAILED;
} else { // otherwise - save all tags in file
if (_file->save(TagLib::MPEG::File::AllTags))
return METADATA_EDITOR_ERROR_NONE;
- else
- return METADATA_EDITOR_ERROR_OPERATION_FAILED;
}
+ return METADATA_EDITOR_ERROR_OPERATION_FAILED;
}
case METADATA_EDITOR_FORMAT_MP4: {
TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file;
metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
TagLib::ID3v2::FrameList lst = tag2->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;
- } else { // pictures exist in file
- // Check if index is correct or not
- if ((index < 0) || (lst.size() <= (uint)index)) {
- metadata_editor_error("Index of picture is out of range");
- return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
- } else { // everything is correct - begin extraction
- metadata_editor_info("Removing of picture number %d", index);
- int i = 0;
- // Among all frames we must choose that one with specified index. "i" will be counter
- for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) {
- if (i != index) continue;
- tag2->removeFrame(*it);
- break;
- }
- return METADATA_EDITOR_ERROR_NONE;
- }
+ metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_OPERATION_FAILED, "No pictures in file");
+
+ // Check if index is correct or not
+ metadata_editor_retvm_if((index < 0) || (lst.size() <= (uint)index), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Index of picture is out of range");
+ metadata_editor_info("Removing of picture number %d", index);
+ int i = 0;
+ // Among all frames we must choose that one with specified index. "i" will be counter
+ for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) {
+ if (i != index) continue;
+ tag2->removeFrame(*it);
+ break;
}
+ return METADATA_EDITOR_ERROR_NONE;
}
case METADATA_EDITOR_FORMAT_MP4: {
TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file;