From 846b426a7c21ea8bf37c42235cf2e8bb091f1152 Mon Sep 17 00:00:00 2001 From: Andrew Zwicky Date: Sun, 5 Aug 2018 16:21:53 -0500 Subject: [PATCH 1/4] 2497: Start to implement fallback on card image urls Return a list instead of a single url. This is the start of getting many possible urls instead of one. Functionally identical except that the primary url will be attempted for cards without a muid. --- cockatrice/src/pictureloader.cpp | 83 ++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/cockatrice/src/pictureloader.cpp b/cockatrice/src/pictureloader.cpp index 791bb223..9b5d0edd 100644 --- a/cockatrice/src/pictureloader.cpp +++ b/cockatrice/src/pictureloader.cpp @@ -197,51 +197,70 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString &setName, QString &corre return false; } -QString PictureLoaderWorker::getPicUrl() +QList PictureLoaderWorker::getAllPicUrls() { if (!picDownload) - return QString(); + return QList(); CardInfoPtr card = cardBeingDownloaded.getCard(); CardSetPtr set = cardBeingDownloaded.getCurrentSet(); - QString picUrl = QString(""); + QList urls = QList(); // if sets have been defined for the card, they can contain custom picUrls if (set) { - picUrl = card->getCustomPicURL(set->getShortName()); - if (!picUrl.isEmpty()) - return picUrl; + QString setCustomURL = card->getCustomPicURL(set->getShortName()); + + if (!setCustomURL.isEmpty()) { + urls.append(setCustomURL); + return urls; + } } // if a card has a muid, use the default url; if not, use the fallback int muid = set ? card->getMuId(set->getShortName()) : 0; - picUrl = muid ? settingsCache->getPicUrl() : settingsCache->getPicUrlFallback(); - picUrl.replace("!name!", QUrl::toPercentEncoding(card->getName())); - picUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getName().toLower())); - picUrl.replace("!corrected_name!", QUrl::toPercentEncoding(card->getCorrectedName())); - picUrl.replace("!corrected_name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower())); - picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); - if (set) { - // renamed from !setnumber! to !collectornumber! on 20160819. Remove the old one when convenient. - picUrl.replace("!setnumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); - picUrl.replace("!collectornumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + QList urlArray = QList(); + urlArray.append(settingsCache->getPicUrl()); + urlArray.append(settingsCache->getPicUrlFallback()); + + for(int i=0; i < 2; i++) { + QString originalUrl = urlArray[i]; + QString thisUrl = urlArray[i]; + thisUrl.replace("!name!", QUrl::toPercentEncoding(card->getName())); + thisUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getName().toLower())); + thisUrl.replace("!corrected_name!", QUrl::toPercentEncoding(card->getCorrectedName())); + thisUrl.replace("!corrected_name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower())); + thisUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); + if (set) { + // renamed from !setnumber! to !collectornumber! on 20160819. Remove the old one when convenient. + thisUrl.replace("!setnumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + thisUrl.replace("!collectornumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + + thisUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); + thisUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); + thisUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); + thisUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower())); + } + + if (thisUrl.contains("!name!") || + thisUrl.contains("!name_lower!") || + thisUrl.contains("!corrected_name!") || + thisUrl.contains("!corrected_name_lower!") || + thisUrl.contains("!setnumber!") || + thisUrl.contains("!setcode!") || + thisUrl.contains("!setcode_lower!") || + thisUrl.contains("!setname!") || + thisUrl.contains("!setname_lower!") || + thisUrl.contains("!cardid!")) { + qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << originalUrl; + } + else { + urls.append(thisUrl); + } - picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); - picUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); - picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); - picUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower())); } - if (picUrl.contains("!name!") || picUrl.contains("!name_lower!") || picUrl.contains("!corrected_name!") || - picUrl.contains("!corrected_name_lower!") || picUrl.contains("!setnumber!") || picUrl.contains("!setcode!") || - picUrl.contains("!setcode_lower!") || picUrl.contains("!setname!") || picUrl.contains("!setname_lower!") || - picUrl.contains("!cardid!")) { - qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl; - return QString(); - } - - return picUrl; + return urls; } void PictureLoaderWorker::startNextPicDownload() @@ -256,12 +275,12 @@ void PictureLoaderWorker::startNextPicDownload() cardBeingDownloaded = cardsToDownload.takeFirst(); - QString picUrl = getPicUrl(); - if (picUrl.isEmpty()) { + QList picUrls = getAllPicUrls(); + if (picUrls.isEmpty()) { downloadRunning = false; picDownloadFailed(); } else { - QUrl url(picUrl); + QUrl url(picUrls[0]); // For now, just use the first one, like always. QNetworkRequest req(url); qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url(); From e467698d72eb1d96d7e4dbf6c34b68117e1d3787 Mon Sep 17 00:00:00 2001 From: Andrew Zwicky Date: Sun, 5 Aug 2018 17:43:28 -0500 Subject: [PATCH 2/4] 2497: Forgot to check in .h file --- cockatrice/src/pictureloader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/pictureloader.h b/cockatrice/src/pictureloader.h index d6bf1f08..427577cf 100644 --- a/cockatrice/src/pictureloader.h +++ b/cockatrice/src/pictureloader.h @@ -57,7 +57,7 @@ private: PictureToLoad cardBeingDownloaded; bool picDownload, downloadRunning, loadQueueRunning; void startNextPicDownload(); - QString getPicUrl(); + QList getAllPicUrls(); bool cardImageExistsOnDisk(QString &setName, QString &correctedCardname); bool imageIsBlackListed(const QByteArray &picData); private slots: From 8239539946bc59e65dae47fefe86063c3e73d5e7 Mon Sep 17 00:00:00 2001 From: Andrew Zwicky Date: Wed, 8 Aug 2018 22:42:22 -0500 Subject: [PATCH 3/4] 2479: Initial work on downloading cards through fallback URLs. This change will add in the ability to proceed to the next URL should the first one fail. First trial shows that it's working, but needs more refinement. --- cockatrice/src/pictureloader.cpp | 146 +++++++++++++++++-------------- cockatrice/src/pictureloader.h | 8 ++ 2 files changed, 90 insertions(+), 64 deletions(-) diff --git a/cockatrice/src/pictureloader.cpp b/cockatrice/src/pictureloader.cpp index 9b5d0edd..d9e259c4 100644 --- a/cockatrice/src/pictureloader.cpp +++ b/cockatrice/src/pictureloader.cpp @@ -43,12 +43,21 @@ public: } }; -PictureToLoad::PictureToLoad(CardInfoPtr _card) : card(std::move(_card)), setIndex(0) +PictureToLoad::PictureToLoad(CardInfoPtr _card) : + card(std::move(_card)), + customSetPicturesChecked(false), + urlInitialized(false), + setIndex(0), + urlIndex(0) { if (card) { sortedSets = card->getSets(); qSort(sortedSets.begin(), sortedSets.end(), SetDownloadPriorityComparator()); } + + // This will be replaced with an expandable list ideally + urlTemplates.append(settingsCache->getPicUrl()); + urlTemplates.append(settingsCache->getPicUrlFallback()); } bool PictureToLoad::nextSet() @@ -56,9 +65,42 @@ bool PictureToLoad::nextSet() if (setIndex == sortedSets.size() - 1) return false; ++setIndex; + customSetPicturesChecked = false; return true; } +bool PictureToLoad::nextUrl() +{ + if (!customSetPicturesChecked) { + customSetPicturesChecked = true; + + QString setCustomURL = card->getCustomPicURL(getCurrentSet()->getShortName()); + + if (!setCustomURL.isEmpty()) { + currentUrl = setCustomURL; + return true; + } + } + + for ( ; urlIndex < urlTemplates.size(); ) { + currentUrl = transformUrl(); + urlIndex++; + + if (!currentUrl.isEmpty()) + return true; + } + + return false; +} + +QString PictureToLoad::getCurrentUrl() +{ + if (!urlInitialized) + nextUrl(); + + return currentUrl; +} + QString PictureToLoad::getSetName() const { if (setIndex < sortedSets.size()) @@ -197,70 +239,45 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString &setName, QString &corre return false; } -QList PictureLoaderWorker::getAllPicUrls() +QString PictureToLoad::transformUrl() const { - if (!picDownload) - return QList(); - - CardInfoPtr card = cardBeingDownloaded.getCard(); - CardSetPtr set = cardBeingDownloaded.getCurrentSet(); - QList urls = QList(); - - // if sets have been defined for the card, they can contain custom picUrls - if (set) { - QString setCustomURL = card->getCustomPicURL(set->getShortName()); - - if (!setCustomURL.isEmpty()) { - urls.append(setCustomURL); - return urls; - } - } + QString transformedUrl = urlTemplates[urlIndex]; + CardSetPtr set = getCurrentSet(); // if a card has a muid, use the default url; if not, use the fallback int muid = set ? card->getMuId(set->getShortName()) : 0; - QList urlArray = QList(); - urlArray.append(settingsCache->getPicUrl()); - urlArray.append(settingsCache->getPicUrlFallback()); - - for(int i=0; i < 2; i++) { - QString originalUrl = urlArray[i]; - QString thisUrl = urlArray[i]; - thisUrl.replace("!name!", QUrl::toPercentEncoding(card->getName())); - thisUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getName().toLower())); - thisUrl.replace("!corrected_name!", QUrl::toPercentEncoding(card->getCorrectedName())); - thisUrl.replace("!corrected_name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower())); - thisUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); - if (set) { - // renamed from !setnumber! to !collectornumber! on 20160819. Remove the old one when convenient. - thisUrl.replace("!setnumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); - thisUrl.replace("!collectornumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); - - thisUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); - thisUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); - thisUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); - thisUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower())); - } - - if (thisUrl.contains("!name!") || - thisUrl.contains("!name_lower!") || - thisUrl.contains("!corrected_name!") || - thisUrl.contains("!corrected_name_lower!") || - thisUrl.contains("!setnumber!") || - thisUrl.contains("!setcode!") || - thisUrl.contains("!setcode_lower!") || - thisUrl.contains("!setname!") || - thisUrl.contains("!setname_lower!") || - thisUrl.contains("!cardid!")) { - qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << originalUrl; - } - else { - urls.append(thisUrl); - } + transformedUrl.replace("!name!", QUrl::toPercentEncoding(card->getName())); + transformedUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getName().toLower())); + transformedUrl.replace("!corrected_name!", QUrl::toPercentEncoding(card->getCorrectedName())); + transformedUrl.replace("!corrected_name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower())); + transformedUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); + if (set) { + // renamed from !setnumber! to !collectornumber! on 20160819. Remove the old one when convenient. + transformedUrl.replace("!setnumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + transformedUrl.replace("!collectornumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + transformedUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); + transformedUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); + transformedUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); + transformedUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower())); } - return urls; + if (transformedUrl.contains("!name!") || + transformedUrl.contains("!name_lower!") || + transformedUrl.contains("!corrected_name!") || + transformedUrl.contains("!corrected_name_lower!") || + transformedUrl.contains("!setnumber!") || + transformedUrl.contains("!setcode!") || + transformedUrl.contains("!setcode_lower!") || + transformedUrl.contains("!setname!") || + transformedUrl.contains("!setname_lower!") || + transformedUrl.contains("!cardid!")) { + qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << urlTemplates[urlIndex]; + return QString(); + } + + return transformedUrl; } void PictureLoaderWorker::startNextPicDownload() @@ -275,29 +292,30 @@ void PictureLoaderWorker::startNextPicDownload() cardBeingDownloaded = cardsToDownload.takeFirst(); - QList picUrls = getAllPicUrls(); - if (picUrls.isEmpty()) { + QString picUrl = cardBeingDownloaded.getCurrentUrl(); + + if (picUrl.isEmpty()) { downloadRunning = false; picDownloadFailed(); } else { - QUrl url(picUrls[0]); // For now, just use the first one, like always. + QUrl url(picUrl); // For now, just use the first one, like always. QNetworkRequest req(url); - qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url(); + qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url().toString(); networkManager->get(req); } } void PictureLoaderWorker::picDownloadFailed() { - if (cardBeingDownloaded.nextSet()) { - qDebug() << "Picture NOT found, download failed, moving to next set (newset: " + if (cardBeingDownloaded.nextUrl()) { + qDebug() << "Picture NOT found, download failed, moving to next url (newurl: " << cardBeingDownloaded.getCurrentUrl() << "set: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getName() << ")"; mutex.lock(); loadQueue.prepend(cardBeingDownloaded); mutex.unlock(); } else { - qDebug() << "Picture NOT found, download failed, no more sets to try: BAILING OUT (oldset: " + qDebug() << "Picture NOT found, download failed, no more url combinations to try: BAILING OUT (oldset: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getName() << ")"; imageLoaded(cardBeingDownloaded.getCard(), QImage()); cardBeingDownloaded.clear(); diff --git a/cockatrice/src/pictureloader.h b/cockatrice/src/pictureloader.h index 427577cf..ac3d90f1 100644 --- a/cockatrice/src/pictureloader.h +++ b/cockatrice/src/pictureloader.h @@ -18,7 +18,12 @@ private: CardInfoPtr card; QList sortedSets; + QList urlTemplates; + QString currentUrl; + bool customSetPicturesChecked; + bool urlInitialized; int setIndex; + int urlIndex; public: PictureToLoad(CardInfoPtr _card = CardInfoPtr()); @@ -31,8 +36,11 @@ public: card.clear(); } CardSetPtr getCurrentSet() const; + QString getCurrentUrl(); QString getSetName() const; + QString transformUrl() const; bool nextSet(); + bool nextUrl(); }; class PictureLoaderWorker : public QObject From cbd430555f12f819559f7a4e21d591c6fff3df6d Mon Sep 17 00:00:00 2001 From: Andrew Zwicky Date: Thu, 9 Aug 2018 23:50:01 -0500 Subject: [PATCH 4/4] 2479: Working Url traversal Url checking is now working as expected. In set order, starting with custom sets, then going in priority order by url template order, Urls will checked, and the first successful one will be used. --- cockatrice/src/pictureloader.cpp | 117 ++++++++++++++++++++----------- cockatrice/src/pictureloader.h | 9 ++- 2 files changed, 81 insertions(+), 45 deletions(-) diff --git a/cockatrice/src/pictureloader.cpp b/cockatrice/src/pictureloader.cpp index d9e259c4..04522931 100644 --- a/cockatrice/src/pictureloader.cpp +++ b/cockatrice/src/pictureloader.cpp @@ -45,19 +45,39 @@ public: PictureToLoad::PictureToLoad(CardInfoPtr _card) : card(std::move(_card)), - customSetPicturesChecked(false), - urlInitialized(false), setIndex(0), urlIndex(0) { - if (card) { - sortedSets = card->getSets(); - qSort(sortedSets.begin(), sortedSets.end(), SetDownloadPriorityComparator()); - } - // This will be replaced with an expandable list ideally urlTemplates.append(settingsCache->getPicUrl()); urlTemplates.append(settingsCache->getPicUrlFallback()); + + if (card) { + sortedSets = card->getSets(); + qSort(sortedSets.begin(), sortedSets.end(), SetDownloadPriorityComparator()); + populateSetUrls(); + } +} + +void PictureToLoad::populateSetUrls() +{ + currentSetUrls.clear(); + + QString setCustomURL = card->getCustomPicURL(getCurrentSet()->getShortName()); + + if (!setCustomURL.isEmpty()) { + currentSetUrls.append(setCustomURL); + } + + for (int i; i< urlTemplates.size(); i++) { + QString transformedUrl = transformUrl(urlTemplates[i]); + + if (!transformedUrl.isEmpty()) { + currentSetUrls.append(transformedUrl); + } + } + + urlIndex = 0; } bool PictureToLoad::nextSet() @@ -65,40 +85,52 @@ bool PictureToLoad::nextSet() if (setIndex == sortedSets.size() - 1) return false; ++setIndex; - customSetPicturesChecked = false; + populateSetUrls(); return true; } bool PictureToLoad::nextUrl() { - if (!customSetPicturesChecked) { - customSetPicturesChecked = true; - - QString setCustomURL = card->getCustomPicURL(getCurrentSet()->getShortName()); - - if (!setCustomURL.isEmpty()) { - currentUrl = setCustomURL; - return true; + /* If we are past the list of urls currently populated + * for this set, try to move to the next set. This + * will repopulate the list of urls. + */ + if (urlIndex == currentSetUrls.size() - 1) { + if (nextSet()){ + // There is a new set to check, so test the Url again + // UrlIndex would have been reset inside nextSet() + if (urlIndex == currentSetUrls.size() - 1) { + // The newly populated set did not yield any usable Urls. + return false; + } + else + { + // Set was updated, UrlIndex is reset, proceed checking Urls. + return true; + } + } + else + { + // Because there is not another set, there are not more Urls to check. + return false; } } - - for ( ; urlIndex < urlTemplates.size(); ) { - currentUrl = transformUrl(); - urlIndex++; - - if (!currentUrl.isEmpty()) - return true; + else + { + // We are still in the middle of the list, increment and return + // This must be inside the else to protect against UrlIndex being incremented + // when the set is moved to the next set. + ++urlIndex; + return true; } - - return false; } -QString PictureToLoad::getCurrentUrl() +QString PictureToLoad::getCurrentUrl() const { - if (!urlInitialized) - nextUrl(); - - return currentUrl; + if (urlIndex < currentSetUrls.size()) + return currentSetUrls[urlIndex]; + else + return QString(""); } QString PictureToLoad::getSetName() const @@ -163,13 +195,13 @@ void PictureLoaderWorker::processLoadQueue() QString setName = cardBeingLoaded.getSetName(); QString cardName = cardBeingLoaded.getCard()->getName(); QString correctedCardName = cardBeingLoaded.getCard()->getCorrectedName(); - qDebug() << "Trying to load picture (set: " << setName << " card: " << cardName << ")"; + qDebug() << "Trying to load picture for card:" << cardName << " from set:" << setName; if (cardImageExistsOnDisk(setName, correctedCardName)) continue; if (picDownload) { - qDebug() << "Picture NOT found, trying to download (set: " << setName << " card: " << cardName << ")"; + qDebug() << "Picture not found, trying to download"; cardsToDownload.append(cardBeingLoaded); cardBeingLoaded.clear(); if (!downloadRunning) @@ -239,9 +271,9 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString &setName, QString &corre return false; } -QString PictureToLoad::transformUrl() const +QString PictureToLoad::transformUrl(QString urlTemplate) const { - QString transformedUrl = urlTemplates[urlIndex]; + QString transformedUrl = urlTemplate; CardSetPtr set = getCurrentSet(); // if a card has a muid, use the default url; if not, use the fallback @@ -257,6 +289,7 @@ QString PictureToLoad::transformUrl() const // renamed from !setnumber! to !collectornumber! on 20160819. Remove the old one when convenient. transformedUrl.replace("!setnumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); transformedUrl.replace("!collectornumber!", QUrl::toPercentEncoding(card->getCollectorNumber(set->getShortName()))); + transformedUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); transformedUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); transformedUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); @@ -301,7 +334,8 @@ void PictureLoaderWorker::startNextPicDownload() QUrl url(picUrl); // For now, just use the first one, like always. QNetworkRequest req(url); - qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url().toString(); + qDebug() << "Trying to download picture for card:" << cardBeingDownloaded.getCard()->getName() + << " from set:" << cardBeingDownloaded.getSetName() << "from url:" << picUrl; networkManager->get(req); } } @@ -309,14 +343,15 @@ void PictureLoaderWorker::startNextPicDownload() void PictureLoaderWorker::picDownloadFailed() { if (cardBeingDownloaded.nextUrl()) { - qDebug() << "Picture NOT found, download failed, moving to next url (newurl: " << cardBeingDownloaded.getCurrentUrl() << "set: " - << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getName() << ")"; + //qDebug() << "Picture NOT found, download failed, moving to next url (url: " << cardBeingDownloaded.getCurrentUrl() + // << " set: " << cardBeingDownloaded.getSetName() + // << " card: " << cardBeingDownloaded.getCard()->getName() << ")"; mutex.lock(); loadQueue.prepend(cardBeingDownloaded); mutex.unlock(); } else { - qDebug() << "Picture NOT found, download failed, no more url combinations to try: BAILING OUT (oldset: " - << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getName() << ")"; + qDebug() << "Picture NOT found, download failed, no more url combinations to try: BAILING OUT for card: " + << cardBeingDownloaded.getCard()->getName() << ")"; imageLoaded(cardBeingDownloaded.getCard(), QImage()); cardBeingDownloaded.clear(); } @@ -339,7 +374,7 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) if (statusCode == 301 || statusCode == 302) { QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); QNetworkRequest req(redirectUrl); - qDebug() << "following redirect:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url(); + qDebug() << "following redirect:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url().toString(); networkManager->get(req); return; } @@ -382,7 +417,9 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) } imageLoaded(cardBeingDownloaded.getCard(), testImage); + qDebug() << "Image successfully downloaded from " << reply->request().url().toString(); } else { + qDebug() << "Possible picture at " << reply->request().url().toString() << " could not be loaded"; picDownloadFailed(); } diff --git a/cockatrice/src/pictureloader.h b/cockatrice/src/pictureloader.h index ac3d90f1..57c9316d 100644 --- a/cockatrice/src/pictureloader.h +++ b/cockatrice/src/pictureloader.h @@ -19,9 +19,7 @@ private: CardInfoPtr card; QList sortedSets; QList urlTemplates; - QString currentUrl; - bool customSetPicturesChecked; - bool urlInitialized; + QList currentSetUrls; int setIndex; int urlIndex; @@ -36,11 +34,12 @@ public: card.clear(); } CardSetPtr getCurrentSet() const; - QString getCurrentUrl(); + QString getCurrentUrl() const; QString getSetName() const; - QString transformUrl() const; + QString transformUrl(QString urlTemplate) const; bool nextSet(); bool nextUrl(); + void populateSetUrls(); }; class PictureLoaderWorker : public QObject