diff --git a/src/filescanner.h b/src/filescanner.h --- a/src/filescanner.h +++ b/src/filescanner.h @@ -26,11 +26,7 @@ #include -namespace KFileMetaData { - -class ExtractorCollection; - -} +#include namespace Baloo { @@ -58,6 +54,8 @@ std::unique_ptr d; + QString checkForMultipleEntries(KFileMetaData::Property::Property property); + }; #endif // FILESCANNER_H diff --git a/src/filescanner.cpp b/src/filescanner.cpp --- a/src/filescanner.cpp +++ b/src/filescanner.cpp @@ -36,6 +36,7 @@ #endif #include +#include class FileScannerPrivate { @@ -112,17 +113,18 @@ void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) { #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND + auto artistString = checkForMultipleEntries(KFileMetaData::Property::Artist); + auto albumArtistString = checkForMultipleEntries(KFileMetaData::Property::AlbumArtist); + auto genreString = checkForMultipleEntries(KFileMetaData::Property::Genre); + auto composerString = checkForMultipleEntries(KFileMetaData::Property::Composer); + auto lyricistString = checkForMultipleEntries(KFileMetaData::Property::Lyricist); + auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); auto durationProperty = d->mAllProperties.find(KFileMetaData::Property::Duration); - auto artistProperty = d->mAllProperties.find(KFileMetaData::Property::Artist); auto albumProperty = d->mAllProperties.find(KFileMetaData::Property::Album); - auto albumArtistProperty = d->mAllProperties.find(KFileMetaData::Property::AlbumArtist); auto trackNumberProperty = d->mAllProperties.find(KFileMetaData::Property::TrackNumber); auto discNumberProperty = d->mAllProperties.find(KFileMetaData::Property::DiscNumber); - auto genreProperty = d->mAllProperties.find(KFileMetaData::Property::Genre); auto yearProperty = d->mAllProperties.find(KFileMetaData::Property::ReleaseYear); - auto composerProperty = d->mAllProperties.find(KFileMetaData::Property::Composer); - auto lyricistProperty = d->mAllProperties.find(KFileMetaData::Property::Lyricist); auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); @@ -132,12 +134,28 @@ auto fileData = KFileMetaData::UserMetaData(localFileName); #endif - if (albumProperty != d->mAllProperties.end()) { - trackData.setAlbumName(albumProperty->toString()); + if (!artistString.isEmpty()) { + trackData.setArtist(artistString); + } + + if (!albumArtistString.isEmpty()) { + trackData.setAlbumArtist(albumArtistString); + } + + if (genreString.isEmpty()) { + trackData.setGenre(genreString); } - if (artistProperty != d->mAllProperties.end()) { - trackData.setArtist(artistProperty->toStringList().join(QStringLiteral(", "))); + if (composerString.isEmpty()) { + trackData.setComposer(composerString); + } + + if (lyricistString.isEmpty()) { + trackData.setLyricist(lyricistString); + } + + if (albumProperty != d->mAllProperties.end()) { + trackData.setAlbumName(albumProperty->toString()); } if (durationProperty != d->mAllProperties.end()) { @@ -158,10 +176,6 @@ trackData.setDiscNumber(1); } - if (albumArtistProperty != d->mAllProperties.end()) { - trackData.setAlbumArtist(albumArtistProperty->toStringList().join(QStringLiteral(", "))); - } - if (yearProperty != d->mAllProperties.end()) { trackData.setYear(yearProperty->toInt()); } @@ -178,18 +192,6 @@ trackData.setSampleRate(sampleRateProperty->toInt()); } - if (genreProperty != d->mAllProperties.end()) { - trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); - } - - if (composerProperty != d->mAllProperties.end()) { - trackData.setComposer(composerProperty->toStringList().join(QStringLiteral(", "))); - } - - if (lyricistProperty != d->mAllProperties.end()) { - trackData.setLyricist(lyricistProperty->toStringList().join(QStringLiteral(", "))); - } - if (trackData.artist().isEmpty()) { trackData.setArtist(trackData.albumArtist()); } @@ -232,3 +234,23 @@ Q_UNUSED(trackData) #endif } + +QString FileScanner::checkForMultipleEntries(KFileMetaData::Property::Property property) +{ + if (d->mAllProperties.count(property) > 1) { + auto propertyList = d->mAllProperties.values(property); + return QLocale().createSeparatedList(QVariant(propertyList).toStringList()); + } else { + auto variantResult = d->mAllProperties.find(property); + if (variantResult != d->mAllProperties.end()) { + auto value = variantResult.value(); + if (value.type() == QVariant::List || value.type() == QVariant::StringList) { + return QLocale().createSeparatedList(value.toStringList()); + } else { + return value.toString(); + } + } else { + return QString(); + } + } +}