Fixed scryfall images download for PUMA set;

This commit is contained in:
Oleg Agafonov 2018-11-12 02:23:11 +04:00
parent b298a621fb
commit 0b089895a7
2 changed files with 24 additions and 10 deletions

View file

@ -250,7 +250,9 @@ public enum ScryfallImageSource implements CardImageSource {
String localizedCode = languageAliases.getOrDefault(preferredLanguage, defaultCode);
// loc example: https://api.scryfall.com/cards/xln/121/ru?format=image
// TODO: do not use API at all? It's can help with scryfall request limits (1 request instead 2)
// WARNING, some cards haven't direct images and uses random GUID:
// As example: Raging Ravine - https://scryfall.com/card/uma/249/raging-ravine
// https://img.scryfall.com/cards/large/front/5/4/54f41726-e0bb-4154-a2db-4b68b50f5032.jpg
String baseUrl = null;
String alternativeUrl = null;
@ -272,12 +274,19 @@ public enum ScryfallImageSource implements CardImageSource {
}
}
// special card number like "103a" already compatible
// special card number like "103a" and "U123" already compatible
if (baseUrl == null && card.isCollectorIdWithStr()) {
baseUrl = "https://img.scryfall.com/cards/large/" + localizedCode + "/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + ".jpg";
alternativeUrl = "https://img.scryfall.com/cards/large/" + defaultCode + "/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + ".jpg";
// WARNING, after 2018 it's not compatible and some new sets have GUID files instead card numbers
// TODO: replace card number links to API calls (need test with lands, alternative images and double faces), replace not working images by direct links
if (card.getCollectorId().startsWith("U")) {
// fix for Ultimate Box Topper (PUMA) -- need to use API
// ignored and go to API call at the end
} else {
baseUrl = "https://img.scryfall.com/cards/large/" + localizedCode + "/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + ".jpg";
alternativeUrl = "https://img.scryfall.com/cards/large/" + defaultCode + "/" + formatSetName(card.getSet()) + "/"
+ card.getCollectorId() + ".jpg";
}
}
// double faced cards do not supports by API (need direct link for img)

View file

@ -362,7 +362,7 @@ public final class CardUtil {
/**
* Parse card number as int (support base [123] and alternative numbers
* [123b]).
* [123b], [U123]).
*
* @param cardNumber origin card number
* @return int
@ -373,10 +373,15 @@ public final class CardUtil {
throw new IllegalArgumentException("Card number is empty.");
}
if (Character.isDigit(cardNumber.charAt(cardNumber.length() - 1))) {
return Integer.parseInt(cardNumber);
} else {
if (!Character.isDigit(cardNumber.charAt(0))) {
// U123
return Integer.parseInt(cardNumber.substring(1, cardNumber.length()));
} else if (!Character.isDigit(cardNumber.charAt(cardNumber.length() - 1))) {
// 123b
return Integer.parseInt(cardNumber.substring(0, cardNumber.length() - 1));
} else {
// 123
return Integer.parseInt(cardNumber);
}
}