diff --git a/autotests/samplefiles/test.aif b/autotests/samplefiles/test.aif index f564bb8..3230cee 100644 Binary files a/autotests/samplefiles/test.aif and b/autotests/samplefiles/test.aif differ diff --git a/autotests/samplefiles/test.mp3 b/autotests/samplefiles/test.mp3 index 39bcaab..8c05880 100644 Binary files a/autotests/samplefiles/test.mp3 and b/autotests/samplefiles/test.mp3 differ diff --git a/autotests/samplefiles/test.wav b/autotests/samplefiles/test.wav index abf71b2..ab5ae8f 100644 Binary files a/autotests/samplefiles/test.wav and b/autotests/samplefiles/test.wav differ diff --git a/autotests/taglibextractortest.cpp b/autotests/taglibextractortest.cpp index 4e5c199..c7cf92b 100644 --- a/autotests/taglibextractortest.cpp +++ b/autotests/taglibextractortest.cpp @@ -1,554 +1,564 @@ /* * TagLibExtractor tests. * * Copyright (C) 2015 Juan Palacios * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "taglibextractortest.h" #include "simpleextractionresult.h" #include "propertyinfo.h" //TODO: use QTESTFINDDATA and remove this #include "indexerextractortestsconfig.h" #include "extractors/taglibextractor.h" #include #include #include Q_DECLARE_METATYPE(KFileMetaData::Property::Property) using namespace KFileMetaData; QString TagLibExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } const QStringList TagLibExtractorTest::propertyEnumNames(const QList& keys) const { QStringList result; for (auto key : keys) { result.append(PropertyInfo(key).name()); } return result; } void TagLibExtractorTest::testCommonData() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; QCOMPARE(plugin.mimetypes().contains(mimeType), true); SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Audio); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(result.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(result.properties().value(Property::Album), QVariant(QStringLiteral("Album"))); QCOMPARE(result.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(result.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(result.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::ReleaseYear).toInt(), 2015); } void TagLibExtractorTest::testCommonData_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); QTest::addRow("aiff") << QStringLiteral("aif") << QStringLiteral("audio/x-aiff") ; QTest::addRow("ape") << QStringLiteral("ape") << QStringLiteral("audio/x-ape") ; QTest::addRow("flac") << QStringLiteral("flac") << QStringLiteral("audio/flac") ; QTest::addRow("m4a") << QStringLiteral("m4a") << QStringLiteral("audio/mp4") ; QTest::addRow("mp3") << QStringLiteral("mp3") << QStringLiteral("audio/mpeg3") ; QTest::addRow("mpc") << QStringLiteral("mpc") << QStringLiteral("audio/x-musepack") ; QTest::addRow("ogg") << QStringLiteral("ogg") << QStringLiteral("audio/ogg") ; QTest::addRow("opus") << QStringLiteral("opus") << QStringLiteral("audio/opus") ; QTest::addRow("wav") << QStringLiteral("wav") << QStringLiteral("audio/wav") ; QTest::addRow("wavpack") << QStringLiteral("wv") << QStringLiteral("audio/x-wavpack") ; QTest::addRow("wma") << QStringLiteral("wma") << QStringLiteral("audio/x-ms-wma") ; } void TagLibExtractorTest::testVorbisComment() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Opus).toInt(), 1); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Rating).toInt(), 5); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.90)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.512)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-10.44)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.301)); } void TagLibExtractorTest::testVorbisComment_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); QTest::addRow("flac") << QStringLiteral("flac") << QStringLiteral("audio/flac") ; QTest::addRow("ogg") << QStringLiteral("ogg") << QStringLiteral("audio/ogg") ; QTest::addRow("opus") << QStringLiteral("opus") << QStringLiteral("audio/opus") ; } void TagLibExtractorTest::testId3() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Rating).toInt(), 10); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-3.33)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.333)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(3.33)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.369)); } void TagLibExtractorTest::testId3_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); + QTest::addRow("aiff") + << QStringLiteral("aif") + << QStringLiteral("audio/x-aiff") + ; + QTest::addRow("mp3") << QStringLiteral("mp3") << QStringLiteral("audio/mpeg") ; + + QTest::addRow("wav") + << QStringLiteral("wav") + << QStringLiteral("audio/wav") + ; } void TagLibExtractorTest::testApe() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).isValid(), false); QCOMPARE(result.properties().value(Property::Rating).toInt(), 4); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.44)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.099)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-5.23)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.234)); } void TagLibExtractorTest::testApe_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); QTest::addRow("ape") << QStringLiteral("ape") << QStringLiteral("audio/x-ape") ; QTest::addRow("musepack") << QStringLiteral("mpc") << QStringLiteral("audio/x-musepack") ; QTest::addRow("wavpack") << QStringLiteral("wv") << QStringLiteral("audio/x-wavpack") ; } void TagLibExtractorTest::testMp4() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; SimpleExtractionResult resultMp4(testFilePath(fileName), mimeType); plugin.extract(&resultMp4); QCOMPARE(resultMp4.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultMp4.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultMp4.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(resultMp4.properties().value(Property::Rating).toInt(), 8); } void TagLibExtractorTest::testMp4_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); QTest::addRow("mp4") << QStringLiteral("m4a") << QStringLiteral("audio/mp4") ; } void TagLibExtractorTest::testAsf() { QFETCH(QString, fileType); QFETCH(QString, mimeType); QString fileName = QStringLiteral("test.") + fileType; TagLibExtractor plugin{this}; SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Rating).toInt(), 6); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); } void TagLibExtractorTest::testAsf_data() { QTest::addColumn("fileType"); QTest::addColumn("mimeType"); QTest::addRow("asf") << QStringLiteral("wma") << QStringLiteral("audio/x-ms-wma") ; } void TagLibExtractorTest::testId3Rating_data() { QTest::addColumn("path"); QTest::addColumn("expectedRating"); QTest::addRow("WMP") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP.mp3") << 0 ; QTest::addRow("WMP1") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP1.mp3") << 2 ; QTest::addRow("WMP2") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP2.mp3") << 4 ; QTest::addRow("WMP3") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP3.mp3") << 6 ; QTest::addRow("WMP4") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP4.mp3") << 8 ; QTest::addRow("WMP5") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP5.mp3") << 10 ; QTest::addRow("MM") << QFINDTESTDATA("samplefiles/mp3_rating/testMM.mp3") << 0 ; QTest::addRow("MM1") << QFINDTESTDATA("samplefiles/mp3_rating/testMM1.mp3") << 1 ; QTest::addRow("MM2") << QFINDTESTDATA("samplefiles/mp3_rating/testMM2.mp3") << 2 ; QTest::addRow("MM3") << QFINDTESTDATA("samplefiles/mp3_rating/testMM3.mp3") << 3 ; QTest::addRow("MM4") << QFINDTESTDATA("samplefiles/mp3_rating/testMM4.mp3") << 4 ; QTest::addRow("MM5") << QFINDTESTDATA("samplefiles/mp3_rating/testMM5.mp3") << 5 ; QTest::addRow("MM6") << QFINDTESTDATA("samplefiles/mp3_rating/testMM6.mp3") << 6 ; QTest::addRow("MM7") << QFINDTESTDATA("samplefiles/mp3_rating/testMM7.mp3") << 7 ; QTest::addRow("MM8") << QFINDTESTDATA("samplefiles/mp3_rating/testMM8.mp3") << 8 ; QTest::addRow("MM9") << QFINDTESTDATA("samplefiles/mp3_rating/testMM9.mp3") << 9 ; QTest::addRow("MM10") << QFINDTESTDATA("samplefiles/mp3_rating/testMM10.mp3") << 10 ; } void TagLibExtractorTest::testId3Rating() { QFETCH(QString, path); QFETCH(int, expectedRating); TagLibExtractor plugin{this}; SimpleExtractionResult result(path, "audio/mpeg"); plugin.extract(&result); QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); } void TagLibExtractorTest::testWmaRating() { QFETCH(QString, path); QFETCH(int, expectedRating); TagLibExtractor plugin{this}; SimpleExtractionResult result(path, "audio/x-ms-wma"); plugin.extract(&result); QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); } void TagLibExtractorTest::testWmaRating_data() { QTest::addColumn("path"); QTest::addColumn("expectedRating"); QTest::addRow("WMP0") << QFINDTESTDATA("samplefiles/wma_rating/test0.wma") << 0 ; QTest::addRow("WMP1") << QFINDTESTDATA("samplefiles/wma_rating/test1.wma") << 2 ; QTest::addRow("WMP2") << QFINDTESTDATA("samplefiles/wma_rating/test2.wma") << 4 ; QTest::addRow("WMP3") << QFINDTESTDATA("samplefiles/wma_rating/test3.wma") << 6 ; QTest::addRow("WMP4") << QFINDTESTDATA("samplefiles/wma_rating/test4.wma") << 8 ; QTest::addRow("WMP5") << QFINDTESTDATA("samplefiles/wma_rating/test5.wma") << 10 ; } void TagLibExtractorTest::testNoMetadata_data() { const auto expectedKeys = QList{ Property::BitRate, Property::Channels, Property::Duration, Property::SampleRate, }; QTest::addColumn("path"); QTest::addColumn("mimeType"); QTest::addColumn>("expectedKeys"); QTest::addColumn("failMessage"); QTest::addRow("mp3") << QFINDTESTDATA("samplefiles/no-meta/test.mp3") << QStringLiteral("audio/mpeg") << expectedKeys << QString() ; QTest::addRow("m4a") << QFINDTESTDATA("samplefiles/no-meta/test.m4a") << QStringLiteral("audio/mp4") << expectedKeys << QString() ; QTest::addRow("flac") << QFINDTESTDATA("samplefiles/no-meta/test.flac") << QStringLiteral("audio/flac") << expectedKeys << QString() ; QTest::addRow("opus") << QFINDTESTDATA("samplefiles/no-meta/test.opus") << QStringLiteral("audio/opus") << expectedKeys << QString() ; QTest::addRow("ogg") << QFINDTESTDATA("samplefiles/no-meta/test.ogg") << QStringLiteral("audio/ogg") << expectedKeys << QString() ; QTest::addRow("mpc") << QFINDTESTDATA("samplefiles/no-meta/test.mpc") << QStringLiteral("audio/x-musepack") << expectedKeys << QString() ; } void TagLibExtractorTest::testNoMetadata() { QFETCH(QString, path); QFETCH(QString, mimeType); QFETCH(QList, expectedKeys); QFETCH(QString, failMessage); TagLibExtractor plugin{this}; SimpleExtractionResult extracted(path, mimeType); plugin.extract(&extracted); const auto resultList = extracted.properties(); const auto resultKeys = resultList.uniqueKeys(); const auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto missingKeys = expectedKeys.toSet() - resultKeys.toSet(); if (excessKeys.size()) { const auto propNames = propertyEnumNames(excessKeys.toList()).join(QLatin1String(", ")); if (failMessage.isEmpty()) { const auto message = QStringLiteral("Excess properties: %1").arg(propNames); QWARN(qPrintable(message)); } else { QEXPECT_FAIL("", qPrintable(QStringLiteral("%1: %2").arg(failMessage).arg(propNames)), Continue); } } else if (missingKeys.size()) { const auto message = QStringLiteral("Missing properties: %1") .arg(propertyEnumNames(missingKeys.toList()).join(QLatin1String(", "))); QWARN(qPrintable(message)); } QCOMPARE(resultKeys, expectedKeys); if (!failMessage.isEmpty()) { auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto message = QStringLiteral("%1: %2") .arg(failMessage) .arg(propertyEnumNames(excessKeys.toList()).join(QLatin1String(", "))); QEXPECT_FAIL("", qPrintable(message), Continue); } QCOMPARE(resultKeys, expectedKeys); } QTEST_GUILESS_MAIN(TagLibExtractorTest) diff --git a/src/extractors/taglibextractor.cpp b/src/extractors/taglibextractor.cpp index 45e4c62..c7b43c3 100644 --- a/src/extractors/taglibextractor.cpp +++ b/src/extractors/taglibextractor.cpp @@ -1,1108 +1,1115 @@ /* Copyright (C) 2012 Vishesh Handa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "taglibextractor.h" // Taglib includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KFileMetaData; TagLibExtractor::TagLibExtractor(QObject* parent) : ExtractorPlugin(parent) { } QStringList TagLibExtractor::mimetypes() const { return QStringList{ QStringLiteral("audio/mpeg"), QStringLiteral("audio/mpeg3"), QStringLiteral("audio/x-mpeg"), QStringLiteral("audio/mp4"), QStringLiteral("audio/flac"), QStringLiteral("audio/x-musepack"), QStringLiteral("audio/ogg"), QStringLiteral("audio/x-vorbis+ogg"), QStringLiteral("audio/opus"), QStringLiteral("audio/x-opus+ogg"), QStringLiteral("audio/wav"), QStringLiteral("audio/x-aiff"), QStringLiteral("audio/x-ape"), QStringLiteral("audio/x-wavpack"), QStringLiteral("audio/x-ms-wma") }; } void TagLibExtractor::extractId3Tags(TagLib::ID3v2::Tag* Id3Tags, ExtractedData& data) { if (Id3Tags->isEmpty()) { return; } TagLib::ID3v2::FrameList lstID3v2; // Artist. lstID3v2 = Id3Tags->frameListMap()["TPE1"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.artists.isEmpty()) { data.artists += ", "; } data.artists += (*it)->toString(); } } // Album Artist. lstID3v2 = Id3Tags->frameListMap()["TPE2"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.albumArtists.isEmpty()) { data.albumArtists += ", "; } data.albumArtists += (*it)->toString(); } } // Composer. lstID3v2 = Id3Tags->frameListMap()["TCOM"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.composers.isEmpty()) { data.composers += ", "; } data.composers += (*it)->toString(); } } // Lyricist. lstID3v2 = Id3Tags->frameListMap()["TEXT"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.lyricists.isEmpty()) { data.lyricists += ", "; } data.lyricists += (*it)->toString(); } } // Genre. lstID3v2 = Id3Tags->frameListMap()["TCON"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { data.genres.append((*it)->toString()); } } // Disc number. lstID3v2 = Id3Tags->frameListMap()["TPOS"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { data.discNumber = (*it)->toString().toInt(); } } // Performer. lstID3v2 = Id3Tags->frameListMap()["TMCL"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.performer.isEmpty()) { data.performer += ", "; } data.performer += (*it)->toString(); } } // Conductor. lstID3v2 = Id3Tags->frameListMap()["TPE3"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.conductor.isEmpty()) { data.conductor += ", "; } data.conductor += (*it)->toString(); } } // Publisher. lstID3v2 = Id3Tags->frameListMap()["TPUB"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.publisher.isEmpty()) { data.publisher += ", "; } data.publisher += (*it)->toString(); } } // Copyright. lstID3v2 = Id3Tags->frameListMap()["TCOP"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.copyright.isEmpty()) { data.copyright += ", "; } data.copyright += (*it)->toString(); } } // Language. lstID3v2 = Id3Tags->frameListMap()["TLAN"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.language.isEmpty()) { data.language += ", "; } data.language += (*it)->toString(); } } // Lyrics. lstID3v2 = Id3Tags->frameListMap()["USLT"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.lyrics.isEmpty()) { data.lyrics += ", "; } data.lyrics += (*it)->toString(); } } // Compilation. lstID3v2 = Id3Tags->frameListMap()["TCMP"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { if (!data.compilation.isEmpty()) { data.compilation += ", "; } data.compilation += (*it)->toString(); } } // Rating. /* There is no standard regarding ratings. Most of the implementations match a 5 stars rating to a range of 0-255 for MP3. Match it to baloo rating with a range of 0 - 10 */ lstID3v2 = Id3Tags->frameListMap()["POPM"]; if (!lstID3v2.isEmpty()) { for (TagLib::ID3v2::FrameList::ConstIterator it = lstID3v2.begin(); it != lstID3v2.end(); ++it) { TagLib::ID3v2::PopularimeterFrame *ratingFrame = static_cast(*it); int rating = ratingFrame->rating(); if (rating == 0) { data.rating = 0; } else if (rating == 1) { TagLib::String ratingProvider = ratingFrame->email(); if (ratingProvider == "no@email" || ratingProvider == "org.kde.kfilemetadata") { data.rating = 1; } else { data.rating = 2; } } else if (rating >= 1 && rating <= 255) { data.rating = static_cast(0.032 * rating + 2); } } } // User Text Frame. lstID3v2 = Id3Tags->frameListMap()["TXXX"]; if (!lstID3v2.isEmpty()) { // look for ReplayGain tags typedef TagLib::ID3v2::UserTextIdentificationFrame IdFrame; auto trackGainFrame = IdFrame::find(Id3Tags, "replaygain_track_gain"); if (trackGainFrame && !trackGainFrame->fieldList().isEmpty()) { data.replayGainTrackGain = TStringToQString(trackGainFrame->fieldList().back()); } auto trackPeakFrame = IdFrame::find(Id3Tags, "replaygain_track_peak"); if (trackPeakFrame && !trackPeakFrame->fieldList().isEmpty()) { data.replayGainTrackPeak = TStringToQString(trackPeakFrame->fieldList().back()); } auto albumGainFrame = IdFrame::find(Id3Tags, "replaygain_album_gain"); if (albumGainFrame && !albumGainFrame->fieldList().isEmpty()) { data.replayGainAlbumGain = TStringToQString(albumGainFrame->fieldList().back()); } auto albumPeakFrame = IdFrame::find(Id3Tags, "replaygain_album_peak"); if (albumPeakFrame && !albumPeakFrame->fieldList().isEmpty()) { data.replayGainAlbumPeak = TStringToQString(albumPeakFrame->fieldList().back()); } } //TODO handle TIPL tag } void TagLibExtractor::extractMp4Tags(TagLib::MP4::Tag* mp4Tags, ExtractedData& data) { if (mp4Tags->isEmpty()) { return; } TagLib::MP4::ItemListMap allTags = mp4Tags->itemListMap(); TagLib::MP4::ItemListMap::Iterator itAlbumArtists = allTags.find("aART"); if (itAlbumArtists != allTags.end()) { data.albumArtists = itAlbumArtists->second.toStringList().toString(", "); } TagLib::MP4::ItemListMap::Iterator itDiscNumber = allTags.find("disk"); if (itDiscNumber != allTags.end()) { data.discNumber = itDiscNumber->second.toInt(); } TagLib::MP4::ItemListMap::Iterator itCompilation = allTags.find("cpil"); if (itCompilation != allTags.end()) { data.compilation = itCompilation->second.toStringList().toString(", "); } TagLib::MP4::ItemListMap::Iterator itCopyright = allTags.find("cprt"); if (itCopyright != allTags.end()) { data.copyright = itCopyright->second.toStringList().toString(", "); } TagLib::String genreAtomName(TagLib::String("©gen", TagLib::String::UTF8).to8Bit(), TagLib::String::Latin1); TagLib::MP4::ItemListMap::Iterator itGenres = allTags.find(genreAtomName); if (itGenres != allTags.end()) { data.genres = itGenres->second.toStringList().toString(", "); } TagLib::String composerAtomName(TagLib::String("©wrt", TagLib::String::UTF8).to8Bit(), TagLib::String::Latin1); TagLib::MP4::ItemListMap::Iterator itComposers = allTags.find(composerAtomName); if (itComposers != allTags.end()) { data.composers = itComposers->second.toStringList().toString(", "); } /* There is no standard regarding ratings. Mimic MediaMonkey's behavior with a range of 0 to 100 (stored in steps of 10) and make it compatible with baloo rating with a range from 0 to 10 */ TagLib::MP4::ItemListMap::Iterator itRating = allTags.find("rate"); if (itRating != allTags.end()) { data.rating = itRating->second.toStringList().toString().toInt() / 10; } TagLib::String lyricsAtomName(TagLib::String("©lyr", TagLib::String::UTF8).to8Bit(), TagLib::String::Latin1); TagLib::MP4::ItemListMap::Iterator itLyrics = allTags.find(lyricsAtomName); if (itLyrics != allTags.end()) { data.lyrics = itLyrics->second.toStringList().toString(", "); } } void TagLibExtractor::extractApeTags(TagLib::APE::Tag* apeTags, ExtractedData& data) { if (apeTags->isEmpty()) { return; } TagLib::APE::ItemListMap lstMusepack = apeTags->itemListMap(); TagLib::APE::ItemListMap::ConstIterator itMPC; itMPC = lstMusepack.find("ARTIST"); if (itMPC != lstMusepack.end()) { if (!data.artists.isEmpty()) { data.artists += ", "; } data.artists += (*itMPC).second.toString(); } itMPC = lstMusepack.find("ALBUMARTIST"); if (itMPC == lstMusepack.end()) { itMPC = lstMusepack.find("ALBUM ARTIST"); } if (itMPC != lstMusepack.end()) { if(!data.albumArtists.isEmpty()) { data.albumArtists += ", "; } data.albumArtists += (*itMPC).second.toString(); } itMPC = lstMusepack.find("COMPOSER"); if (itMPC != lstMusepack.end()) { if (!data.composers.isEmpty()) { data.composers += ", "; } data.composers += (*itMPC).second.toString(); } itMPC = lstMusepack.find("LYRICIST"); if (itMPC != lstMusepack.end()) { if (!data.lyricists.isEmpty()) { data.lyricists += ", "; } data.lyricists += (*itMPC).second.toString(); } itMPC = lstMusepack.find("GENRE"); if (itMPC != lstMusepack.end()) { data.genres.append((*itMPC).second.toString()); } itMPC = lstMusepack.find("LOCATION"); if (itMPC != lstMusepack.end()) { if (!data.location.isEmpty()) { data.location += ", "; } data.location += (*itMPC).second.toString(); } itMPC = lstMusepack.find("ARRANGER"); if (itMPC != lstMusepack.end()) { if (!data.arranger.isEmpty()) { data.arranger += ", "; } data.arranger += (*itMPC).second.toString(); } itMPC = lstMusepack.find("PERFORMER"); if (itMPC != lstMusepack.end()) { if (!data.performer.isEmpty()) { data.performer += ", "; } data.performer += (*itMPC).second.toString(); } itMPC = lstMusepack.find("CONDUCTOR"); if (itMPC != lstMusepack.end()) { if (!data.conductor.isEmpty()) { data.conductor += ", "; } data.conductor += (*itMPC).second.toString(); } itMPC = lstMusepack.find("ENSEMBLE"); if (itMPC != lstMusepack.end()) { if (!data.ensemble.isEmpty()) { data.ensemble += ", "; } data.ensemble += (*itMPC).second.toString(); } itMPC = lstMusepack.find("PUBLISHER"); if (itMPC != lstMusepack.end()) { if (!data.publisher.isEmpty()) { data.publisher += ", "; } data.publisher += (*itMPC).second.toString(); } itMPC = lstMusepack.find("COPYRIGHT"); if (itMPC != lstMusepack.end()) { if (!data.copyright.isEmpty()) { data.copyright += ", "; } data.copyright += (*itMPC).second.toString(); } itMPC = lstMusepack.find("LABEL"); if (itMPC != lstMusepack.end()) { if (!data.label.isEmpty()) { data.label += ", "; } data.label += (*itMPC).second.toString(); } itMPC = lstMusepack.find("AUTHOR"); if (itMPC != lstMusepack.end()) { if (!data.author.isEmpty()) { data.author += ", "; } data.author += (*itMPC).second.toString(); } itMPC = lstMusepack.find("LICENSE"); if (itMPC != lstMusepack.end()) { if (!data.license.isEmpty()) { data.license += ", "; } data.license += (*itMPC).second.toString(); } itMPC = lstMusepack.find("LYRICS"); if (itMPC != lstMusepack.end()) { if (!data.lyrics.isEmpty()) { data.lyrics += ", "; } data.lyrics += (*itMPC).second.toString(); } itMPC = lstMusepack.find("COMPILATION"); if (itMPC != lstMusepack.end()) { if (!data.compilation.isEmpty()) { data.compilation += ", "; } data.compilation += (*itMPC).second.toString(); } itMPC = lstMusepack.find("LANGUAGE"); if (itMPC != lstMusepack.end()) { if (!data.language.isEmpty()) { data.language += ", "; } data.language += (*itMPC).second.toString(); } itMPC = lstMusepack.find("DISCNUMBER"); if (itMPC != lstMusepack.end()) { data.discNumber = (*itMPC).second.toString().toInt(); } itMPC = lstMusepack.find("OPUS"); if (itMPC != lstMusepack.end()) { data.opus = (*itMPC).second.toString().toInt(); } // Rating. itMPC = lstMusepack.find("RATING"); if (itMPC != lstMusepack.end()) { /* There is no standard regarding ratings. There is one implementation most seem to follow with a range of 0 to 100 (stored in steps of 10). Make it compatible with baloo rating with a range from 0 to 10 */ data.rating = (*itMPC).second.toString().toInt() / 10; } itMPC = lstMusepack.find("REPLAYGAIN_TRACK_GAIN"); if (itMPC != lstMusepack.end()) { data.replayGainTrackGain = TStringToQString((*itMPC).second.toString()); } itMPC = lstMusepack.find("REPLAYGAIN_TRACK_PEAK"); if (itMPC != lstMusepack.end()) { data.replayGainTrackPeak = TStringToQString((*itMPC).second.toString()); } itMPC = lstMusepack.find("REPLAYGAIN_ALBUM_GAIN"); if (itMPC != lstMusepack.end()) { data.replayGainAlbumGain = TStringToQString((*itMPC).second.toString()); } itMPC = lstMusepack.find("REPLAYGAIN_ALBUM_PEAK"); if (itMPC != lstMusepack.end()) { data.replayGainAlbumPeak = TStringToQString((*itMPC).second.toString()); } } void TagLibExtractor::extractVorbisTags(TagLib::Ogg::XiphComment* vorbisTags, ExtractedData& data) { if (vorbisTags->isEmpty()) { return; } TagLib::Ogg::FieldListMap lstOgg = vorbisTags->fieldListMap(); TagLib::Ogg::FieldListMap::ConstIterator itOgg; itOgg = lstOgg.find("ARTIST"); if (itOgg != lstOgg.end()) { if (!data.artists.isEmpty()) { data.artists += ", "; } data.artists += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("ALBUMARTIST"); if (itOgg == lstOgg.end()) { itOgg = lstOgg.find("ALBUM ARTIST"); } if (itOgg != lstOgg.end()) { if (!data.albumArtists.isEmpty()) { data.albumArtists += ", "; } data.albumArtists += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("COMPOSER"); if (itOgg != lstOgg.end()) { if (!data.composers.isEmpty()) { data.composers += ", "; } data.composers += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LYRICIST"); if (itOgg != lstOgg.end()) { if (!data.lyricists.isEmpty()) { data.lyricists += ", "; } data.lyricists += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LOCATION"); if (itOgg != lstOgg.end()) { if (!data.location.isEmpty()) { data.location += ", "; } data.location += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("ARRANGER"); if (itOgg != lstOgg.end()) { if (!data.arranger.isEmpty()) { data.arranger += ", "; } data.arranger += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("PERFORMER"); if (itOgg != lstOgg.end()) { if (!data.performer.isEmpty()) { data.performer += ", "; } data.performer += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("CONDUCTOR"); if (itOgg != lstOgg.end()) { if (!data.conductor.isEmpty()) { data.conductor += ", "; } data.conductor += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("ENSEMBLE"); if (itOgg != lstOgg.end()) { if (!data.ensemble.isEmpty()) { data.ensemble += ", "; } data.ensemble += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("PUBLISHER"); if (itOgg != lstOgg.end()) { if (!data.publisher.isEmpty()) { data.publisher += ", "; } data.publisher += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("COPYRIGHT"); if (itOgg != lstOgg.end()) { if (!data.copyright.isEmpty()) { data.copyright += ", "; } data.copyright += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LABEL"); if (itOgg != lstOgg.end()) { if (!data.label.isEmpty()) { data.label += ", "; } data.label += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("AUTHOR"); if (itOgg != lstOgg.end()) { if (!data.author.isEmpty()) { data.author += ", "; } data.author += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LICENSE"); if (itOgg != lstOgg.end()) { if (!data.license.isEmpty()) { data.license += ", "; } data.license += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LYRICS"); if (itOgg != lstOgg.end()) { if (!data.lyrics.isEmpty()) { data.lyrics += ", "; } data.lyrics += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("COMPILATION"); if (itOgg != lstOgg.end()) { if (!data.compilation.isEmpty()) { data.compilation += ", "; } data.compilation += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("LANGUAGE"); if (itOgg != lstOgg.end()) { if (!data.language.isEmpty()) { data.language += ", "; } data.language += (*itOgg).second.toString(", "); } itOgg = lstOgg.find("GENRE"); if (itOgg != lstOgg.end()) { data.genres.append((*itOgg).second); } itOgg = lstOgg.find("DISCNUMBER"); if (itOgg != lstOgg.end()) { data.discNumber = (*itOgg).second.toString("").toInt(); } itOgg = lstOgg.find("OPUS"); if (itOgg != lstOgg.end()) { data.opus = (*itOgg).second.toString("").toInt(); } itOgg = lstOgg.find("RATING"); if (itOgg != lstOgg.end()) { //there is no standard regarding ratings. There is one implementation //most seem to follow with a range of 0 to 100 (stored in steps of 10). //make it compatible with baloo rating with a range from 0 to 10 data.rating = (*itOgg).second.toString("").toInt() / 10; } itOgg = lstOgg.find("REPLAYGAIN_TRACK_GAIN"); if (itOgg != lstOgg.end()) { data.replayGainTrackGain = TStringToQString((*itOgg).second.toString("")); } itOgg = lstOgg.find("REPLAYGAIN_TRACK_PEAK"); if (itOgg != lstOgg.end()) { data.replayGainTrackPeak = TStringToQString((*itOgg).second.toString("")); } itOgg = lstOgg.find("REPLAYGAIN_ALBUM_GAIN"); if (itOgg != lstOgg.end()) { data.replayGainAlbumGain = TStringToQString((*itOgg).second.toString("")); } itOgg = lstOgg.find("REPLAYGAIN_ALBUM_PEAK"); if (itOgg != lstOgg.end()) { data.replayGainAlbumPeak = TStringToQString((*itOgg).second.toString("")); } } void TagLibExtractor::extractAsfTags(TagLib::ASF::Tag* asfTags, ExtractedData& data) { if (asfTags->isEmpty()) { return; } if (!asfTags->copyright().isEmpty()) { data.copyright = asfTags->copyright(); } TagLib::ASF::AttributeList lstASF = asfTags->attribute("WM/SharedUserRating"); if (!lstASF.isEmpty()) { int rating = lstASF.front().toString().toInt(); //map the rating values of WMP to Baloo rating //0->0, 1->2, 25->4, 50->6, 75->8, 99->10 if (rating == 0) { data.rating = 0; } else if (rating == 1) { data.rating = 2; } else { data.rating = static_cast(0.09 * rating + 2); } } lstASF = asfTags->attribute("WM/PartOfSet"); if (!lstASF.isEmpty()) { data.discNumber = lstASF.front().toString().toInt(); } lstASF = asfTags->attribute("WM/AlbumArtist"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.albumArtists.isEmpty()) { data.albumArtists += ", "; } data.albumArtists += attribute.toString(); } lstASF = asfTags->attribute("WM/Composer"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.composers.isEmpty()) { data.composers += ", "; } data.composers += attribute.toString(); } lstASF = asfTags->attribute("WM/Conductor"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.conductor.isEmpty()) { data.conductor += ", "; } data.conductor += attribute.toString(); } lstASF = asfTags->attribute("WM/Writer"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.lyricists.isEmpty()) { data.lyricists += ", "; } data.lyricists += attribute.toString(); } lstASF = asfTags->attribute("WM/Publisher"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.publisher.isEmpty()) { data.publisher += ", "; } data.publisher += attribute.toString(); } lstASF = asfTags->attribute("Author"); for (const auto& attribute : qAsConst(lstASF)) { if (!data.author.isEmpty()) { data.author += ", "; } data.author += attribute.toString(); } } void TagLibExtractor::extract(ExtractionResult* result) { const QString fileUrl = result->inputUrl(); const QString mimeType = result->inputMimetype(); // Open the file readonly. Important if we're sandboxed. TagLib::FileStream stream(fileUrl.toUtf8().constData(), true); if (!stream.isOpen()) { qWarning() << "Unable to open file readonly: " << fileUrl; return; } TagLib::FileRef file(&stream, true); if (file.isNull()) { qWarning() << "Unable to open file: " << fileUrl; return; } TagLib::Tag* tags = file.tag(); result->addType(Type::Audio); ExtractedData data; if ((mimeType == QLatin1String("audio/mpeg")) || (mimeType == QLatin1String("audio/mpeg3")) || (mimeType == QLatin1String("audio/x-mpeg"))) { TagLib::MPEG::File mpegFile(&stream, TagLib::ID3v2::FrameFactory::instance(), true); if (mpegFile.hasID3v2Tag()) { extractId3Tags(mpegFile.ID3v2Tag(), data); } + } else if ((mimeType == QLatin1String("audio/x-aiff")) || (mimeType == QLatin1String("audio/wav"))) { + /* For some reason, TagLib::RIFF::AIFF::File and TagLib::RIFF::WAV::File tag() return + * only an invalid pointer. Use the dynamic_cast instead. */ + TagLib::ID3v2::Tag* ID3v2Tag = dynamic_cast(tags); + if (ID3v2Tag) { + extractId3Tags(ID3v2Tag, data); + } } else if (mimeType == QLatin1String("audio/mp4")) { TagLib::MP4::File mp4File(&stream, true); if (mp4File.hasMP4Tag()) { extractMp4Tags(mp4File.tag(), data); } } else if (mimeType == QLatin1String("audio/x-musepack")) { TagLib::MPC::File mpcFile(&stream, true); if (mpcFile.hasAPETag()) { extractApeTags(mpcFile.APETag(), data); } } else if (mimeType == QLatin1String("audio/x-ape")) { TagLib::APE::File apeFile(&stream, true); if (apeFile.hasAPETag()) { extractApeTags(apeFile.APETag(), data); } } else if (mimeType == QLatin1String("audio/x-wavpack")) { TagLib::WavPack::File wavpackFile(&stream, true); if (wavpackFile.hasAPETag()) { extractApeTags(wavpackFile.APETag(), data); } } else if (mimeType == QLatin1String("audio/flac")) { TagLib::FLAC::File flacFile(&stream, TagLib::ID3v2::FrameFactory::instance(), true); if (flacFile.hasXiphComment()) { extractVorbisTags(flacFile.xiphComment(), data); } } else if (mimeType == QLatin1String("audio/ogg") || mimeType == QLatin1String("audio/x-vorbis+ogg")) { TagLib::Ogg::Vorbis::File oggFile(&stream, true); if (oggFile.tag()) { extractVorbisTags(oggFile.tag(), data); } } else if (mimeType == QLatin1String("audio/opus") || mimeType == QLatin1String("audio/x-opus+ogg")) { TagLib::Ogg::Opus::File opusFile(&stream, true); if (opusFile.tag()) { extractVorbisTags(opusFile.tag(), data); } } else if (mimeType == QLatin1String("audio/x-ms-wma")) { /* For some reason, TagLib::ASF::File tag() returns only an invalid pointer. * Use the dynamic_cast instead. */ TagLib::ASF::Tag* asfTags = dynamic_cast(tags); if (asfTags) { extractAsfTags(asfTags, data); } } if (!tags->isEmpty()) { QString title = TStringToQString(tags->title()); if (!title.isEmpty()) { result->add(Property::Title, title); } QString comment = TStringToQString(tags->comment()); if (!comment.isEmpty()) { result->add(Property::Comment, comment); } if (data.genres.isEmpty()) { data.genres.append(tags->genre()); } for (uint i = 0; i < data.genres.size(); i++) { QString genre = TStringToQString(data.genres[i]).trimmed(); if (!genre.isEmpty()) { // Convert from int bool ok = false; int genreNum = genre.toInt(&ok); if (ok) { genre = TStringToQString(TagLib::ID3v1::genre(genreNum)); } result->add(Property::Genre, genre); } } const auto artistString = data.artists.isEmpty() ? TStringToQString(tags->artist()) : TStringToQString(data.artists).trimmed(); const auto artists = contactsFromString(artistString); for (auto& artist : artists) { result->add(Property::Artist, artist); } const auto composersString = TStringToQString(data.composers).trimmed(); const auto composers = contactsFromString(composersString); for (auto& comp : composers) { result->add(Property::Composer, comp); } const auto lyricistsString = TStringToQString(data.lyricists).trimmed(); const auto lyricists = contactsFromString(lyricistsString); for (auto& lyr : lyricists) { result->add(Property::Lyricist, lyr); } const auto album = TStringToQString(tags->album()); if (!album.isEmpty()) { result->add(Property::Album, album); const auto albumArtistsString = TStringToQString(data.albumArtists).trimmed(); const auto albumArtists = contactsFromString(albumArtistsString); for (auto& res : albumArtists) { result->add(Property::AlbumArtist, res); } } if (tags->track()) { result->add(Property::TrackNumber, tags->track()); } if (tags->year()) { result->add(Property::ReleaseYear, tags->year()); } QString locationsString = TStringToQString(data.location).trimmed(); QStringList locations = contactsFromString(locationsString); foreach(const QString& loc, locations) { result->add(Property::Location, loc); } QString performersString = TStringToQString(data.performer).trimmed(); QStringList performers = contactsFromString(performersString); foreach(const QString& per, performers) { result->add(Property::Performer, per); } QString ensembleString = TStringToQString(data.ensemble).trimmed(); QStringList ensembles = contactsFromString(ensembleString); foreach(const QString& ens, ensembles) { result->add(Property::Ensemble, ens); } QString arrangerString = TStringToQString(data.arranger).trimmed(); QStringList arrangers = contactsFromString(arrangerString); foreach(const QString& arr, arrangers) { result->add(Property::Arranger, arr); } QString conductorString = TStringToQString(data.conductor).trimmed(); QStringList conductors = contactsFromString(conductorString); foreach(const QString& arr, conductors) { result->add(Property::Conductor, arr); } QString publisherString = TStringToQString(data.publisher).trimmed(); QStringList publishers = contactsFromString(publisherString); foreach(const QString& arr, publishers) { result->add(Property::Publisher, arr); } QString copyrightString = TStringToQString(data.copyright).trimmed(); QStringList copyrights = contactsFromString(copyrightString); foreach(const QString& arr, copyrights) { result->add(Property::Copyright, arr); } QString labelString = TStringToQString(data.label).trimmed(); QStringList labels = contactsFromString(labelString); foreach(const QString& arr, labels) { result->add(Property::Label, arr); } QString authorString = TStringToQString(data.author).trimmed(); QStringList authors = contactsFromString(authorString); foreach(const QString& arr, authors) { result->add(Property::Author, arr); } QString languageString = TStringToQString(data.language).trimmed(); QStringList languages = contactsFromString(languageString); foreach(const QString& arr, languages) { result->add(Property::Language, arr); } QString licenseString = TStringToQString(data.license).trimmed(); QStringList licenses = contactsFromString(licenseString); foreach(const QString& arr, licenses) { result->add(Property::License, arr); } QString compilationString = TStringToQString(data.compilation).trimmed(); QStringList compilations = contactsFromString(compilationString); foreach(const QString& arr, compilations) { result->add(Property::Compilation, arr); } QString lyricsString = TStringToQString(data.lyrics).trimmed(); if (!lyricsString.isEmpty()) { result->add(Property::Lyrics, lyricsString); } if (data.opus.isValid()) { result->add(Property::Opus, data.opus); } if (data.discNumber.isValid()) { result->add(Property::DiscNumber, data.discNumber); } if (data.rating.isValid()) { result->add(Property::Rating, data.rating); } if (!data.replayGainAlbumGain.isEmpty()) { /* remove " dB" suffix */ if (data.replayGainAlbumGain.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { data.replayGainAlbumGain.chop(3); } bool success = false; double replayGainAlbumGain = data.replayGainAlbumGain.toDouble(&success); if (success) { result->add(Property::ReplayGainAlbumGain, replayGainAlbumGain); } } if (!data.replayGainAlbumPeak.isEmpty()) { bool success = false; double replayGainAlbumPeak = data.replayGainAlbumPeak.toDouble(&success); if (success) { result->add(Property::ReplayGainAlbumPeak, replayGainAlbumPeak); } } if (!data.replayGainTrackGain.isEmpty()) { /* remove " dB" suffix */ if (data.replayGainTrackGain.endsWith(QStringLiteral(" dB"), Qt::CaseInsensitive)) { data.replayGainTrackGain.chop(3); } bool success = false; double replayGainTrackGain = data.replayGainTrackGain.toDouble(&success); if (success) { result->add(Property::ReplayGainTrackGain, replayGainTrackGain); } } if (!data.replayGainTrackPeak.isEmpty()) { bool success = false; double replayGainTrackPeak = data.replayGainTrackPeak.toDouble(&success); if (success) { result->add(Property::ReplayGainTrackPeak, replayGainTrackPeak); } } } TagLib::AudioProperties* audioProp = file.audioProperties(); if (audioProp) { if (audioProp->length()) { // What about the xml duration? result->add(Property::Duration, audioProp->length()); } if (audioProp->bitrate()) { result->add(Property::BitRate, audioProp->bitrate() * 1000); } if (audioProp->channels()) { result->add(Property::Channels, audioProp->channels()); } if (audioProp->sampleRate()) { result->add(Property::SampleRate, audioProp->sampleRate()); } } } // TAG information (incomplete). // https://xiph.org/vorbis/doc/v-comment.html // http://help.mp3tag.de/main_tags.html // http://id3.org/ // https://www.legroom.net/2009/05/09/ogg-vorbis-and-flac-comment-field-recommendations // https://kodi.wiki/view/Music_tagging#Tags_Kodi_reads // -- FLAC/OGG -- // Artist: ARTIST, PERFORMER // Album artist: ALBUMARTIST // Composer: COMPOSER // Lyricist: LYRICIST // Conductor: CONDUCTOR // Disc number: DISCNUMBER // Total discs: TOTALDISCS, DISCTOTAL // Track number: TRACKNUMBER // Total tracks: TOTALTRACKS, TRACKTOTAL // Genre: GENRE // -- ID3v2 -- // Artist: TPE1 // Album artist: TPE2 // Composer: TCOM // Lyricist: TEXT // Conductor: TPE3 // Disc number[/total dics]: TPOS // Track number[/total tracks]: TRCK // Genre: TCON