mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[M15] Added temp. fix for image download of M15 cards from Wizards side. Problems caused by new web design of wizards. Images are now added as png files. Png images are saved with a jpg suffix name but they are correctly displayed in XMage. Needs more work for a clean solution.
This commit is contained in:
parent
63612b4291
commit
03e6ccf4ab
1 changed files with 50 additions and 25 deletions
|
@ -69,36 +69,61 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
private Map<String, String> getSetLinks(String cardSet) {
|
||||
Map<String, String> setLinks = new HashMap<>();
|
||||
try {
|
||||
Document doc = Jsoup.connect("http://www.wizards.com/magic/tcg/article.aspx?x=mtg/tcg/" + setsAliases.get(cardSet)).get();
|
||||
Elements cardsImages = doc.select("img[height$=370]");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
String cardName = normalizeName(cardsImages.get(i).attr("title"));
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
|
||||
int landNumber = 1;
|
||||
while (setLinks.get((cardName + landNumber).toLowerCase()) != null) {
|
||||
landNumber++;
|
||||
String urlDocument;
|
||||
if (cardSet.equals("M15")) {
|
||||
urlDocument = "http://magic.wizards.com/en/content/magic-2015-core-set-card-set-archive-products-game-info";
|
||||
Document doc = Jsoup.connect(urlDocument).get();
|
||||
Elements cardsImages = doc.select("div.advanced-card img");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
String cardName = normalizeName(cardsImages.get(i).attr("alt"));
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
|
||||
int landNumber = 1;
|
||||
while (setLinks.get((cardName + landNumber).toLowerCase()) != null) {
|
||||
landNumber++;
|
||||
}
|
||||
cardName += landNumber;
|
||||
}
|
||||
cardName += landNumber;
|
||||
setLinks.put(cardName.toLowerCase(), cardsImages.get(i).attr("src"));
|
||||
} else {
|
||||
setLinks.put(Integer.toString(i), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
setLinks.put(cardName.toLowerCase(), cardsImages.get(i).attr("src"));
|
||||
} else {
|
||||
setLinks.put(Integer.toString(i), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
}
|
||||
|
||||
cardsImages = doc.select("img[height$=470]");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
String cardName = normalizeName(cardsImages.get(i).attr("title"));
|
||||
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
String[] cardNames = cardName.replace(")", "").split(" \\(");
|
||||
for (String name : cardNames) {
|
||||
setLinks.put(name.toLowerCase(), cardsImages.get(i).attr("src"));
|
||||
|
||||
} else {
|
||||
urlDocument = "http://www.wizards.com/magic/tcg/article.aspx?x=mtg/tcg/" + setsAliases.get(cardSet);
|
||||
Document doc = Jsoup.connect(urlDocument).get();
|
||||
Elements cardsImages = doc.select("img[height$=370]");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
String cardName = normalizeName(cardsImages.get(i).attr("title"));
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
|
||||
int landNumber = 1;
|
||||
while (setLinks.get((cardName + landNumber).toLowerCase()) != null) {
|
||||
landNumber++;
|
||||
}
|
||||
cardName += landNumber;
|
||||
}
|
||||
setLinks.put(cardName.toLowerCase(), cardsImages.get(i).attr("src"));
|
||||
} else {
|
||||
setLinks.put(Integer.toString(i), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
} else {
|
||||
setLinks.put(Integer.toString(i), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
|
||||
cardsImages = doc.select("img[height$=470]");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
String cardName = normalizeName(cardsImages.get(i).attr("title"));
|
||||
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
String[] cardNames = cardName.replace(")", "").split(" \\(");
|
||||
for (String name : cardNames) {
|
||||
setLinks.put(name.toLowerCase(), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
} else {
|
||||
setLinks.put(Integer.toString(i), cardsImages.get(i).attr("src"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception when parsing the wizards page: " + ex.getMessage());
|
||||
|
|
Loading…
Reference in a new issue