Merge pull request #1160 from ctrlaltca/image_blacklist

Small improvements to card image downloading
This commit is contained in:
ctrlaltca 2015-06-24 09:57:30 +02:00
commit 9f24728301
3 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "carddatabase.h"
#include "settingscache.h"
#include <QCryptographicHash>
#include <QDir>
#include <QDirIterator>
#include <QFile>
@ -212,6 +213,9 @@ CardSet *PictureToLoad::getCurrentSet() const
return 0;
}
QStringList PictureLoader::md5Blacklist = QStringList()
<< "db0c48db407a907c16ade38de048a441"; // card back returned by gatherer when card is not found
PictureLoader::PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent)
: QObject(parent),
_picsPath(__picsPath), picDownload(_picDownload), picDownloadHq(_picDownloadHq),
@ -413,6 +417,18 @@ void PictureLoader::picDownloadFinished(QNetworkReply *reply)
}
const QByteArray &picData = reply->peek(reply->size()); //peek is used to keep the data in the buffer for use by QImageReader
// check if the image is blacklisted
QString md5sum = QCryptographicHash::hash(picData, QCryptographicHash::Md5).toHex();
if(md5Blacklist.contains(md5sum))
{
qDebug() << "Picture downloaded, but blacklisted (" << md5sum << "), will consider it as not found";
picDownloadFailed();
reply->deleteLater();
startNextPicDownload();
return;
}
QImage testImage;
QImageReader imgReader;

View file

@ -94,6 +94,7 @@ private:
bool picDownload, picDownloadHq, downloadRunning, loadQueueRunning;
void startNextPicDownload();
QString getPicUrl();
static QStringList md5Blacklist;
public:
PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent = 0);
~PictureLoader();

View file

@ -3,10 +3,11 @@
#include <QObject>
// the falbacks are used for cards without a muid
#define PIC_URL_DEFAULT "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!cardid!&type=card"
#define PIC_URL_FALLBACK "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!cardid!&type=card"
#define PIC_URL_FALLBACK "http://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"
#define PIC_URL_HQ_DEFAULT "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!cardid!&type=card"
#define PIC_URL_HQ_FALLBACK "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!cardid!&type=card"
#define PIC_URL_HQ_FALLBACK "http://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"
// size should be a multiple of 64
#define PIXMAPCACHE_SIZE_DEFAULT 2047
#define PIXMAPCACHE_SIZE_MIN 64