musikr: handle null tags
This commit is contained in:
parent
ed3e0845d6
commit
e519e8f8be
2 changed files with 28 additions and 21 deletions
|
@ -35,34 +35,20 @@ void JVMMetadataBuilder::setMimeType(const std::string_view type) {
|
||||||
|
|
||||||
void JVMMetadataBuilder::setId3v2(const TagLib::ID3v2::Tag &tag) {
|
void JVMMetadataBuilder::setId3v2(const TagLib::ID3v2::Tag &tag) {
|
||||||
for (auto frame : tag.frameList()) {
|
for (auto frame : tag.frameList()) {
|
||||||
LOGD("Frame Check");
|
|
||||||
if (frame == nullptr)
|
|
||||||
continue;
|
|
||||||
LOGD("Text Frame Check");
|
|
||||||
if (auto txxxFrame =
|
if (auto txxxFrame =
|
||||||
dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(frame)) {
|
dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(frame)) {
|
||||||
LOGD("TXXX ID");
|
|
||||||
TagLib::String id = frame->frameID();
|
TagLib::String id = frame->frameID();
|
||||||
LOGD("TXXX Fields");
|
|
||||||
TagLib::StringList frameText = txxxFrame->fieldList();
|
TagLib::StringList frameText = txxxFrame->fieldList();
|
||||||
LOGD("TXXX Check");
|
|
||||||
if (frameText.isEmpty())
|
if (frameText.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
LOGD("TXXX Begin");
|
|
||||||
auto begin = frameText.begin();
|
auto begin = frameText.begin();
|
||||||
LOGD("TXXX Desc");
|
|
||||||
TagLib::String description = *begin;
|
TagLib::String description = *begin;
|
||||||
LOGD("TXXX Erase");
|
|
||||||
frameText.erase(begin);
|
frameText.erase(begin);
|
||||||
LOGD("TXXX Add");
|
|
||||||
id3v2.add_combined(id, description, frameText);
|
id3v2.add_combined(id, description, frameText);
|
||||||
} else if (auto textFrame =
|
} else if (auto textFrame =
|
||||||
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame*>(frame)) {
|
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame*>(frame)) {
|
||||||
LOGD("T*** ID");
|
|
||||||
TagLib::String key = frame->frameID();
|
TagLib::String key = frame->frameID();
|
||||||
LOGD("T*** Fields");
|
|
||||||
TagLib::StringList frameText = textFrame->fieldList();
|
TagLib::StringList frameText = textFrame->fieldList();
|
||||||
LOGD("T*** Add");
|
|
||||||
id3v2.add_id(key, frameText);
|
id3v2.add_id(key, frameText);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -46,24 +46,45 @@ Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
||||||
|
|
||||||
if (auto *mpegFile = dynamic_cast<TagLib::MPEG::File *>(file)) {
|
if (auto *mpegFile = dynamic_cast<TagLib::MPEG::File *>(file)) {
|
||||||
builder.setMimeType("audio/mpeg");
|
builder.setMimeType("audio/mpeg");
|
||||||
builder.setId3v2(*mpegFile->ID3v2Tag());
|
auto tag = mpegFile->ID3v2Tag();
|
||||||
|
if (tag != nullptr) {
|
||||||
|
builder.setId3v2(*tag);
|
||||||
|
}
|
||||||
} else if (auto *mp4File = dynamic_cast<TagLib::MP4::File *>(file)) {
|
} else if (auto *mp4File = dynamic_cast<TagLib::MP4::File *>(file)) {
|
||||||
builder.setMimeType("audio/mp4");
|
builder.setMimeType("audio/mp4");
|
||||||
builder.setMp4(*mp4File->tag());
|
auto tag = mp4File->tag();
|
||||||
|
if (tag != nullptr) {
|
||||||
|
builder.setMp4(*tag);
|
||||||
|
}
|
||||||
} else if (auto *flacFile = dynamic_cast<TagLib::FLAC::File *>(file)) {
|
} else if (auto *flacFile = dynamic_cast<TagLib::FLAC::File *>(file)) {
|
||||||
builder.setMimeType("audio/flac");
|
builder.setMimeType("audio/flac");
|
||||||
builder.setId3v2(*flacFile->ID3v2Tag());
|
auto id3v2Tag = flacFile->ID3v2Tag();
|
||||||
builder.setXiph(*flacFile->xiphComment());
|
if (id3v2Tag != nullptr) {
|
||||||
|
builder.setId3v2(*id3v2Tag);
|
||||||
|
}
|
||||||
|
auto xiphComment = flacFile->xiphComment();
|
||||||
|
if (xiphComment != nullptr) {
|
||||||
|
builder.setXiph(*xiphComment);
|
||||||
|
}
|
||||||
} else if (auto *opusFile = dynamic_cast<TagLib::Ogg::Opus::File *>(file)) {
|
} else if (auto *opusFile = dynamic_cast<TagLib::Ogg::Opus::File *>(file)) {
|
||||||
builder.setMimeType("audio/opus");
|
builder.setMimeType("audio/opus");
|
||||||
builder.setXiph(*opusFile->tag());
|
auto tag = opusFile->tag();
|
||||||
|
if (tag != nullptr) {
|
||||||
|
builder.setXiph(*tag);
|
||||||
|
}
|
||||||
} else if (auto *vorbisFile =
|
} else if (auto *vorbisFile =
|
||||||
dynamic_cast<TagLib::Ogg::Vorbis::File *>(file)) {
|
dynamic_cast<TagLib::Ogg::Vorbis::File *>(file)) {
|
||||||
builder.setMimeType("audio/vorbis");
|
builder.setMimeType("audio/vorbis");
|
||||||
builder.setXiph(*vorbisFile->tag());
|
auto tag = vorbisFile->tag();
|
||||||
|
if (tag != nullptr) {
|
||||||
|
builder.setXiph(*tag);
|
||||||
|
}
|
||||||
} else if (auto *wavFile = dynamic_cast<TagLib::RIFF::WAV::File *>(file)) {
|
} else if (auto *wavFile = dynamic_cast<TagLib::RIFF::WAV::File *>(file)) {
|
||||||
builder.setMimeType("audio/wav");
|
builder.setMimeType("audio/wav");
|
||||||
builder.setId3v2(*wavFile->ID3v2Tag());
|
auto tag = wavFile->ID3v2Tag();
|
||||||
|
if (tag != nullptr) {
|
||||||
|
builder.setId3v2(*tag);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// While taglib supports other formats, ExoPlayer does not. Ignore them.
|
// While taglib supports other formats, ExoPlayer does not. Ignore them.
|
||||||
LOGE("Unsupported file format");
|
LOGE("Unsupported file format");
|
||||||
|
|
Loading…
Reference in a new issue