mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-30 17:14:58 +01:00
Minor code improvements to album cover loader
This commit is contained in:
parent
f77475dbfe
commit
5eda028af3
@ -36,6 +36,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QFile>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@ -418,33 +419,31 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(Task *task) {
|
|||||||
QByteArray image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(task->song.url().toLocalFile());
|
QByteArray image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(task->song.url().toLocalFile());
|
||||||
if (!image_data.isEmpty()) {
|
if (!image_data.isEmpty()) {
|
||||||
QImage image;
|
QImage image;
|
||||||
if (task->options.get_image_ && image.loadFromData(image_data)) {
|
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
|
||||||
return TryLoadResult(false, true, AlbumCoverLoaderResult::Type_Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
|
return TryLoadResult(false, !image.isNull(), AlbumCoverLoaderResult::Type_Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return TryLoadResult(false, true, AlbumCoverLoaderResult::Type_Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
|
return TryLoadResult(false, !image_data.isEmpty(), AlbumCoverLoaderResult::Type_Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cover_url.isLocalFile()) {
|
if (cover_url.isLocalFile()) {
|
||||||
QFile file(cover_url.toLocalFile());
|
QFile file(cover_url.toLocalFile());
|
||||||
if (file.exists()) {
|
if (file.exists() && file.open(QIODevice::ReadOnly)) {
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
QByteArray image_data = file.readAll();
|
||||||
QByteArray image_data = file.readAll();
|
file.close();
|
||||||
file.close();
|
QImage image;
|
||||||
QImage image;
|
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
|
||||||
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
|
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
||||||
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to open album cover file" << cover_url;
|
return TryLoadResult(false, !image_data.isEmpty(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
qLog(Error) << "Failed to open album cover file" << cover_url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (cover_url.scheme().isEmpty()) { // Assume a local file with no scheme.
|
else if (cover_url.scheme().isEmpty()) { // Assume a local file with no scheme.
|
||||||
QFile file(cover_url.path());
|
QFile file(cover_url.path());
|
||||||
@ -456,7 +455,7 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(Task *task) {
|
|||||||
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
return TryLoadResult(false, !image_data.isEmpty(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,21 +511,16 @@ void AlbumCoverLoader::RemoteFetchFinished(QNetworkReply *reply, const QUrl &cov
|
|||||||
QByteArray image_data = reply->readAll();
|
QByteArray image_data = reply->readAll();
|
||||||
QString mime_type = Utilities::MimeTypeFromData(image_data);
|
QString mime_type = Utilities::MimeTypeFromData(image_data);
|
||||||
QImage image;
|
QImage image;
|
||||||
if (task.options.get_image_data_) {
|
if (image.loadFromData(image_data)) {
|
||||||
if (image.loadFromData(image_data)) {
|
QImage image_scaled;
|
||||||
QImage image_scaled;
|
QImage image_thumbnail;
|
||||||
QImage image_thumbnail;
|
if (task.options.scale_output_image_) image_scaled = ImageUtils::ScaleAndPad(image, task.options.scale_output_image_, task.options.pad_output_image_, task.options.desired_height_);
|
||||||
if (task.options.scale_output_image_) image_scaled = ImageUtils::ScaleAndPad(image, task.options.scale_output_image_, task.options.pad_output_image_, task.options.desired_height_);
|
if (task.options.create_thumbnail_) image_thumbnail = ImageUtils::CreateThumbnail(image, task.options.pad_thumbnail_image_, task.options.thumbnail_size_);
|
||||||
if (task.options.create_thumbnail_) image_thumbnail = ImageUtils::CreateThumbnail(image, task.options.pad_thumbnail_image_, task.options.thumbnail_size_);
|
emit AlbumCoverLoaded(task.id, AlbumCoverLoaderResult(true, task.type, AlbumCoverImageResult(cover_url, mime_type, (task.options.get_image_data_ ? image_data : QByteArray()), image), image_scaled, image_thumbnail, task.art_updated));
|
||||||
emit AlbumCoverLoaded(task.id, AlbumCoverLoaderResult(true, task.type, AlbumCoverImageResult(cover_url, mime_type, (task.options.get_image_data_ ? image_data : QByteArray()), image), image_scaled, image_thumbnail, task.art_updated));
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qLog(Error) << "Unable to load album cover image" << cover_url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit AlbumCoverLoaded(task.id, AlbumCoverLoaderResult(true, task.type, AlbumCoverImageResult(cover_url, mime_type, image_data, QImage()), QImage(), QImage(), task.art_updated));
|
qLog(Error) << "Unable to load album cover image" << cover_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user