Merge pull request #1160 from ctrlaltca/image_blacklist
Small improvements to card image downloading
This commit is contained in:
commit
9f24728301
3 changed files with 20 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "carddatabase.h"
|
#include "carddatabase.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -212,6 +213,9 @@ CardSet *PictureToLoad::getCurrentSet() const
|
||||||
return 0;
|
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)
|
PictureLoader::PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
_picsPath(__picsPath), picDownload(_picDownload), picDownloadHq(_picDownloadHq),
|
_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
|
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;
|
QImage testImage;
|
||||||
|
|
||||||
QImageReader imgReader;
|
QImageReader imgReader;
|
||||||
|
|
|
@ -94,6 +94,7 @@ private:
|
||||||
bool picDownload, picDownloadHq, downloadRunning, loadQueueRunning;
|
bool picDownload, picDownloadHq, downloadRunning, loadQueueRunning;
|
||||||
void startNextPicDownload();
|
void startNextPicDownload();
|
||||||
QString getPicUrl();
|
QString getPicUrl();
|
||||||
|
static QStringList md5Blacklist;
|
||||||
public:
|
public:
|
||||||
PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent = 0);
|
PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent = 0);
|
||||||
~PictureLoader();
|
~PictureLoader();
|
||||||
|
|
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
#include <QObject>
|
#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_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_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
|
// size should be a multiple of 64
|
||||||
#define PIXMAPCACHE_SIZE_DEFAULT 2047
|
#define PIXMAPCACHE_SIZE_DEFAULT 2047
|
||||||
#define PIXMAPCACHE_SIZE_MIN 64
|
#define PIXMAPCACHE_SIZE_MIN 64
|
||||||
|
|
Loading…
Reference in a new issue