1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-03 09:18:59 -09:00

* Update Gatherer Downloader.

This commit is contained in:
LevelX2 2015-03-29 03:48:55 +02:00
parent 93e573e719
commit 45aa5f675c
8 changed files with 211 additions and 116 deletions
Mage.Client/src/main/java/org/mage/plugins/card
Mage.Sets/src/mage/sets/anthologyjacevschandra
Mage/src/mage/cards

View file

@ -10,5 +10,6 @@ public interface CardImageSource {
String generateURL(CardDownloadData card) throws Exception;
String generateTokenUrl(CardDownloadData card);
String getSourceName();
Float getAverageSize();
}

View file

@ -96,6 +96,11 @@ public class MagicCardsImageSource implements CardImageSource {
private static final long serialVersionUID = 1L;
};
@Override
public String getSourceName() {
return "magiccards.info";
}
public static CardImageSource getInstance() {
if (instance == null) {
instance = new MagicCardsImageSource();

View file

@ -50,6 +50,11 @@ public class MtgImageSource implements CardImageSource {
return instance;
}
@Override
public String getSourceName() {
return "mtgimage.com";
}
@Override
public String generateURL(CardDownloadData card) throws Exception {
Integer collectorId = card.getCollectorId();

View file

@ -1,14 +1,14 @@
package org.mage.plugins.card.dl.sources;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.mage.plugins.card.images.CardDownloadData;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author North
@ -26,74 +26,174 @@ public class WizardCardsImageSource implements CardImageSource {
return instance;
}
@Override
public String getSourceName() {
return "WOTC Gatherer";
}
public WizardCardsImageSource() {
sets = new HashMap<>();
setsAliases = new HashMap<>();
setsAliases.put("DTK", "magicorigins/cig");
setsAliases.put("DTK", "modernmasters2015/cig");
setsAliases.put("FRF", "fatereforged/cig");
setsAliases.put("C14", "commander2014/cig");
setsAliases.put("KTK", "khansoftarkir/cig");
setsAliases.put("M15", "magic2015coreset/cig");
setsAliases.put("CNS", "vintagemasters/cig");
setsAliases.put("CNS", "conspiracy/cig");
setsAliases.put("JOU", "journeyintonyx/cig");
setsAliases.put("BNG", "bornofthegods/cig");
setsAliases.put("C13", "commander2013/cig");
setsAliases.put("THS", "theros/cig");
setsAliases.put("M14", "magic2014coreset/cig");
setsAliases.put("MMA", "modernmasters/cig");
setsAliases.put("DGM", "dragonsmaze/cig");
setsAliases.put("GTC", "gatecrash/cig");
setsAliases.put("RTR", "returntoravnica/cig");
setsAliases.put("M13", "magic2013/cig");
setsAliases.put("AVR", "avacynrestored/cig");
setsAliases.put("DKA", "darkascension/cig");
setsAliases.put("ISD", "innistrad/cig");
setsAliases.put("M12", "magic2012/cig");
setsAliases.put("CMD", "commander/cig");
setsAliases.put("NPH", "newphyrexia/spoiler");
setsAliases.put("MBS", "mirrodinbesieged/spoiler");
setsAliases.put("SOM", "scarsofmirrodin/spoiler");
setsAliases.put("M11", "magic2011/spoiler");
setsAliases.put("ROE", "riseoftheeldrazi/spoiler");
setsAliases.put("WWK", "worldwake/spoiler");
setsAliases.put("ZEN", "zendikar/spoiler");
setsAliases.put("M10", "magic2010/spoiler");
setsAliases.put("ARB", "alarareborn/spoiler");
setsAliases.put("CON", "conflux/spoiler");
setsAliases.put("ALA", "shardsofalara/spoiler");
setsAliases.put("PC2", "planechase2012edition/cig");
setsAliases.put("PTK", "portalthreekingdoms/cig");
setsAliases.put("DD3", "anthologyelvesvsgoblins/cig");
setsAliases.put("DD3", "anthologyjacevschandra/cig");
setsAliases.put("DD3", "anthologydivinevsdemonic/cig");
setsAliases.put("DD3", "anthologygarrukvsliliana/cig");
setsAliases.put("EVG", "elvesvsgoblins/cig");
setsAliases.put("DD2", "jacevschandra/cig");
setsAliases.put("DDC", "divinevsdemonic/cig");
setsAliases.put("DDD", "garrukvsliliana/cig");
setsAliases.put("DDE", "phyrexiavsthecoalition/cig");
setsAliases.put("DDF", "elspethvstezzeret/cig");
setsAliases.put("DDG", "knightsvsdragons/cig");
setsAliases.put("DDH", "ajanivsnicolbolas/cig");
setsAliases.put("DDI", "venservskoth/cig");
setsAliases.put("DDJ", "izzetvsgolgari/cig");
setsAliases.put("DDK", "sorinvstibalt/cig");
setsAliases.put("DDL", "heroesvsmonsters/cig");
setsAliases.put("DDM", "jacevsvraska/cig");
setsAliases.put("DDN", "speedvscunning/cig");
setsAliases.put("DDO", "elspethvskiora/cig");
setsAliases.put("2ED", "Unlimited Edition");
setsAliases.put("10E", "Tenth Edition");
setsAliases.put("3ED", "Revised Edition");
setsAliases.put("4ED", "Fourth Edition");
setsAliases.put("5DN", "Fifth Dawn");
setsAliases.put("5ED", "Fifth Edition");
setsAliases.put("6ED", "Classic Sixth Edition");
setsAliases.put("7ED", "Seventh Edition");
setsAliases.put("8ED", "Eighth Edition");
setsAliases.put("9ED", "Ninth Edition");
setsAliases.put("ALA", "Shards of Alara");
setsAliases.put("ALL", "Alliances");
setsAliases.put("APC", "Apocalypse");
setsAliases.put("ARB", "Alara Reborn");
setsAliases.put("ARC", "Archenemy");
setsAliases.put("ARN", "Arabian Nights");
setsAliases.put("ATH", "Anthologies");
setsAliases.put("ATQ", "Antiquities");
setsAliases.put("AVR", "Avacyn Restored");
setsAliases.put("BNG", "Born of the Gods");
setsAliases.put("BOK", "Betrayers of Kamigawa");
setsAliases.put("BRB", "Battle Royale Box Set");
setsAliases.put("BTD", "Beatdown Box Set");
setsAliases.put("C13", "Commander 2013 Edition");
setsAliases.put("C14", "Commander 2014 Edition");
setsAliases.put("CHK", "Champions of Kamigawa");
setsAliases.put("CHR", "Chronicles");
setsAliases.put("CMD", "Magic: The Gathering-Commander");
setsAliases.put("CNS", "Magic: The Gathering-Conspiracy");
setsAliases.put("CON", "Conflux");
setsAliases.put("CSP", "Coldsnap");
setsAliases.put("DD2", "Duel Decks: Jace vs. Chandra");
setsAliases.put("DD3", "Duel Decks Anthology, Divine vs. Demonic^Duel Decks Anthology, Elves vs. Goblins^Duel Decks Anthology, Garruk vs. Liliana^Duel Decks Anthology, Jace vs. Chandra");
setsAliases.put("DDC", "Duel Decks: Divine vs. Demonic");
setsAliases.put("DDD", "Duel Decks: Garruk vs. Liliana");
setsAliases.put("DDE", "Duel Decks: Phyrexia vs. the Coalition");
setsAliases.put("DDF", "Duel Decks: Elspeth vs. Tezzeret");
setsAliases.put("DDG", "Duel Decks: Knights vs. Dragons");
setsAliases.put("DDH", "Duel Decks: Ajani vs. Nicol Bolas");
setsAliases.put("DDI", "Duel Decks: Venser vs. Koth");
setsAliases.put("DDJ", "Duel Decks: Izzet vs. Golgari");
setsAliases.put("DDK", "Duel Decks: Sorin vs. Tibalt");
setsAliases.put("DDL", "Duel Decks: Heroes vs. Monsters");
setsAliases.put("DDM", "Duel Decks: Jace vs. Vraska");
setsAliases.put("DDN", "Duel Decks: Speed vs. Cunning");
setsAliases.put("DDO", "Duel Decks: Elspeth vs. Kiora");
setsAliases.put("DGM", "Dragon's Maze");
setsAliases.put("DIS", "Dissension");
setsAliases.put("DKA", "Dark Ascension");
setsAliases.put("DKM", "Deckmasters");
setsAliases.put("DRK", "The Dark");
setsAliases.put("DST", "Darksteel");
setsAliases.put("DTK", "Dragons of Tarkir");
setsAliases.put("EVE", "Eventide");
setsAliases.put("EVG", "Duel Decks: Elves vs. Goblins");
setsAliases.put("EXO", "Exodus");
setsAliases.put("FEM", "Fallen Empires");
setsAliases.put("FNMP", "Friday Night Magic");
setsAliases.put("FRF", "Fate Reforged");
setsAliases.put("FUT", "Future Sight");
setsAliases.put("FVD", "From the Vault: Dragons");
setsAliases.put("FVE", "From the Vault: Exiled");
setsAliases.put("FVR", "From the Vault: Relics");
setsAliases.put("GPT", "Guildpact");
setsAliases.put("GPX", "Grand Prix");
setsAliases.put("GRC", "WPN Gateway");
setsAliases.put("GTC", "Gatecrash");
setsAliases.put("HML", "Homelands");
setsAliases.put("HOP", "Planechase");
setsAliases.put("ICE", "Ice Age");
setsAliases.put("INV", "Invasion");
setsAliases.put("ISD", "Innistrad");
setsAliases.put("JOU", "Journey into Nyx");
setsAliases.put("JR", "Judge Promo");
setsAliases.put("JUD", "Judgment");
setsAliases.put("KTK", "Khans of Tarkir");
setsAliases.put("LEA", "Limited Edition Alpha");
setsAliases.put("LEB", "Limited Edition Beta");
setsAliases.put("LEG", "Legends");
setsAliases.put("LGN", "Legions");
setsAliases.put("LRW", "Lorwyn");
setsAliases.put("M10", "Magic 2010");
setsAliases.put("M11", "Magic 2011");
setsAliases.put("M12", "Magic 2012");
setsAliases.put("M13", "Magic 2013");
setsAliases.put("M14", "Magic 2014");
setsAliases.put("M15", "Magic 2015");
setsAliases.put("MBP", "Media Inserts");
setsAliases.put("MBS", "Mirrodin Besieged");
setsAliases.put("ME2", "Masters Edition II");
setsAliases.put("ME3", "Masters Edition III");
setsAliases.put("ME4", "Masters Edition IV");
setsAliases.put("MED", "Masters Edition");
// setsAliases.put("MGDC", "Game Day");
setsAliases.put("MIR", "Mirage");
setsAliases.put("MLP", "Launch Party");
setsAliases.put("MMA", "Modern Masters");
setsAliases.put("MMB", "Modern Masters 2015");
setsAliases.put("MMQ", "Mercadian Masques");
setsAliases.put("MOR", "Morningtide");
setsAliases.put("MPRP", "Magic Player Rewards");
setsAliases.put("MRD", "Mirrodin");
setsAliases.put("NMS", "Nemesis");
setsAliases.put("NPH", "New Phyrexia");
setsAliases.put("ODY", "Odyssey");
setsAliases.put("ONS", "Onslaught");
setsAliases.put("ORI", "Magic Origins");
setsAliases.put("PC2", "Planechase 2012 Edition");
setsAliases.put("PCY", "Prophecy");
setsAliases.put("PD2", "Premium Deck Series: Fire and Lightning");
setsAliases.put("PDS", "Premium Deck Series: Slivers");
setsAliases.put("PLC", "Planar Chaos");
setsAliases.put("PLS", "Planeshift");
setsAliases.put("PO2", "Portal Second Age");
setsAliases.put("POR", "Portal");
setsAliases.put("PTC", "Prerelease Events");
setsAliases.put("PTK", "Portal Three Kingdoms");
setsAliases.put("RAV", "Ravnica: City of Guilds");
setsAliases.put("ROE", "Rise of the Eldrazi");
setsAliases.put("RTR", "Return to Ravnica");
setsAliases.put("S00", "Starter 2000");
setsAliases.put("S99", "Starter 1999");
setsAliases.put("SCG", "Scourge");
setsAliases.put("SHM", "Shadowmoor");
setsAliases.put("SOK", "Saviors of Kamigawa");
setsAliases.put("SOM", "Scars of Mirrodin");
setsAliases.put("STH", "Stronghold");
setsAliases.put("THS", "Theros");
setsAliases.put("TMP", "Tempest");
setsAliases.put("TOR", "Torment");
setsAliases.put("TSB", "Time Spiral 'Timeshifted'");
setsAliases.put("TSP", "Time Spiral");
setsAliases.put("UDS", "Urza's Destiny");
setsAliases.put("UGL", "Unglued");
setsAliases.put("ULG", "Urza's Legacy");
setsAliases.put("UNH", "Unhinged");
setsAliases.put("USG", "Urza's Saga");
setsAliases.put("VG1", "Vanguard Set 1");
setsAliases.put("VG2", "Vanguard Set 2");
setsAliases.put("VG3", "Vanguard Set 3");
setsAliases.put("VG4", "Vanguard Set 4");
setsAliases.put("VGO", "MTGO Vanguard");
setsAliases.put("VIS", "Visions");
setsAliases.put("VMA", "Vintage Masters");
setsAliases.put("WMCQ", "World Magic Cup Qualifier");
setsAliases.put("WTH", "Weatherlight");
setsAliases.put("WWK", "Worldwake");
setsAliases.put("ZEN", "Zendikar");
}
private Map<String, String> getSetLinks(String cardSet) {
Map<String, String> setLinks = new HashMap<>();
try {
String urlDocument;
if (cardSet.equals("M15")) {
urlDocument = "http://magic.wizards.com/en/content/magic-2015-core-set-card-set-archive-products-game-info";
String setNames = setsAliases.get(cardSet);
for (String setName : setNames.split("\\^")) {
String URLSetName = URLEncoder.encode(setName, "UTF-8");
String urlDocument;
urlDocument = "http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=+[%22" + URLSetName + "%22]";
Document doc = Jsoup.connect(urlDocument).get();
Elements cardsImages = doc.select("div.advanced-card img");
Elements cardsImages = doc.select("img[src^=../../Handlers/]");
for (int i = 0; i < cardsImages.size(); i++) {
String cardName = normalizeName(cardsImages.get(i).attr("alt"));
if (cardName != null && !cardName.isEmpty()) {
@ -104,46 +204,9 @@ public class WizardCardsImageSource implements CardImageSource {
}
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").substring(5));
}
}
} 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"));
}
}
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());
@ -173,7 +236,8 @@ public class WizardCardsImageSource implements CardImageSource {
if (card.isFlippedSide()) { //doesn't support rotated images
return null;
}
if (setsAliases.get(cardSet) != null) {
String setNames = setsAliases.get(cardSet);
if (setNames != null) {
Map<String, String> setLinks = sets.get(cardSet);
if (setLinks == null) {
setLinks = getSetLinks(cardSet);
@ -191,7 +255,7 @@ public class WizardCardsImageSource implements CardImageSource {
}
}
if (link != null && !link.startsWith("http://")) {
link = "http://www.wizards.com" + link;
link = "http://gatherer.wizards.com" + link;
}
return link;
}

View file

@ -58,7 +58,6 @@ import net.java.truevfs.kernel.spec.FsSyncException;
import org.apache.log4j.Logger;
import org.mage.plugins.card.dl.sources.CardImageSource;
import org.mage.plugins.card.dl.sources.MagicCardsImageSource;
import org.mage.plugins.card.dl.sources.MtgImageSource;
import org.mage.plugins.card.dl.sources.WizardCardsImageSource;
import org.mage.plugins.card.properties.SettingsManager;
import org.mage.plugins.card.utils.CardImageUtils;
@ -85,7 +84,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
private Proxy p = Proxy.NO_PROXY;
private final ExecutorService executor = Executors.newFixedThreadPool(10);
// private ExecutorService executor = Executors.newFixedThreadPool(10);
public static void main(String[] args) {
startDownload(null, null);
@ -445,6 +444,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
update(0, cardsToDownload.size());
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < cardsToDownload.size() && !cancel; i++) {
try {
@ -466,6 +466,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
Runnable task = new DownloadTask(card, new URL(url), cardsToDownload.size());
executor.execute(task);
} else {
logger.info("Card not available on " + cardImageSource.getSourceName()+ ": " + card.getName() + " (" + card.getSet() + ")");
synchronized (sync) {
update(cardIndex + 1, cardsToDownload.size());
}
@ -646,7 +647,6 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
bar.setString("0 cards remaining! Please close!");
} else {
bar.setString(String.format("%d cards remaining! Please choose another source!", count));
//executor = Executors.newFixedThreadPool(10);
startDownloadButton.setEnabled(true);
}
}

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect;
import mage.abilities.keyword.MorphAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
@ -57,7 +58,7 @@ public class WallOfDeceit extends CardImpl {
this.addAbility(DefenderAbility.getInstance());
// {3}: Turn Wall of Deceit face down.
Effect effect = new BecomesFaceDownCreatureEffect(null, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED);
Effect effect = new BecomesFaceDownCreatureEffect(Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED);
effect.setText("Turn Wall of Deceit face down. <i>(It becomes a 2/2 creature.)</i>");
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{3}")));

View file

@ -40,6 +40,7 @@ import java.util.UUID;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import org.apache.log4j.Logger;
@ -54,6 +55,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
private static Random rnd = new Random();
private UUID ownerId;
private Zone zone;
private boolean errorLogged = false;
public CardsImpl() { }
@ -189,8 +191,17 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
if (card != null) {
cards.add(card);
} else {
// seems like this can happen during the cancelation of a game
logger.error("Card not found cardId: " + cardId + " gameId: " + game.getId() );
if (!errorLogged) { // this runs in iteration, so the flag helps to stop to fill the log file
// seems like this can happen during the cancelation of a game
logger.error("Card not found cardId: " + cardId + " gameId: " + game.getId() );
for (Player player :game.getPlayers().values()) {
logger.error(player.getName() + " inGame=" + (player.isInGame() ? "true":"false"));
}
for (StackTraceElement stackTraceElement: Thread.currentThread().getStackTrace()) {
logger.error(stackTraceElement.toString());
}
errorLogged = true;
}
}
}
return cards;

View file

@ -30,18 +30,26 @@ package mage.cards;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import mage.cards.decks.DeckCardInfo;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import static mage.constants.ColoredManaSymbol.B;
import static mage.constants.ColoredManaSymbol.G;
import static mage.constants.ColoredManaSymbol.R;
import static mage.constants.ColoredManaSymbol.U;
import static mage.constants.ColoredManaSymbol.W;
import mage.util.ClassScanner;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
@ -57,7 +65,7 @@ public class Sets extends HashMap<String, ExpansionSet> {
}
private Sets() {
ArrayList<String> packages = new ArrayList<String>();
ArrayList<String> packages = new ArrayList<>();
packages.add("mage.sets");
for (Class c : ClassScanner.findClasses(packages, ExpansionSet.class)) {
try {
@ -130,8 +138,8 @@ public class Sets extends HashMap<String, ExpansionSet> {
public static void saveDeck(String file, DeckCardLists deck) throws FileNotFoundException {
PrintWriter out = new PrintWriter(file);
Map<String, DeckCardInfo> deckCards = new HashMap<String, DeckCardInfo>();
Map<String, DeckCardInfo> sideboard = new HashMap<String, DeckCardInfo>();
Map<String, DeckCardInfo> deckCards = new HashMap<>();
Map<String, DeckCardInfo> sideboard = new HashMap<>();
try {
if (deck.getName() != null && deck.getName().length() > 0) {
out.println("NAME:" + deck.getName());