musikr: add id3v1 support
Forgot to go ahead and implement this.
This commit is contained in:
parent
802e215482
commit
8c3750778f
5 changed files with 41 additions and 22 deletions
|
@ -34,6 +34,15 @@ void JVMMetadataBuilder::setMimeType(const std::string_view type) {
|
|||
this->mimeType = type;
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setId3v1(TagLib::ID3v1::Tag &tag) {
|
||||
id3v2.add_id("TIT2", tag.title());
|
||||
id3v2.add_id("TPE1", tag.artist());
|
||||
id3v2.add_id("TALB", tag.album());
|
||||
id3v2.add_id("TRCK", std::to_string(tag.track()));
|
||||
id3v2.add_id("TYER", std::to_string(tag.year()));
|
||||
id3v2.add_id("TCON", std::to_string(tag.genreNumber()));
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setId3v2(TagLib::ID3v2::Tag &tag) {
|
||||
// We want to ideally find the front cover, fall back to the first picture otherwise.
|
||||
std::optional<TagLib::ID3v2::AttachedPictureFrame*> firstPic;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
#include "taglib/id3v1tag.h"
|
||||
#include "taglib/id3v2tag.h"
|
||||
#include "taglib/xiphcomment.h"
|
||||
#include "taglib/mp4tag.h"
|
||||
|
@ -35,6 +36,7 @@ public:
|
|||
JVMMetadataBuilder(JNIEnv *env);
|
||||
|
||||
void setMimeType(const std::string_view type);
|
||||
void setId3v1(TagLib::ID3v1::Tag &tag);
|
||||
void setId3v2(TagLib::ID3v2::Tag &tag);
|
||||
void setXiph(TagLib::Ogg::XiphComment &tag);
|
||||
void setMp4(TagLib::MP4::Tag &tag);
|
||||
|
|
|
@ -52,13 +52,13 @@ JVMTagMap::~JVMTagMap() {
|
|||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
|
||||
void JVMTagMap::add_id(TagLib::String &id, TagLib::String &value) {
|
||||
void JVMTagMap::add_id(TagLib::String id, TagLib::String value) {
|
||||
env->CallVoidMethod(tagMap, tagMapAddIdSingleMethod,
|
||||
env->NewStringUTF(id.toCString(true)),
|
||||
env->NewStringUTF(value.toCString(true)));
|
||||
}
|
||||
|
||||
void JVMTagMap::add_id(TagLib::String &id, TagLib::StringList &value) {
|
||||
void JVMTagMap::add_id(TagLib::String id, TagLib::StringList value) {
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
for (auto &item : value) {
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod,
|
||||
|
@ -68,14 +68,14 @@ void JVMTagMap::add_id(TagLib::String &id, TagLib::StringList &value) {
|
|||
env->NewStringUTF(id.toCString(true)), arrayList);
|
||||
}
|
||||
|
||||
void JVMTagMap::add_custom(TagLib::String &description, TagLib::String &value) {
|
||||
void JVMTagMap::add_custom(TagLib::String description, TagLib::String value) {
|
||||
env->CallVoidMethod(tagMap, tagMapAddCustomSingleMethod,
|
||||
env->NewStringUTF(description.toCString(true)),
|
||||
env->NewStringUTF(value.toCString(true)));
|
||||
}
|
||||
|
||||
void JVMTagMap::add_custom(TagLib::String &description,
|
||||
TagLib::StringList &value) {
|
||||
void JVMTagMap::add_custom(TagLib::String description,
|
||||
TagLib::StringList value) {
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
for (auto &item : value) {
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod,
|
||||
|
@ -85,16 +85,16 @@ void JVMTagMap::add_custom(TagLib::String &description,
|
|||
env->NewStringUTF(description.toCString(true)), arrayList);
|
||||
}
|
||||
|
||||
void JVMTagMap::add_combined(TagLib::String &id, TagLib::String &description,
|
||||
TagLib::String &value) {
|
||||
void JVMTagMap::add_combined(TagLib::String id, TagLib::String description,
|
||||
TagLib::String value) {
|
||||
env->CallVoidMethod(tagMap, tagMapAddCombinedSingleMethod,
|
||||
env->NewStringUTF(id.toCString(true)),
|
||||
env->NewStringUTF(description.toCString(true)),
|
||||
env->NewStringUTF(value.toCString(true)));
|
||||
}
|
||||
|
||||
void JVMTagMap::add_combined(TagLib::String &id, TagLib::String &description,
|
||||
TagLib::StringList &value) {
|
||||
void JVMTagMap::add_combined(TagLib::String id, TagLib::String description,
|
||||
TagLib::StringList value) {
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
for (auto &item : value) {
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod,
|
||||
|
|
|
@ -32,16 +32,16 @@ public:
|
|||
JVMTagMap(const JVMTagMap&) = delete;
|
||||
JVMTagMap& operator=(const JVMTagMap&) = delete;
|
||||
|
||||
void add_id(TagLib::String &id, TagLib::String &value);
|
||||
void add_id(TagLib::String &id, TagLib::StringList &value);
|
||||
void add_id(TagLib::String id, TagLib::String value);
|
||||
void add_id(TagLib::String id, TagLib::StringList value);
|
||||
|
||||
void add_custom(TagLib::String &description, TagLib::String &value);
|
||||
void add_custom(TagLib::String &description, TagLib::StringList &value);
|
||||
void add_custom(TagLib::String description, TagLib::String value);
|
||||
void add_custom(TagLib::String description, TagLib::StringList value);
|
||||
|
||||
void add_combined(TagLib::String &id, TagLib::String &description,
|
||||
TagLib::String &value);
|
||||
void add_combined(TagLib::String &id, TagLib::String &description,
|
||||
TagLib::StringList &value);
|
||||
void add_combined(TagLib::String id, TagLib::String description,
|
||||
TagLib::String value);
|
||||
void add_combined(TagLib::String id, TagLib::String description,
|
||||
TagLib::StringList value);
|
||||
|
||||
jobject getObject();
|
||||
|
||||
|
|
|
@ -46,9 +46,13 @@ Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
|||
|
||||
if (auto *mpegFile = dynamic_cast<TagLib::MPEG::File *>(file)) {
|
||||
builder.setMimeType("audio/mpeg");
|
||||
auto tag = mpegFile->ID3v2Tag();
|
||||
if (tag != nullptr) {
|
||||
builder.setId3v2(*tag);
|
||||
auto id3v1Tag = mpegFile->ID3v1Tag();
|
||||
if (id3v1Tag != nullptr) {
|
||||
builder.setId3v1(*id3v1Tag);
|
||||
}
|
||||
auto id3v2Tag = mpegFile->ID3v2Tag();
|
||||
if (id3v2Tag != nullptr) {
|
||||
builder.setId3v2(*id3v2Tag);
|
||||
}
|
||||
} else if (auto *mp4File = dynamic_cast<TagLib::MP4::File *>(file)) {
|
||||
builder.setMimeType("audio/mp4");
|
||||
|
@ -58,6 +62,10 @@ Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
|||
}
|
||||
} else if (auto *flacFile = dynamic_cast<TagLib::FLAC::File *>(file)) {
|
||||
builder.setMimeType("audio/flac");
|
||||
auto id3v1Tag = flacFile->ID3v1Tag();
|
||||
if (id3v1Tag != nullptr) {
|
||||
builder.setId3v1(*id3v1Tag);
|
||||
}
|
||||
auto id3v2Tag = flacFile->ID3v2Tag();
|
||||
if (id3v2Tag != nullptr) {
|
||||
builder.setId3v2(*id3v2Tag);
|
||||
|
@ -89,14 +97,14 @@ Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
|||
}
|
||||
} else {
|
||||
// While taglib supports other formats, ExoPlayer does not. Ignore them.
|
||||
LOGE("Unsupported file format");
|
||||
LOGD("Unsupported file format");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
builder.setProperties(file->audioProperties());
|
||||
return builder.build();
|
||||
} catch (std::runtime_error e) {
|
||||
LOGE("Error opening file: %s", e.what());
|
||||
LOGD("Error opening file: %s", e.what());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue