Commit 0242be13 authored by Tranter Madi's avatar Tranter Madi 🌧 Committed by Nate Graham
Browse files

Increase visibility of the embedded cover art

- Accept other ID3 embedded image besides FrontCover
- Show embedded images for non-indexed tracks

CCBUG: 418800
parent a1157c97
Pipeline #170904 passed with stage
in 9 minutes and 49 seconds
......@@ -7,7 +7,11 @@
#include "embeddedcoverageimageprovider.h"
#include <KFileMetaData/EmbeddedImageData>
#include <KFileMetaData/ExtractorCollection>
#include <KFileMetaData/SimpleExtractionResult>
#include <QImage>
#include <QMimeDatabase>
class AsyncImageResponse : public QQuickImageResponse, public QRunnable
{
......@@ -35,12 +39,25 @@ public:
void run() override
{
KFileMetaData::EmbeddedImageData embeddedImage;
QMimeDatabase mimeDatabase;
const auto fileMimeType = mimeDatabase.mimeTypeForFile(mId).name();
KFileMetaData::ExtractorCollection ec;
KFileMetaData::SimpleExtractionResult result(mId, fileMimeType, KFileMetaData::ExtractionResult::ExtractImageData);
auto extractors = ec.fetchExtractors(fileMimeType);
for (const auto& ex : extractors) {
ex->extract(&result);
}
auto imageData = embeddedImage.imageData(mId);
auto imageData = result.imageData();
if (!imageData.isEmpty()) {
if (imageData.contains(KFileMetaData::EmbeddedImageData::FrontCover)) {
mCoverImage = QImage::fromData(imageData[KFileMetaData::EmbeddedImageData::FrontCover]);
} else {
mCoverImage = QImage::fromData(imageData.values().first());
}
if (imageData.contains(KFileMetaData::EmbeddedImageData::FrontCover)) {
mCoverImage = QImage::fromData(imageData[KFileMetaData::EmbeddedImageData::FrontCover]);
auto newCoverImage = mCoverImage.scaled(mRequestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (!newCoverImage.isNull()) {
mCoverImage = std::move(newCoverImage);
......
......@@ -231,7 +231,12 @@ void FileScanner::scanProperties(const QString &localFileName, DataTypes::TrackD
return;
}
trackData[DataTypes::HasEmbeddedCover] = checkEmbeddedCoverImage(localFileName);
if (checkEmbeddedCoverImage(localFileName)) {
trackData[DataTypes::HasEmbeddedCover] = true;
trackData[DataTypes::ImageUrlRole] = QUrl(QLatin1String("image://cover/") + localFileName);
} else {
trackData[DataTypes::HasEmbeddedCover] = false;
}
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
const auto fileData = KFileMetaData::UserMetaData(localFileName);
......@@ -282,10 +287,8 @@ bool FileScanner::checkEmbeddedCoverImage(const QString &localFileName)
#if KF5FileMetaData_FOUND
const auto &imageData = d->mImageScanner.imageData(localFileName);
if (imageData.contains(KFileMetaData::EmbeddedImageData::FrontCover)) {
if (!imageData[KFileMetaData::EmbeddedImageData::FrontCover].isEmpty()) {
return true;
}
if (!imageData.isEmpty()) {
return true;
}
#else
Q_UNUSED(localFileName)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment