diff --git a/src/filescanner.h b/src/filescanner.h --- a/src/filescanner.h +++ b/src/filescanner.h @@ -28,11 +28,7 @@ #include -namespace KFileMetaData { - -class ExtractorCollection; - -} +#include namespace Baloo { @@ -60,6 +56,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 lyricsProperty = d->mAllProperties.find(KFileMetaData::Property::Lyrics); auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); @@ -133,12 +135,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 (composerString.isEmpty()) { + trackData.setComposer(composerString); + } + + if (lyricistString.isEmpty()) { + trackData.setLyricist(lyricistString); } - if (artistProperty != d->mAllProperties.end()) { - trackData.setArtist(artistProperty->toStringList().join(QStringLiteral(", "))); + if (albumProperty != d->mAllProperties.end()) { + trackData.setAlbumName(albumProperty->toString()); } if (durationProperty != d->mAllProperties.end()) { @@ -157,10 +175,6 @@ trackData.setDiscNumber(discNumberProperty->toInt()); } - if (albumArtistProperty != d->mAllProperties.end()) { - trackData.setAlbumArtist(albumArtistProperty->toStringList().join(QStringLiteral(", "))); - } - if (yearProperty != d->mAllProperties.end()) { trackData.setYear(yearProperty->toInt()); } @@ -177,6 +191,7 @@ trackData.setSampleRate(sampleRateProperty->toInt()); } +<<<<<<< HEAD if (genreProperty != d->mAllProperties.end()) { trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); } @@ -193,6 +208,8 @@ trackData.setLyrics(lyricsProperty->toString()); } +======= +>>>>>>> Check for string lists and multi-values in property map if (trackData.artist().isEmpty()) { trackData.setArtist(trackData.albumArtist()); } @@ -235,3 +252,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(); + } + } +}