Fixed images downloading from scryfall (two sided cards)

This commit is contained in:
Oleg Agafonov 2018-01-07 04:41:07 +04:00
parent e9bd2852e6
commit 1280565928
2 changed files with 25 additions and 8 deletions

View file

@ -8,7 +8,7 @@ import java.util.Set;
import org.mage.plugins.card.images.CardDownloadData;
/**
* @author Quercitron
* @author Quercitron, JayDi85
*
*/
public enum ScryfallImageSource implements CardImageSource {
@ -217,17 +217,23 @@ public enum ScryfallImageSource implements CardImageSource {
@Override
public String generateURL(CardDownloadData card) throws Exception {
// special card number like "103a" already compatible
if (card.isCollectorIdWithStr()) {
return "https://img.scryfall.com/cards/large/en/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + ".jpg";
}
// double faced cards do not supporte by API (need direct link for img)
// example: https://img.scryfall.com/cards/large/en/xln/173b.jpg
if (card.isTwoFacedCard()) {
// double faced cards do not supporte by API (need direct link for img)
// example: https://img.scryfall.com/cards/large/en/xln/173b.jpg
return "https://img.scryfall.com/cards/large/en/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + (card.isSecondSide() ? "b" : "a") + ".jpg";
}else {
// single face cards support by single API call (redirect to img link)
// example: https://api.scryfall.com/cards/xln/121?format=image
return "https://api.scryfall.com/cards/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + "?format=image";
}
// basic cards by api call (redirect to img link)
// example: https://api.scryfall.com/cards/xln/121?format=image
return "https://api.scryfall.com/cards/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + "?format=image";
}
@Override

View file

@ -1,5 +1,7 @@
package org.mage.plugins.card.images;
import mage.util.CardUtil;
import java.util.Objects;
/**
@ -128,6 +130,15 @@ public class CardDownloadData {
return collectorId;
}
public Integer getCollectorIdAsInt() {
return CardUtil.parseCardNumberAsInt(collectorId);
}
public boolean isCollectorIdWithStr(){
// card have special numbers like "103a", "180b" (scryfall style)
return !getCollectorId().equals(getCollectorIdAsInt().toString());
}
public String getName() {
return name;
}