return METADATA_EDITOR_ERROR_NONE;
}
-// *** This function reads frames that exist only in ID3v2 tag *** //
-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, 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
metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame %s does not exist", frameID);
metadata_editor_info("The frame %s exists", frameID);
- // 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);
+ *value = g_strdup(tag2->frameListMap()[frameID][0]->toString().toCString(true));
return METADATA_EDITOR_ERROR_NONE;
}
return METADATA_EDITOR_ERROR_NONE;
}
-// *** This function is used to receive unsynchronized lyrics from ID3v2 tag in file *** //
-// *** This frame differs from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** //
-static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) {
+static int __ID3_getLyricsFrame(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()["USLT"]; // link to unsynchronized lyric frames in tag
- // Check if frames exist in file
+ TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"];
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<TagLib::ID3v2::UnsynchronizedLyricsFrame*>(*it);
- TagLib::String str = frame->text();
- 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);
+
+ *value = g_strdup(frame->text().toCString(true));
+
return METADATA_EDITOR_ERROR_NONE;
}
return METADATA_EDITOR_ERROR_NONE;
}
-static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char **value)
+static int __MP4_getStringItem(metadata_editor_s *_metadata, const char *itemname, char **value)
{
int ret = METADATA_EDITOR_ERROR_NONE;
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(itemname);
- if (it != itemMap.end()) { // Item was found
- TagLib::String str = it->second.toStringList()[0]; // Get the first string in item
- // Check the encoding of the string (1252 or not)
- bool isUTF = false;
- if (!str.isLatin1()) isUTF = true;
- metadata_editor_info("String is %sUTF", (isUTF ? "" : "not "));
- // Get the length of the string and check if it is empty or 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);
- return METADATA_EDITOR_ERROR_NONE;
- } else { // Item was not found
+
+ if (it != itemMap.end())
+ *value = g_strdup(it->second.toStringList()[0].toCString(true));
+ else
metadata_editor_info("No item <%s> in file", itemname);
- return METADATA_EDITOR_ERROR_NONE;
- }
+
+ return METADATA_EDITOR_ERROR_NONE;
}
-static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value)
+static int __MP4_getIntegerItem(metadata_editor_s *_metadata, const char *itemname, char **value)
{
int ret = METADATA_EDITOR_ERROR_NONE;
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(itemname);
- if (it != itemMap.end()) { // Item was found
- char buf[META_MAX_BUF_LEN] = {0, };
- int num = it->second.toInt(); // Get integer value in item
- snprintf(buf, META_MAX_BUF_LEN, "%u", num); // Convert int into char[]
- // Determine the length of created c-string and copy it into the output variable
- int length = strlen(buf);
- metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string");
- *value = strndup(buf, length);
- return METADATA_EDITOR_ERROR_NONE;
- } else { // Item was not found
+
+ if (it != itemMap.end())
+ *value = g_strdup_printf("%u", it->second.toInt());
+ else
metadata_editor_info("No item <%s> in file", itemname);
- return METADATA_EDITOR_ERROR_NONE;
- }
+
+ return METADATA_EDITOR_ERROR_NONE;
}
static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value)
return METADATA_EDITOR_ERROR_NONE;
}
+
#if 0
-// *** This function is used to extract string from Xiph Comment field *** //
-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, TagLib::Ogg::XiphComment *xtag, const char *fieldname, char **value)
+{
int ret = METADATA_EDITOR_ERROR_NONE;
ret = __check_metadata_get_parameter(_metadata, value);
const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap();
TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname);
- if ((xtag->contains(fieldname)) && (it != fieldMap.end())) { // Field was found
- metadata_editor_info("Field %s was found. Extracting", fieldname);
- TagLib::String str = it->second[0]; // Get the first string in xiph field
- // Check the encoding of the string (1252 or not)
- bool isUTF = false;
- if (!str.isLatin1()) isUTF = true;
- metadata_editor_info("String is %sUTF", (isUTF ? "" : "not "));
- // Get the length of the string and check if it is empty or 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);
- return METADATA_EDITOR_ERROR_NONE;
- } else { // Field was not found
+ if ((xtag->contains(fieldname)) && (it != fieldMap.end()))
+ *value = g_strdup(it->second[0].toCString(true));
+ else
metadata_editor_info("No field %s in Xiph Comment", fieldname);
- return METADATA_EDITOR_ERROR_NONE;
- }
+
+ return METADATA_EDITOR_ERROR_NONE;
}
// *** This function is used to write string into Xiph Comment fields *** //