ktaglib: fix tag mapping
- TagLib apparently bundles description with a TXXX frame's field values. - TagLib doesn't normalize to lowercase like Auxio does (Will change this in the future to be uppercase instead to save on re-allocs)
This commit is contained in:
parent
93a602b592
commit
2f98d67855
2 changed files with 24 additions and 14 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "JVMMetadataBuilder.h"
|
||||
|
||||
#include <taglib/mp4tag.h>
|
||||
#include <taglib/textidentificationframe.h>
|
||||
|
||||
JVMMetadataBuilder::JVMMetadataBuilder(JNIEnv *env) : env(env), id3v2(env), xiph(env), mp4(env),
|
||||
cover(), properties(nullptr) {}
|
||||
|
@ -15,28 +16,37 @@ void JVMMetadataBuilder::setMimeType(const std::string_view mimeType) {
|
|||
|
||||
void JVMMetadataBuilder::setId3v2(const TagLib::ID3v2::Tag &tag) {
|
||||
for (auto frame: tag.frameList()) {
|
||||
auto frameId = TagLib::String(frame->frameID());
|
||||
auto frameText = frame->toStringList();
|
||||
id3v2.add(frameId, frameText);
|
||||
if (auto txxxFrame = dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame *>(frame)) {
|
||||
TagLib::String desc = std::string(txxxFrame->description().toCString(true));
|
||||
// Make desc lowercase
|
||||
std::transform(desc.begin(), desc.end(), desc.begin(), ::tolower);
|
||||
TagLib::String key = TagLib::String(frame->frameID()) + ":" + desc;
|
||||
TagLib::StringList frameText = txxxFrame->fieldList();
|
||||
frameText.erase(frameText.begin()); // Remove description that exists for some insane reason
|
||||
id3v2.add(key, frameText);
|
||||
} else if (auto textFrame = dynamic_cast<TagLib::ID3v2::TextIdentificationFrame *>(frame)) {
|
||||
TagLib::String key = frame->frameID();
|
||||
TagLib::StringList frameText = textFrame->fieldList();
|
||||
id3v2.add(key, frameText);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setXiph(const TagLib::Ogg::XiphComment &tag) {
|
||||
for (auto field: tag.fieldListMap()) {
|
||||
auto fieldName = TagLib::String(field.first);
|
||||
auto fieldName = std::string(field.first.toCString(true));
|
||||
std::transform(fieldName.begin(), fieldName.end(), fieldName.begin(), ::tolower);
|
||||
auto taglibFieldName = TagLib::String(fieldName);
|
||||
auto fieldValue = field.second;
|
||||
xiph.add(fieldName, fieldValue);
|
||||
xiph.add(taglibFieldName, fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setMp4(const TagLib::MP4::Tag &tag) {
|
||||
for (auto item: tag.itemMap()) {
|
||||
auto atomName = item.first;
|
||||
// Strip out ID Padding
|
||||
while (atomName.startsWith("\251")) {
|
||||
atomName = atomName.substr(1);
|
||||
}
|
||||
auto itemName = TagLib::String(atomName);
|
||||
auto itemName = TagLib::String(item.first);
|
||||
auto itemValue = item.second;
|
||||
auto type = itemValue.type();
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ data class FileRef(
|
|||
)
|
||||
|
||||
data class Metadata(
|
||||
val id3v2: Map<String, String>,
|
||||
val xiph: Map<String, String>,
|
||||
val mp4: Map<String, String>,
|
||||
val id3v2: Map<String, List<String>>,
|
||||
val xiph: Map<String, List<String>>,
|
||||
val mp4: Map<String, List<String>>,
|
||||
val cover: ByteArray?,
|
||||
val properties: Properties
|
||||
) {
|
||||
|
|
Loading…
Reference in a new issue