Merge ReworkImageDownload

This commit is contained in:
LevelX2 2017-09-15 23:23:49 +02:00
commit 2117bfc17c
14 changed files with 3499 additions and 1869 deletions

View file

@ -44,8 +44,6 @@ import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import mage.cards.action.ActionCallback;
import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.client.cards.BigCard;
import mage.client.chat.ChatPanelBasic;
@ -134,8 +132,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private final BalloonTip balloonTip;
private java.util.List<CardInfo> missingCards;
/**
* @return the session
*/
@ -513,18 +509,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
private void checkForNewImages() {
long beforeCall = System.currentTimeMillis();
missingCards = CardRepository.instance.findCards(new CardCriteria());
LOGGER.info("Card pool load time: " + ((System.currentTimeMillis() - beforeCall) / 1000 + " seconds"));
beforeCall = System.currentTimeMillis();
if (DownloadPictures.checkForMissingCardImages(missingCards)) {
LOGGER.info("Card images checking time: " + ((System.currentTimeMillis() - beforeCall) / 1000 + " seconds"));
UserRequestMessage message = new UserRequestMessage("New images available", "Card images are missing (" + missingCards.size() + "). Do you want to download the images?"
+ "<br><br><i>You can deactivate the image download check on application start in the preferences.</i>");
message.setButton1("No", null);
message.setButton2("Yes", PlayerAction.CLIENT_DOWNLOAD_CARD_IMAGES);
showUserRequestDialog(message);
}
// Removed TODO: Remove related pref code
}
public static void setActive(MagePane frame) {
@ -978,8 +963,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}//GEN-LAST:event_btnImagesActionPerformed
public void downloadImages() {
java.util.List<CardInfo> cards = CardRepository.instance.findCards(new CardCriteria());
DownloadPictures.startDownload(null, cards);
DownloadPictures.startDownload();
}
public void exitApp() {
@ -1317,7 +1301,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
Plugins.instance.downloadSymbols();
break;
case CLIENT_DOWNLOAD_CARD_IMAGES:
DownloadPictures.startDownload(null, missingCards);
DownloadPictures.startDownload();
break;
case CLIENT_DISCONNECT:
if (SessionHandler.isConnected()) {

View file

@ -1,5 +1,6 @@
package org.mage.plugins.card.dl.sources;
import java.util.ArrayList;
import org.mage.plugins.card.images.CardDownloadData;
/**
@ -9,12 +10,38 @@ import org.mage.plugins.card.images.CardDownloadData;
public interface CardImageSource {
String generateURL(CardDownloadData card) throws Exception;
String generateTokenUrl(CardDownloadData card) throws Exception;
String getNextHttpImageUrl();
String getFileForHttpImage(String httpImageUrl);
String getSourceName();
float getAverageSize();
int getTotalImages();
boolean isTokenSource();
default int getTokenImages() {
return 0;
}
default boolean isTokenSource() {
return false;
}
void doPause(String httpImageUrl);
default ArrayList<String> getSupportedSets() {
return null;
}
default boolean isSetSupportedComplete(String setCode) {
return true;
}
default boolean isImageProvided(String setCode, String cardName) {
return false;
}
}

View file

@ -1,7 +1,10 @@
package org.mage.plugins.card.dl.sources;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import mage.client.dialog.PreferencesDialog;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.utils.CardImageUtils;
@ -13,6 +16,202 @@ import org.mage.plugins.card.utils.CardImageUtils;
public enum MagicCardsImageSource implements CardImageSource {
instance;
private static final Set<String> supportedSets = new LinkedHashSet<String>() {
{
// add("PTC"); // Prerelease Events
add("LEA");
add("LEB");
add("2ED");
add("ARN");
add("ATQ");
add("3ED");
add("LEG");
add("DRK");
add("FEM");
add("4ED");
add("ICE");
add("CHR");
add("HML");
add("ALL");
add("MIR");
add("VIS");
add("5ED");
add("POR");
add("WTH");
add("TMP");
add("STH");
add("EXO");
add("P02");
add("UGL");
add("USG");
add("DD3DVD");
add("DD3EVG");
add("DD3GVL");
add("DD3JVC");
add("ULG");
add("6ED");
add("UDS");
add("PTK");
add("S99");
add("MMQ");
// add("BRB");Battle Royale Box Set
add("NEM");
add("S00");
add("PCY");
add("INV");
// add("BTD"); // Beatdown Boxset
add("PLS");
add("7ED");
add("APC");
add("ODY");
// add("DKM"); // Deckmasters 2001
add("TOR");
add("JUD");
add("ONS");
add("LGN");
add("SCG");
add("8ED");
add("MRD");
add("DST");
add("5DN");
add("CHK");
add("UNH");
add("BOK");
add("SOK");
add("9ED");
add("RAV");
add("GPT");
add("DIS");
add("CSP");
add("TSP");
add("TSB");
add("PLC");
add("FUT");
add("10E");
add("MED");
add("LRW");
add("EVG");
add("MOR");
add("SHM");
add("EVE");
add("DRB");
add("ME2");
add("ALA");
add("DD2");
add("CON");
add("DDC");
add("ARB");
add("M10");
// add("TD0"); // Magic Online Deck Series
add("V09");
add("HOP");
add("ME3");
add("ZEN");
add("DDD");
add("H09");
add("WWK");
add("DDE");
add("ROE");
add("DPA");
add("ARC");
add("M11");
add("V10");
add("DDF");
add("SOM");
// add("TD0"); // Commander Theme Decks
add("PD2");
add("ME4");
add("MBS");
add("DDG");
add("NPH");
add("CMD");
add("M12");
add("V11");
add("DDH");
add("ISD");
add("PD3");
add("DKA");
add("DDI");
add("AVR");
add("PC2");
add("M13");
add("V12");
add("DDJ");
add("RTR");
add("CM1");
// add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
add("GTC");
add("DDK");
add("DGM");
add("MMA");
add("M14");
add("V13");
add("DDL");
add("THS");
add("C13");
add("BNG");
add("DDM");
add("JOU");
// add("MD1"); // Modern Event Deck
add("CNS");
add("VMA");
add("M15");
add("V14");
add("DDN");
add("KTK");
add("C14");
// add("DD3"); // Duel Decks Anthology
add("FRF");
add("DDO");
add("DTK");
add("TPR");
add("MM2");
add("ORI");
add("V15");
add("DDP");
add("BFZ");
add("EXP");
add("C15");
// add("PZ1"); // Legendary Cube
add("OGW");
add("DDQ");
add("W16");
add("SOI");
add("EMA");
add("EMN");
add("V16");
add("CN2");
add("DDR");
add("KLD");
add("MPS");
// add("PZ2"); // Treasure Chests
add("C16");
add("PCA");
add("AER");
add("MM3");
add("DDS");
add("W17");
add("AKH");
add("MPS");
add("CMA");
add("E01");
add("HOU");
add("C17");
// add("XLN");
// add("DDT");
// add("IMA");
// add("E02");
// add("V17");
// add("UST");
// add("RIX");
// add("A25");
// add("DOM");
// add("M19");
}
};
private static final Map<String, String> setNameTokenReplacement = new HashMap<String, String>() {
{
put("10E", "tenth-edition");
@ -146,12 +345,11 @@ public enum MagicCardsImageSource implements CardImageSource {
return "magiccards.info";
}
@Override
public String getNextHttpImageUrl() {
return null;
}
@Override
public String getFileForHttpImage(String httpImageUrl) {
return null;
@ -210,18 +408,26 @@ public enum MagicCardsImageSource implements CardImageSource {
public float getAverageSize() {
return 70.0f;
}
@Override
public int getTotalImages() {
return -1;
}
@Override
public boolean isTokenSource() {
return true;
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
@Override
public void doPause(String httpImageUrl) {
}
}

View file

@ -24,20 +24,221 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package org.mage.plugins.card.dl.sources;
import org.mage.plugins.card.images.CardDownloadData;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.mage.plugins.card.images.CardDownloadData;
/**
*
* @author Pete Rossi
*/
public enum MagidexImageSource implements CardImageSource {
instance;
public enum MagidexImageSource implements CardImageSource {
instance;
private final Set<String> supportedSets;
MagidexImageSource() {
supportedSets = new LinkedHashSet<>();
// supportedSets.add("PTC"); // Prerelease Events
// supportedSets.add("FNMP");
supportedSets.add("JR");
supportedSets.add("LEA");
supportedSets.add("LEB");
supportedSets.add("2ED");
supportedSets.add("ARN");
supportedSets.add("ATQ");
supportedSets.add("3ED");
supportedSets.add("LEG");
supportedSets.add("DRK");
supportedSets.add("FEM");
supportedSets.add("4ED");
supportedSets.add("ICE");
supportedSets.add("CHR");
supportedSets.add("HML");
supportedSets.add("ALL");
supportedSets.add("MIR");
supportedSets.add("VIS");
supportedSets.add("5ED");
supportedSets.add("POR");
supportedSets.add("WTH");
supportedSets.add("TMP");
supportedSets.add("STH");
supportedSets.add("EXO");
supportedSets.add("P02");
supportedSets.add("UGL");
supportedSets.add("USG");
supportedSets.add("DD3DVD");
supportedSets.add("DD3EVG");
supportedSets.add("DD3GVL");
supportedSets.add("DD3JVC");
supportedSets.add("ULG");
supportedSets.add("6ED");
supportedSets.add("UDS");
supportedSets.add("PTK");
supportedSets.add("S99");
supportedSets.add("MMQ");
// supportedSets.add("BRB");Battle Royale Box Set
supportedSets.add("NEM");
supportedSets.add("S00");
supportedSets.add("PCY");
supportedSets.add("INV");
// supportedSets.add("BTD"); // Beatdown Boxset
supportedSets.add("PLS");
supportedSets.add("7ED");
supportedSets.add("APC");
supportedSets.add("ODY");
// supportedSets.add("DKM"); // Deckmasters 2001
supportedSets.add("TOR");
supportedSets.add("JUD");
supportedSets.add("ONS");
supportedSets.add("LGN");
supportedSets.add("SCG");
supportedSets.add("8ED");
supportedSets.add("MRD");
supportedSets.add("DST");
supportedSets.add("5DN");
supportedSets.add("CHK");
supportedSets.add("UNH");
supportedSets.add("BOK");
supportedSets.add("SOK");
supportedSets.add("9ED");
supportedSets.add("RAV");
supportedSets.add("GPT");
supportedSets.add("DIS");
supportedSets.add("CSP");
supportedSets.add("TSP");
supportedSets.add("TSB");
supportedSets.add("PLC");
supportedSets.add("FUT");
supportedSets.add("10E");
supportedSets.add("MED");
supportedSets.add("LRW");
supportedSets.add("EVG");
supportedSets.add("MOR");
supportedSets.add("SHM");
supportedSets.add("EVE");
supportedSets.add("DRB");
supportedSets.add("ME2");
supportedSets.add("ALA");
supportedSets.add("DD2");
supportedSets.add("CON");
supportedSets.add("DDC");
supportedSets.add("ARB");
supportedSets.add("M10");
// supportedSets.add("TD0"); // Magic Online Deck Series
supportedSets.add("V09");
supportedSets.add("HOP");
supportedSets.add("ME3");
supportedSets.add("ZEN");
supportedSets.add("DDD");
supportedSets.add("H09");
supportedSets.add("WWK");
supportedSets.add("DDE");
supportedSets.add("ROE");
supportedSets.add("DPA");
supportedSets.add("ARC");
supportedSets.add("M11");
supportedSets.add("V10");
supportedSets.add("DDF");
supportedSets.add("SOM");
// supportedSets.add("TD0"); // Commander Theme Decks
supportedSets.add("PD2");
supportedSets.add("ME4");
supportedSets.add("MBS");
supportedSets.add("DDG");
supportedSets.add("NPH");
supportedSets.add("CMD");
supportedSets.add("M12");
supportedSets.add("V11");
supportedSets.add("DDH");
supportedSets.add("ISD");
supportedSets.add("PD3");
supportedSets.add("DKA");
supportedSets.add("DDI");
supportedSets.add("AVR");
supportedSets.add("PC2");
supportedSets.add("M13");
supportedSets.add("V12");
supportedSets.add("DDJ");
supportedSets.add("RTR");
supportedSets.add("CM1");
// supportedSets.add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
supportedSets.add("GTC");
supportedSets.add("DDK");
supportedSets.add("DGM");
supportedSets.add("MMA");
supportedSets.add("M14");
supportedSets.add("V13");
supportedSets.add("DDL");
supportedSets.add("THS");
supportedSets.add("C13");
supportedSets.add("BNG");
supportedSets.add("DDM");
supportedSets.add("JOU");
// supportedSets.add("MD1"); // Modern Event Deck
supportedSets.add("CNS");
supportedSets.add("VMA");
supportedSets.add("M15");
supportedSets.add("V14");
supportedSets.add("DDN");
supportedSets.add("KTK");
supportedSets.add("C14");
// supportedSets.add("DD3"); // Duel Decks Anthology
supportedSets.add("FRF");
supportedSets.add("DDO");
supportedSets.add("DTK");
supportedSets.add("TPR");
supportedSets.add("MM2");
supportedSets.add("ORI");
supportedSets.add("V15");
supportedSets.add("DDP");
supportedSets.add("BFZ");
supportedSets.add("EXP");
supportedSets.add("C15");
// supportedSets.add("PZ1"); // Legendary Cube
supportedSets.add("OGW");
supportedSets.add("DDQ");
supportedSets.add("W16");
supportedSets.add("SOI");
supportedSets.add("EMA");
supportedSets.add("EMN");
supportedSets.add("V16");
supportedSets.add("CN2");
supportedSets.add("DDR");
supportedSets.add("KLD");
supportedSets.add("MPS");
// supportedSets.add("PZ2"); // Treasure Chests
supportedSets.add("C16");
supportedSets.add("PCA");
supportedSets.add("AER");
supportedSets.add("MM3");
supportedSets.add("DDS");
supportedSets.add("W17");
supportedSets.add("AKH");
supportedSets.add("MPS");
supportedSets.add("CMA");
supportedSets.add("E01");
supportedSets.add("HOU");
supportedSets.add("C17");
// supportedSets.add("XLN");
// supportedSets.add("DDT");
// supportedSets.add("IMA");
// supportedSets.add("E02");
// supportedSets.add("V17");
// supportedSets.add("UST");
// supportedSets.add("RIX");
// supportedSets.add("A25");
// supportedSets.add("DOM");
// supportedSets.add("M19");
}
@Override
public String getSourceName() {
@ -68,10 +269,23 @@ public enum MagidexImageSource implements CardImageSource {
}
// This will properly escape the url
URI uri = new URI("http", "magidex.com", "/extstatic/card/" + cardSet + '/' + cardDownloadName + ".jpg", null, null);
return uri.toASCIIString();
URI uri = new URI("http", "magidex.com", "/extstatic/card/" + formatSetName(cardSet) + '/' + cardDownloadName + ".jpg", null, null);
return uri.toASCIIString();
}
private String formatSetName(String setName) {
if (setNameReplacement.containsKey(setName)) {
setName = setNameReplacement.get(setName);
}
return setName;
}
private static final Map<String, String> setNameReplacement = new HashMap<String, String>() {
{
put("JR", "pJGP");
}
};
@Override
public String generateTokenUrl(CardDownloadData card) {
return null;
@ -95,4 +309,11 @@ public enum MagidexImageSource implements CardImageSource {
@Override
public void doPause(String httpImageUrl) {
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
}

View file

@ -27,11 +27,10 @@
*/
package org.mage.plugins.card.dl.sources;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
import java.io.IOException;
import java.util.HashMap;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
/**
*
@ -368,13 +367,19 @@ public enum MtgOnlTokensImageSource implements CardImageSource {
}
return -1;
}
@Override
public boolean isTokenSource() {
return true;
}
@Override
public void doPause(String httpImageUrl) {
}
@Override
public boolean isImageProvided(String setCode, String cardName) {
return true;
}
}

View file

@ -35,9 +35,11 @@ import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.prefs.Preferences;
@ -57,10 +59,11 @@ import org.mage.plugins.card.images.CardDownloadData;
public enum MythicspoilerComSource implements CardImageSource {
instance;
private Map<String, String> setsAliases;
private Map<String, String> cardNameAliases;
private Map<String, Set<String>> cardNameAliasesStart;
private final Map<String, String> setsAliases;
private final Map<String, String> cardNameAliases;
private final Map<String, Set<String>> cardNameAliasesStart;
private final Map<String, Map<String, String>> sets;
private final Set<String> supportedSets;
@Override
public String getSourceName() {
@ -68,6 +71,187 @@ public enum MythicspoilerComSource implements CardImageSource {
}
MythicspoilerComSource() {
supportedSets = new LinkedHashSet<>();
// supportedSets.add("LEA");
supportedSets.add("LEB");
// supportedSets.add("2ED");
supportedSets.add("ARN");
supportedSets.add("ATQ");
supportedSets.add("3ED");
supportedSets.add("LEG");
supportedSets.add("DRK");
supportedSets.add("FEM");
// supportedSets.add("4ED");
supportedSets.add("ICE");
supportedSets.add("CHR");
supportedSets.add("HML");
supportedSets.add("ALL");
supportedSets.add("MIR");
supportedSets.add("VIS");
// supportedSets.add("5ED");
// supportedSets.add("POR");
supportedSets.add("WTH");
supportedSets.add("TMP");
supportedSets.add("STH");
supportedSets.add("EXO");
// supportedSets.add("P02");
// supportedSets.add("UGL");
supportedSets.add("USG");
// supportedSets.add("DD3DVD");
// supportedSets.add("DD3EVG");
// supportedSets.add("DD3GVL");
// supportedSets.add("DD3JVC");
// supportedSets.add("ULG");
// supportedSets.add("6ED");
supportedSets.add("UDS");
supportedSets.add("PTK");
// supportedSets.add("S99");
supportedSets.add("MMQ");
// supportedSets.add("BRB");Battle Royale Box Set
supportedSets.add("NEM");
// supportedSets.add("S00");
supportedSets.add("PCY");
supportedSets.add("INV");
// supportedSets.add("BTD"); // Beatdown Boxset
supportedSets.add("PLS");
supportedSets.add("7ED");
supportedSets.add("APC");
supportedSets.add("ODY");
// supportedSets.add("DKM"); // Deckmasters 2001
supportedSets.add("TOR");
supportedSets.add("JUD");
supportedSets.add("ONS");
supportedSets.add("LGN");
supportedSets.add("SCG");
supportedSets.add("8ED");
supportedSets.add("MRD");
supportedSets.add("DST");
supportedSets.add("5DN");
supportedSets.add("CHK");
supportedSets.add("UNH");
supportedSets.add("BOK");
supportedSets.add("SOK");
supportedSets.add("9ED");
supportedSets.add("RAV");
supportedSets.add("GPT");
supportedSets.add("DIS");
supportedSets.add("CSP");
supportedSets.add("TSP");
supportedSets.add("TSB");
supportedSets.add("PLC");
supportedSets.add("FUT");
supportedSets.add("10E");
supportedSets.add("MED");
supportedSets.add("LRW");
supportedSets.add("EVG");
supportedSets.add("MOR");
supportedSets.add("SHM");
supportedSets.add("EVE");
supportedSets.add("DRB");
// supportedSets.add("ME2");
supportedSets.add("ALA");
// supportedSets.add("DD2");
supportedSets.add("CON");
// supportedSets.add("DDC");
supportedSets.add("ARB");
supportedSets.add("M10");
// supportedSets.add("TD0"); // Magic Online Deck Series
// supportedSets.add("V09");
supportedSets.add("HOP");
// supportedSets.add("ME3");
supportedSets.add("ZEN");
// supportedSets.add("DDD");
supportedSets.add("H09");
supportedSets.add("WWK");
// supportedSets.add("DDE");
supportedSets.add("ROE");
supportedSets.add("DPA");
supportedSets.add("ARC");
supportedSets.add("M11");
// supportedSets.add("V10");
// supportedSets.add("DDF");
supportedSets.add("SOM");
// supportedSets.add("TD0"); // Commander Theme Decks
// supportedSets.add("PD2");
// supportedSets.add("ME4");
supportedSets.add("MBS");
// supportedSets.add("DDG");
supportedSets.add("NPH");
supportedSets.add("CMD");
supportedSets.add("M12");
supportedSets.add("V11");
// supportedSets.add("DDH");
supportedSets.add("ISD");
supportedSets.add("PD3");
supportedSets.add("DKA");
// supportedSets.add("DDI");
supportedSets.add("AVR");
// supportedSets.add("PC2");
supportedSets.add("M13");
// supportedSets.add("V12");
// supportedSets.add("DDJ");
supportedSets.add("RTR");
// supportedSets.add("CM1");
// supportedSets.add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
supportedSets.add("GTC");
// supportedSets.add("DDK");
supportedSets.add("DGM");
// supportedSets.add("MMA");
supportedSets.add("M14");
supportedSets.add("V13");
// supportedSets.add("DDL");
supportedSets.add("THS");
supportedSets.add("C13");
supportedSets.add("BNG");
// supportedSets.add("DDM");
supportedSets.add("JOU");
// supportedSets.add("MD1"); // Modern Event Deck
// supportedSets.add("CNS");
// supportedSets.add("VMA");
supportedSets.add("M15");
supportedSets.add("V14");
supportedSets.add("DDN");
supportedSets.add("KTK");
supportedSets.add("C14");
// supportedSets.add("DD3"); // Duel Decks Anthology
supportedSets.add("FRF");
// supportedSets.add("DDO");
// supportedSets.add("DTK");
// supportedSets.add("TPR");
supportedSets.add("MM2");
supportedSets.add("ORI");
// supportedSets.add("V15");
// supportedSets.add("DDP");
supportedSets.add("BFZ");
// supportedSets.add("EXP");
supportedSets.add("C15");
// supportedSets.add("PZ1"); // Legendary Cube
supportedSets.add("OGW");
// supportedSets.add("DDQ");
// supportedSets.add("W16");
supportedSets.add("SOI");
supportedSets.add("EMA");
supportedSets.add("EMN");
// supportedSets.add("V16");
supportedSets.add("CN2");
// supportedSets.add("DDR");
supportedSets.add("KLD");
// supportedSets.add("MPS");
// supportedSets.add("PZ2");
supportedSets.add("C16");
// supportedSets.add("PCA");
supportedSets.add("AER");
supportedSets.add("MM3");
// supportedSets.add("W17");
supportedSets.add("AKH");
supportedSets.add("MPS");
supportedSets.add("CMA");
supportedSets.add("E01");
supportedSets.add("HOU");
supportedSets.add("C17");
supportedSets.add("XLN");
sets = new LinkedHashMap<>();
setsAliases = new HashMap<>();
setsAliases.put("exp", "bfz");
@ -243,4 +427,12 @@ public enum MythicspoilerComSource implements CardImageSource {
@Override
public void doPause(String httpImageUrl) {
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
}

View file

@ -1,18 +1,206 @@
package org.mage.plugins.card.dl.sources;
import org.mage.plugins.card.images.CardDownloadData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.mage.plugins.card.images.CardDownloadData;
/**
* @author Quercitron
*
*/
public enum ScryfallImageSource implements CardImageSource {
public enum ScryfallImageSource implements CardImageSource {
instance;
private final Set<String> supportedSets;
ScryfallImageSource() {
supportedSets = new LinkedHashSet<>();
// supportedSets.add("PTC"); //
supportedSets.add("LEA");
supportedSets.add("LEB");
supportedSets.add("2ED");
supportedSets.add("ARN");
supportedSets.add("ATQ");
supportedSets.add("3ED");
supportedSets.add("LEG");
supportedSets.add("DRK");
supportedSets.add("FEM");
supportedSets.add("4ED");
supportedSets.add("ICE");
supportedSets.add("CHR");
supportedSets.add("HML");
supportedSets.add("ALL");
supportedSets.add("MIR");
supportedSets.add("VIS");
supportedSets.add("5ED");
supportedSets.add("POR");
supportedSets.add("WTH");
supportedSets.add("TMP");
supportedSets.add("STH");
supportedSets.add("EXO");
supportedSets.add("P02");
supportedSets.add("UGL");
supportedSets.add("USG");
supportedSets.add("DD3DVD");
supportedSets.add("DD3EVG");
supportedSets.add("DD3GVL");
supportedSets.add("DD3JVC");
supportedSets.add("ULG");
supportedSets.add("6ED");
supportedSets.add("UDS");
supportedSets.add("PTK");
supportedSets.add("S99");
supportedSets.add("MMQ");
// supportedSets.add("BRB");Battle Royale Box Set
supportedSets.add("NEM");
supportedSets.add("S00");
supportedSets.add("PCY");
supportedSets.add("INV");
// supportedSets.add("BTD"); // Beatdown Boxset
supportedSets.add("PLS");
supportedSets.add("7ED");
supportedSets.add("APC");
supportedSets.add("ODY");
// supportedSets.add("DKM"); // Deckmasters 2001
supportedSets.add("TOR");
supportedSets.add("JUD");
supportedSets.add("ONS");
supportedSets.add("LGN");
supportedSets.add("SCG");
supportedSets.add("8ED");
supportedSets.add("MRD");
supportedSets.add("DST");
supportedSets.add("5DN");
supportedSets.add("CHK");
supportedSets.add("UNH");
supportedSets.add("BOK");
supportedSets.add("SOK");
supportedSets.add("9ED");
supportedSets.add("RAV");
supportedSets.add("GPT");
supportedSets.add("DIS");
supportedSets.add("CSP");
supportedSets.add("TSP");
supportedSets.add("TSB");
supportedSets.add("PLC");
supportedSets.add("FUT");
supportedSets.add("10E");
supportedSets.add("MED");
supportedSets.add("LRW");
supportedSets.add("EVG");
supportedSets.add("MOR");
supportedSets.add("SHM");
supportedSets.add("EVE");
supportedSets.add("DRB");
supportedSets.add("ME2");
supportedSets.add("ALA");
supportedSets.add("DD2");
supportedSets.add("CON");
supportedSets.add("DDC");
supportedSets.add("ARB");
supportedSets.add("M10");
// supportedSets.add("TD0"); // Magic Online Deck Series
supportedSets.add("V09");
supportedSets.add("HOP");
supportedSets.add("ME3");
supportedSets.add("ZEN");
supportedSets.add("DDD");
supportedSets.add("H09");
supportedSets.add("WWK");
supportedSets.add("DDE");
supportedSets.add("ROE");
supportedSets.add("DPA");
supportedSets.add("ARC");
supportedSets.add("M11");
supportedSets.add("V10");
supportedSets.add("DDF");
supportedSets.add("SOM");
// supportedSets.add("TD0"); // Commander Theme Decks
supportedSets.add("PD2");
supportedSets.add("ME4");
supportedSets.add("MBS");
supportedSets.add("DDG");
supportedSets.add("NPH");
supportedSets.add("CMD");
supportedSets.add("M12");
supportedSets.add("V11");
supportedSets.add("DDH");
supportedSets.add("ISD");
supportedSets.add("PD3");
supportedSets.add("DKA");
supportedSets.add("DDI");
supportedSets.add("AVR");
supportedSets.add("PC2");
supportedSets.add("M13");
supportedSets.add("V12");
supportedSets.add("DDJ");
supportedSets.add("RTR");
supportedSets.add("CM1");
// supportedSets.add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
supportedSets.add("GTC");
supportedSets.add("DDK");
supportedSets.add("DGM");
supportedSets.add("MMA");
supportedSets.add("M14");
supportedSets.add("V13");
supportedSets.add("DDL");
supportedSets.add("THS");
supportedSets.add("C13");
supportedSets.add("BNG");
supportedSets.add("DDM");
supportedSets.add("JOU");
// supportedSets.add("MD1"); // Modern Event Deck
supportedSets.add("CNS");
supportedSets.add("VMA");
supportedSets.add("M15");
supportedSets.add("V14");
supportedSets.add("DDN");
supportedSets.add("KTK");
supportedSets.add("C14");
// supportedSets.add("DD3"); // Duel Decks Anthology
supportedSets.add("FRF");
supportedSets.add("DDO");
supportedSets.add("DTK");
supportedSets.add("TPR");
supportedSets.add("MM2");
supportedSets.add("ORI");
supportedSets.add("V15");
supportedSets.add("DDP");
supportedSets.add("BFZ");
supportedSets.add("EXP");
supportedSets.add("C15");
// supportedSets.add("PZ1"); // Legendary Cube
supportedSets.add("OGW");
supportedSets.add("DDQ");
supportedSets.add("W16");
supportedSets.add("SOI");
supportedSets.add("EMA");
supportedSets.add("EMN");
supportedSets.add("V16");
supportedSets.add("CN2");
supportedSets.add("DDR");
supportedSets.add("KLD");
supportedSets.add("MPS");
// supportedSets.add("PZ2");
supportedSets.add("C16");
supportedSets.add("PCA");
supportedSets.add("AER");
supportedSets.add("MM3");
supportedSets.add("DDS");
supportedSets.add("W17");
supportedSets.add("AKH");
supportedSets.add("MPS");
supportedSets.add("CMA");
supportedSets.add("E01");
supportedSets.add("HOU");
supportedSets.add("C17");
}
@Override
public String generateURL(CardDownloadData card) throws Exception {
return "https://api.scryfall.com/cards/" + formatSetName(card.getSet()) + "/" + card.getCollectorId() + "?format=image";
@ -40,7 +228,7 @@ public enum ScryfallImageSource implements CardImageSource {
@Override
public float getAverageSize() {
return 240;
return 90;
}
@Override
@ -75,4 +263,11 @@ public enum ScryfallImageSource implements CardImageSource {
put("MBP", "pmei");
}
};
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
}

View file

@ -27,9 +27,6 @@
*/
package org.mage.plugins.card.dl.sources;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -37,8 +34,14 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.images.DownloadPictures;
/**
*
@ -46,13 +49,19 @@ import java.util.Map;
*/
public enum TokensMtgImageSource implements CardImageSource {
instance;
instance;
private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class);
private List<TokenData> tokensData;
// [[EXP/Name, TokenData>
private HashMap<String, ArrayList<TokenData>> tokensData;
private static final Set<String> supportedSets = new LinkedHashSet<String>();
private final Object tokensDataSync = new Object();
private final Set<String> supportedSets;
private TokensMtgImageSource() {
this.supportedSets = new LinkedHashSet<>();
}
@Override
public String getSourceName() {
@ -100,7 +109,12 @@ public enum TokensMtgImageSource implements CardImageSource {
"Sorin",
"Tamiyo",
"Teferi",
"Venser",};
"Venser",
// Custom Emblems
"Yoda",
"Obi-Wan Kenobi",
"Aurra Sing"
};
private static final Map<String, String> SET_NAMES_REPLACEMENT = new HashMap<String, String>() {
{
@ -134,36 +148,31 @@ public enum TokensMtgImageSource implements CardImageSource {
// e.g. http://tokens.mtg.onl/tokens/ORI_010-Thopter.jpg -- token number 010
// We don't know these numbers, but we can take them from a file
// with tokens information that can be downloaded from the site.
List<TokenData> newTokensData = getTokensData();
if (newTokensData.isEmpty()) {
if (tokensData.isEmpty()) {
logger.info("Source " + getSourceName() + " provides no token data.");
return null;
}
List<TokenData> matchedTokens = new ArrayList<>();
for (TokenData token : newTokensData) {
if (name.equalsIgnoreCase(token.getName()) && set.equalsIgnoreCase(token.getExpansionSetCode())) {
matchedTokens.add(token);
}
String key = set + "/" + name;
List<TokenData> list = tokensData.get(key);
if (list == null) {
logger.info("Could not find data for token " + name + ", set " + set + ".");
return null;
}
//
// if (matchedTokens.isEmpty()) {
// logger.info("Could not find data for token " + name + ", set " + set + ".");
// return null;
// }
TokenData tokenData;
if (type == 0) {
if (matchedTokens.size() > 1) {
if (list.size() > 1) {
logger.info("Multiple images were found for token " + name + ", set " + set + '.');
}
tokenData = matchedTokens.get(0);
logger.info("Token found: " + name + ", set " + set + '.');
tokenData = list.get(0);
} else {
if (type > matchedTokens.size()) {
if (type > list.size()) {
logger.warn("Not enough images for token with type " + type + ", name " + name + ", set " + set + '.');
return null;
}
tokenData = matchedTokens.get(card.getType() - 1);
tokenData = list.get(card.getType() - 1);
}
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + '_'
@ -172,15 +181,26 @@ public enum TokensMtgImageSource implements CardImageSource {
return url;
}
private List<TokenData> getTokensData() throws IOException {
private HashMap<String, ArrayList<TokenData>> getTokensData() throws IOException {
synchronized (tokensDataSync) {
if (tokensData == null) {
tokensData = new ArrayList<>();
DownloadPictures.getInstance().updateAndViewMessage("Creating token data...");
tokensData = new HashMap<>();
// get tokens data from resource file
try(InputStream inputStream = this.getClass().getResourceAsStream("/tokens-mtg-onl-list.csv")) {
try (InputStream inputStream = this.getClass().getResourceAsStream("/tokens-mtg-onl-list.csv")) {
List<TokenData> fileTokensData = parseTokensData(inputStream);
tokensData.addAll(fileTokensData);
for (TokenData tokenData : fileTokensData) {
String key = tokenData.getExpansionSetCode() + "/" + tokenData.getName();
ArrayList<TokenData> list = tokensData.get(key);
if (list == null) {
list = new ArrayList<>();
tokensData.put(key, list);
supportedSets.add(tokenData.getExpansionSetCode());
logger.info("Added key: " + key);
}
list.add(tokenData);
}
} catch (Exception exception) {
logger.warn("Failed to get tokens description from resource file tokens-mtg-onl-list.csv", exception);
}
@ -188,27 +208,33 @@ public enum TokensMtgImageSource implements CardImageSource {
// description on site may contain new information
// try to add it
URL url = new URL("http://tokens.mtg.onl/data/SetsWithTokens.csv");
try(InputStream inputStream = url.openStream()) {
try (InputStream inputStream = url.openStream()) {
List<TokenData> siteTokensData = parseTokensData(inputStream);
List<TokenData> newTokensData = new ArrayList<>();
for (TokenData siteData : siteTokensData) {
boolean isNew = true;
for (TokenData fileData : tokensData) {
if (siteData.getName().equalsIgnoreCase(fileData.getName())
&& siteData.getNumber().equalsIgnoreCase(fileData.getNumber())
&& siteData.getExpansionSetCode().equalsIgnoreCase(fileData.getExpansionSetCode())) {
isNew = false;
break;
String key = siteData.getExpansionSetCode() + "/" + siteData.getName();
supportedSets.add(siteData.getExpansionSetCode());
ArrayList<TokenData> list = tokensData.get(key);
if (list == null) {
list = new ArrayList<>();
tokensData.put(key, list);
list.add(siteData);
} else {
boolean newToken = true;
for (TokenData tokenData : list) {
if (siteData.getNumber().equals(tokenData.number)) {
newToken = false;
break;
}
}
if (newToken) {
list.add(siteData);
}
}
if (isNew) {
newTokensData.add(siteData);
}
}
tokensData.addAll(newTokensData);
} catch (Exception exception) {
logger.warn("Failed to get tokens description from tokens.mtg.onl", exception);
DownloadPictures.getInstance().updateAndViewMessage("");
} catch (Exception ex) {
logger.warn("Failed to get tokens description from tokens.mtg.onl", ex);
DownloadPictures.getInstance().updateAndViewMessage(ex.getMessage());
}
}
}
@ -219,8 +245,8 @@ public enum TokensMtgImageSource implements CardImageSource {
private List<TokenData> parseTokensData(InputStream inputStream) throws IOException {
List<TokenData> newTokensData = new ArrayList<>();
try(InputStreamReader inputReader = new InputStreamReader(inputStream, "Cp1252");
BufferedReader reader = new BufferedReader(inputReader)) {
try (InputStreamReader inputReader = new InputStreamReader(inputStream, "Cp1252");
BufferedReader reader = new BufferedReader(inputReader)) {
// we have to specify encoding to read special comma
reader.readLine(); // skip header
@ -285,7 +311,17 @@ public enum TokensMtgImageSource implements CardImageSource {
@Override
public int getTotalImages() {
return -1;
return getTokenImages();
}
@Override
public int getTokenImages() {
try {
getTokensData();
} catch (IOException ex) {
logger.error(getSourceName() + ": Loading available data failed. " + ex.getMessage());
}
return tokensData.size();
}
@Override
@ -296,4 +332,34 @@ public enum TokensMtgImageSource implements CardImageSource {
@Override
public void doPause(String httpImageUrl) {
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
@Override
public boolean isImageProvided(String setCode, String cardName) {
try {
getTokensData();
} catch (IOException ex) {
java.util.logging.Logger.getLogger(TokensMtgImageSource.class.getName()).log(Level.SEVERE, null, ex);
}
String key = setCode + "/" + cardName;
return (tokensData.containsKey(key));
}
@Override
public boolean isSetSupportedComplete(String setCode) {
return false;
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
}

View file

@ -34,10 +34,13 @@ import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -46,6 +49,7 @@ import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -58,10 +62,13 @@ import org.mage.plugins.card.images.CardDownloadData;
public enum WizardCardsImageSource implements CardImageSource {
instance;
private Map<String, String> setsAliases;
private Map<String, String> languageAliases;
private final Map<String, Map<String, String>> sets;
private static final Logger logger = Logger.getLogger(WizardCardsImageSource.class);
private final Map<String, String> setsAliases;
private final Map<String, String> languageAliases;
private final Map<String, Map<String, String>> sets;
private final Set<String> supportedSets;
@Override
public String getSourceName() {
@ -69,6 +76,198 @@ public enum WizardCardsImageSource implements CardImageSource {
}
WizardCardsImageSource() {
supportedSets = new LinkedHashSet<>();
// supportedSets.add("PTC"); // Prerelease Events
supportedSets.add("LEA");
supportedSets.add("LEB");
supportedSets.add("2ED");
supportedSets.add("ARN");
supportedSets.add("ATQ");
supportedSets.add("3ED");
supportedSets.add("LEG");
supportedSets.add("DRK");
supportedSets.add("FEM");
supportedSets.add("4ED");
supportedSets.add("ICE");
supportedSets.add("CHR");
supportedSets.add("HML");
supportedSets.add("ALL");
supportedSets.add("MIR");
supportedSets.add("VIS");
supportedSets.add("5ED");
supportedSets.add("POR");
supportedSets.add("WTH");
supportedSets.add("TMP");
supportedSets.add("STH");
supportedSets.add("EXO");
supportedSets.add("P02");
supportedSets.add("UGL");
supportedSets.add("USG");
supportedSets.add("DD3DVD");
supportedSets.add("DD3EVG");
supportedSets.add("DD3GVL");
supportedSets.add("DD3JVC");
supportedSets.add("ULG");
supportedSets.add("6ED");
supportedSets.add("UDS");
supportedSets.add("PTK");
supportedSets.add("S99");
supportedSets.add("MMQ");
// supportedSets.add("BRB");Battle Royale Box Set
supportedSets.add("NEM");
supportedSets.add("S00");
supportedSets.add("PCY");
supportedSets.add("INV");
// supportedSets.add("BTD"); // Beatdown Boxset
supportedSets.add("PLS");
supportedSets.add("7ED");
supportedSets.add("APC");
supportedSets.add("ODY");
// supportedSets.add("DKM"); // Deckmasters 2001
supportedSets.add("TOR");
supportedSets.add("JUD");
supportedSets.add("ONS");
supportedSets.add("LGN");
supportedSets.add("SCG");
supportedSets.add("8ED");
supportedSets.add("MRD");
supportedSets.add("DST");
supportedSets.add("5DN");
supportedSets.add("CHK");
supportedSets.add("UNH");
supportedSets.add("BOK");
supportedSets.add("SOK");
supportedSets.add("9ED");
supportedSets.add("RAV");
supportedSets.add("GPT");
supportedSets.add("DIS");
supportedSets.add("CSP");
supportedSets.add("TSP");
supportedSets.add("TSB");
supportedSets.add("PLC");
supportedSets.add("FUT");
supportedSets.add("10E");
supportedSets.add("MED");
supportedSets.add("LRW");
supportedSets.add("EVG");
supportedSets.add("MOR");
supportedSets.add("SHM");
supportedSets.add("EVE");
supportedSets.add("DRB");
supportedSets.add("ME2");
supportedSets.add("ALA");
supportedSets.add("DD2");
supportedSets.add("CON");
supportedSets.add("DDC");
supportedSets.add("ARB");
supportedSets.add("M10");
// supportedSets.add("TD0"); // Magic Online Deck Series
supportedSets.add("V09");
supportedSets.add("HOP");
supportedSets.add("ME3");
supportedSets.add("ZEN");
supportedSets.add("DDD");
supportedSets.add("H09");
supportedSets.add("WWK");
supportedSets.add("DDE");
supportedSets.add("ROE");
supportedSets.add("DPA");
supportedSets.add("ARC");
supportedSets.add("M11");
supportedSets.add("V10");
supportedSets.add("DDF");
supportedSets.add("SOM");
// supportedSets.add("TD0"); // Commander Theme Decks
supportedSets.add("PD2");
supportedSets.add("ME4");
supportedSets.add("MBS");
supportedSets.add("DDG");
supportedSets.add("NPH");
supportedSets.add("CMD");
supportedSets.add("M12");
supportedSets.add("V11");
supportedSets.add("DDH");
supportedSets.add("ISD");
supportedSets.add("PD3");
supportedSets.add("DKA");
supportedSets.add("DDI");
supportedSets.add("AVR");
supportedSets.add("PC2");
supportedSets.add("M13");
supportedSets.add("V12");
supportedSets.add("DDJ");
supportedSets.add("RTR");
supportedSets.add("CM1");
// supportedSets.add("TD2"); // Duel Decks: Mirrodin Pure vs. New Phyrexia
supportedSets.add("GTC");
supportedSets.add("DDK");
supportedSets.add("DGM");
supportedSets.add("MMA");
supportedSets.add("M14");
supportedSets.add("V13");
supportedSets.add("DDL");
supportedSets.add("THS");
supportedSets.add("C13");
supportedSets.add("BNG");
supportedSets.add("DDM");
supportedSets.add("JOU");
// supportedSets.add("MD1"); // Modern Event Deck
supportedSets.add("CNS");
supportedSets.add("VMA");
supportedSets.add("M15");
supportedSets.add("V14");
supportedSets.add("DDN");
supportedSets.add("KTK");
supportedSets.add("C14");
// supportedSets.add("DD3"); // Duel Decks Anthology
supportedSets.add("FRF");
supportedSets.add("DDO");
supportedSets.add("DTK");
supportedSets.add("TPR");
supportedSets.add("MM2");
supportedSets.add("ORI");
supportedSets.add("V15");
supportedSets.add("DDP");
supportedSets.add("BFZ");
supportedSets.add("EXP");
supportedSets.add("C15");
// supportedSets.add("PZ1"); // Legendary Cube
supportedSets.add("OGW");
supportedSets.add("DDQ");
supportedSets.add("W16");
supportedSets.add("SOI");
supportedSets.add("EMA");
supportedSets.add("EMN");
supportedSets.add("V16");
supportedSets.add("CN2");
supportedSets.add("DDR");
supportedSets.add("KLD");
supportedSets.add("MPS");
// supportedSets.add("PZ2"); // Treasure Chests
supportedSets.add("C16");
supportedSets.add("PCA");
supportedSets.add("AER");
supportedSets.add("MM3");
supportedSets.add("DDS");
supportedSets.add("W17");
supportedSets.add("AKH");
supportedSets.add("MPS");
supportedSets.add("CMA");
supportedSets.add("E01");
supportedSets.add("HOU");
supportedSets.add("C17");
// supportedSets.add("XLN");
// supportedSets.add("DDT");
// supportedSets.add("IMA");
// supportedSets.add("E02");
// supportedSets.add("V17");
// supportedSets.add("UST");
// supportedSets.add("RIX");
// supportedSets.add("A25");
// supportedSets.add("DOM");
// supportedSets.add("M19");
sets = new HashMap<>();
setsAliases = new HashMap<>();
setsAliases.put("2ED", "Unlimited Edition");
@ -102,6 +301,7 @@ public enum WizardCardsImageSource implements CardImageSource {
setsAliases.put("C14", "Commander 2014");
setsAliases.put("C15", "Commander 2015");
setsAliases.put("C16", "Commander 2016");
setsAliases.put("C17", "Commander 2017");
setsAliases.put("CMA", "Commander Anthology");
setsAliases.put("CHK", "Champions of Kamigawa");
setsAliases.put("CHR", "Chronicles");
@ -140,6 +340,7 @@ public enum WizardCardsImageSource implements CardImageSource {
setsAliases.put("DRK", "The Dark");
setsAliases.put("DST", "Darksteel");
setsAliases.put("DTK", "Dragons of Tarkir");
setsAliases.put("E01", "Archenemy: Nicol Bolas");
setsAliases.put("EMN", "Eldritch Moon");
setsAliases.put("EMA", "Eternal Masters");
setsAliases.put("EVE", "Eventide");
@ -272,18 +473,20 @@ public enum WizardCardsImageSource implements CardImageSource {
}
private Map<String, String> getSetLinks(String cardSet) {
ConcurrentHashMap<String, String> setLinks = new ConcurrentHashMap<>();
LinkedHashMap<String, String> setLinks = new LinkedHashMap<>();
ExecutorService executor = Executors.newFixedThreadPool(10);
try {
String setNames = setsAliases.get(cardSet);
String preferedLanguage = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, "en");
for (String setName : setNames.split("\\^")) {
String URLSetName = URLEncoder.encode(setName, "UTF-8");
// String URLSetName = URLEncoder.encode(setName, "UTF-8");
String URLSetName = setName.replaceAll(" ", "%20");
int page = 0;
int firstMultiverseIdLastPage = 0;
Pages:
while (page < 999) {
String searchUrl = "http://gatherer.wizards.com/Pages/Search/Default.aspx?page=" + page + "&output=spoiler&method=visual&action=advanced&set=+[%22" + URLSetName + "%22]";
String searchUrl = "http://gatherer.wizards.com/Pages/Search/Default.aspx?sort=cn+&page=" + page + "&action=advanced&output=spoiler&method=visual&set=+%5B%22" + URLSetName + "%22%5D";
logger.debug("URL: " + searchUrl);
Document doc = getDocument(searchUrl);
Elements cardsImages = doc.select("img[src^=../../Handlers/]");
if (cardsImages.isEmpty()) {
@ -307,7 +510,7 @@ public enum WizardCardsImageSource implements CardImageSource {
}
}
} catch (IOException ex) {
System.out.println("Exception when parsing the wizards page: " + ex.getMessage());
logger.error("Exception when parsing the wizards page: " + ex.getMessage());
}
executor.shutdown();
@ -327,14 +530,15 @@ public enum WizardCardsImageSource implements CardImageSource {
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
Document doc;
if (proxyType == ProxyType.NONE) {
doc = Jsoup.connect(urlString).get();
doc = Jsoup.connect(urlString).timeout(60 * 1000).get();
} else {
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
URL url = new URL(urlString);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
uc.setConnectTimeout(10000);
uc.setReadTimeout(60000);
uc.connect();
String line;
@ -356,7 +560,7 @@ public enum WizardCardsImageSource implements CardImageSource {
if (!variations.isEmpty()) {
int landNumber = 1;
for (Element variation : variations) {
Integer landMultiverseId = Integer.parseInt(variation.attr("onclick").replaceAll("[^\\d]", ""));
Integer landMultiverseId = Integer.parseInt(variation.attr("href").replaceAll("[^\\d]", ""));
links.put((cardName + landNumber).toLowerCase(), generateLink(landMultiverseId));
landNumber++;
}
@ -435,6 +639,9 @@ public enum WizardCardsImageSource implements CardImageSource {
String setNames = setsAliases.get(cardSet);
if (setNames != null) {
Map<String, String> setLinks = sets.computeIfAbsent(cardSet, k -> getSetLinks(cardSet));
if (setLinks == null || setLinks.isEmpty()) {
return null;
}
String link = setLinks.get(card.getDownloadName().toLowerCase());
if (link == null) {
int length = collectorId.length();
@ -444,11 +651,11 @@ public enum WizardCardsImageSource implements CardImageSource {
}
int number = Integer.parseInt(collectorId.substring(0, length));
if (setLinks.size() >= number) {
link = setLinks.get(Integer.toString(number - 1));
} else {
link = setLinks.get(Integer.toString(number - 21));
List<String> l = new ArrayList<>(setLinks.values());
if (l.size() >= number) {
link = l.get(number - 1);
} else {;
link = l.get(number - 21);
if (link != null) {
link = link.replace(Integer.toString(number - 20), (Integer.toString(number - 20) + 'a'));
}
@ -460,6 +667,7 @@ public enum WizardCardsImageSource implements CardImageSource {
return link;
}
return null;
}
@Override
@ -474,16 +682,24 @@ public enum WizardCardsImageSource implements CardImageSource {
private final class GetImageLinkTask implements Runnable {
private final int multiverseId;
private final String cardName;
private final String preferedLanguage;
private final ConcurrentHashMap setLinks;
private int multiverseId;
private String cardName;
private String preferedLanguage;
private LinkedHashMap setLinks;
public GetImageLinkTask(int multiverseId, String cardName, String preferedLanguage, ConcurrentHashMap setLinks) {
this.multiverseId = multiverseId;
this.cardName = cardName;
this.preferedLanguage = preferedLanguage;
this.setLinks = setLinks;
public GetImageLinkTask(int multiverseId, String cardName, String preferedLanguage, LinkedHashMap setLinks) {
try {
this.multiverseId = multiverseId;
this.cardName = cardName;
this.preferedLanguage = preferedLanguage;
this.setLinks = setLinks;
} catch (Exception ex) {
logger.error(ex.getMessage());
logger.error("multiverseId: " + multiverseId);
logger.error("cardName: " + cardName);
logger.error("preferedLanguage: " + preferedLanguage);
logger.error("setLinks: " + setLinks.toString());
}
}
@Override
@ -496,7 +712,7 @@ public enum WizardCardsImageSource implements CardImageSource {
setLinks.put(cardName.toLowerCase(), generateLink(preferedMultiverseId));
}
} catch (IOException | NumberFormatException ex) {
System.out.println("Exception when parsing the wizards page: " + ex.getMessage());
logger.error("Exception when parsing the wizards page: " + ex.getMessage());
}
}
@ -515,4 +731,12 @@ public enum WizardCardsImageSource implements CardImageSource {
@Override
public void doPause(String httpImageUrl) {
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
}

View file

@ -1,6 +1,7 @@
package org.mage.plugins.card.images;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
@ -14,18 +15,25 @@ import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.swing.*;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.sets.ConstructedFormats;
import mage.remote.Connection;
import static mage.remote.Connection.ProxyType.HTTP;
import static mage.remote.Connection.ProxyType.NONE;
import static mage.remote.Connection.ProxyType.SOCKS;
import net.java.truevfs.access.TFile;
import net.java.truevfs.access.TFileOutputStream;
import net.java.truevfs.access.TVFS;
@ -37,51 +45,97 @@ import org.mage.plugins.card.utils.CardImageUtils;
public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable {
private static DownloadPictures instance;
private static final Logger logger = Logger.getLogger(DownloadPictures.class);
public static final String ALL_IMAGES = "- All images from that source";
public static final String ALL_STANDARD_IMAGES = "- All images from standard from that source";
public static final String ALL_TOKENS = "- Only all token images from that source";
private JDialog dialog;
private final JProgressBar bar;
private final JOptionPane dlg;
private boolean cancel;
private final JButton closeButton;
private final JButton startDownloadButton;
private int cardIndex;
private List<CardDownloadData> cards;
private List<CardDownloadData> type2cards;
private final JComboBox jComboBox1;
private final JLabel jLabel1;
private static boolean offlineMode = false;
private JCheckBox checkBox;
private List<CardDownloadData> allCardsMissingImage;
private List<CardDownloadData> cardsToDownload;
private int missingCards = 0;
private int missingTokens = 0;
List<String> selectedSetCodes = new ArrayList<>();
private final JComboBox jComboBoxServer;
private final JLabel jLabelMessage;
private final JLabel jLabelAllMissing;
private final JLabel jLabelServer;
private final JComboBox jComboBoxSet;
private final JLabel jLabelSet;
private final Object sync = new Object();
private static CardImageSource cardImageSource;
private Proxy p = Proxy.NO_PROXY;
// private ExecutorService executor = Executors.newFixedThreadPool(10);
public static void main(String[] args) {
startDownload(null, null);
enum DownloadSources {
WIZARDS("wizards.com", WizardCardsImageSource.instance),
MYTHICSPOILER("mythicspoiler.com", MythicspoilerComSource.instance),
TOKENS("tokens.mtg.onl", TokensMtgImageSource.instance),
// MTG_ONL("mtg.onl", MtgOnlTokensImageSource.instance), Not working correctly yet
ALTERNATIVE("alternative.mtg.onl", AltMtgOnlTokensImageSource.instance),
GRAB_BAG("GrabBag", GrabbagImageSource.instance),
MAGIDEX("magidex.com", MagidexImageSource.instance),
SCRYFALL("scryfall.com", ScryfallImageSource.instance);
// MAGICCARDS("magiccards.info", MagicCardsImageSource.instance)
private final String text;
private final CardImageSource source;
DownloadSources(String text, CardImageSource sourceInstance) {
this.text = text;
this.source = sourceInstance;
}
public CardImageSource getSource() {
return source;
}
@Override
public String toString() {
return text;
}
}
public static void startDownload(JFrame frame, List<CardInfo> allCards) {
List<CardDownloadData> cards = getNeededCards(allCards);
public static DownloadPictures getInstance() {
return instance;
}
public static void main(String[] args) {
startDownload();
}
public static void startDownload() {
/*
* if (cards == null || cards.isEmpty()) {
* JOptionPane.showMessageDialog(null,
* "All card pictures have been downloaded."); return; }
*/
DownloadPictures download = new DownloadPictures(cards);
JDialog dlg = download.getDlg(frame);
dlg.setVisible(true);
dlg.dispose();
download.cancel = true;
instance = new DownloadPictures(MageFrame.getInstance());
Thread t1 = new Thread(new LoadMissingCardData(instance));
t1.start();
instance.getDlg().setVisible(true);
instance.getDlg().dispose();
instance.cancel = true;
}
public JDialog getDlg(JFrame frame) {
String title = "Downloading";
final JDialog dialog = this.dlg.createDialog(frame, title);
closeButton.addActionListener(e -> dialog.setVisible(false));
public JDialog getDlg() {
return dialog;
}
@ -89,75 +143,77 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
this.cancel = cancel;
}
public DownloadPictures(List<CardDownloadData> cards) {
this.cards = cards;
static int WIDTH = 400;
bar = new JProgressBar(this);
public DownloadPictures(JFrame frame) {
cardsToDownload = new ArrayList<>();
JPanel p0 = new JPanel();
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
p0.add(Box.createVerticalStrut(5));
jLabel1 = new JLabel();
jLabel1.setText("Please select server:");
jLabel1.setAlignmentX(Component.LEFT_ALIGNMENT);
p0.add(jLabel1);
jLabelMessage = new JLabel();
jLabelMessage.setAlignmentX(Component.CENTER_ALIGNMENT);
jLabelMessage.setText("Initializing image download...");
p0.add(jLabelMessage);
p0.add(Box.createVerticalStrut(5));
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[]{
// "magiccards.info",
"wizards.com",
"mythicspoiler.com",
"tokens.mtg.onl", //"mtgimage.com (HQ)",
"mtg.onl",
"alternative.mtg.onl",
"GrabBag",
"magidex.com",
"scryfall.com", //"mtgathering.ru HQ",
//"mtgathering.ru MQ",
//"mtgathering.ru LQ",
});
jComboBox1 = new JComboBox();
cardImageSource = MagicCardsImageSource.instance;
jLabelAllMissing = new JLabel();
jComboBox1.setModel(jComboBox1Model);
jComboBox1.setAlignmentX(Component.LEFT_ALIGNMENT);
jComboBox1.addActionListener(e -> {
JComboBox cb = (JComboBox) e.getSource();
switch (cb.getSelectedIndex() + 1) {
case 0:
cardImageSource = MagicCardsImageSource.instance;
break;
case 1:
cardImageSource = WizardCardsImageSource.instance;
break;
case 2:
cardImageSource = MythicspoilerComSource.instance;
break;
case 3:
cardImageSource = TokensMtgImageSource.instance;
break;
case 4:
cardImageSource = MtgOnlTokensImageSource.instance;
break;
case 5:
cardImageSource = AltMtgOnlTokensImageSource.instance;
break;
case 6:
cardImageSource = GrabbagImageSource.instance;
break;
case 7:
cardImageSource = MagidexImageSource.instance;
break;
case 8:
cardImageSource = ScryfallImageSource.instance;
break;
jLabelAllMissing.setAlignmentX(Component.LEFT_ALIGNMENT);
// jLabelAllMissing.setText("Computing number of missing images...");
p0.add(jLabelAllMissing);
p0.add(Box.createVerticalStrut(5));
jLabelServer = new JLabel();
jLabelServer.setText("Please select image source:");
jLabelServer.setAlignmentX(Component.LEFT_ALIGNMENT);
jLabelServer.setVisible(false);
p0.add(jLabelServer);
p0.add(Box.createVerticalStrut(5));
jComboBoxServer = new JComboBox();
jComboBoxServer.setModel(new DefaultComboBoxModel(DownloadSources.values()));
jComboBoxServer.setAlignmentX(Component.LEFT_ALIGNMENT);
jComboBoxServer.setAlignmentY(Component.LEFT_ALIGNMENT);
jComboBoxServer.addItemListener((ItemEvent event) -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
comboBoxServerItemSelected(event);
}
updateCardsToDownload();
});
p0.add(jComboBox1);
Dimension d = jComboBoxServer.getPreferredSize();
d.width = WIDTH;
jComboBoxServer.setPreferredSize(d);
p0.add(jComboBoxServer);
jComboBoxServer.setVisible(false);
// set the first source as default
cardImageSource = WizardCardsImageSource.instance;
p0.add(Box.createVerticalStrut(5));
// Set selection ---------------------------------
jLabelSet = new JLabel();
jLabelSet.setText("Please select sets to download the images for:");
jLabelSet.setAlignmentX(Component.LEFT_ALIGNMENT);
jLabelSet.setVisible(false);
p0.add(jLabelSet);
jComboBoxSet = new JComboBox();
// jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
jComboBoxSet.setAlignmentX(Component.LEFT_ALIGNMENT);
jComboBoxSet.addItemListener((ItemEvent event) -> {
if (event.getStateChange() == ItemEvent.SELECTED) {
comboBoxSetItemSelected(event);
}
});
p0.add(jComboBoxSet);
jComboBoxSet.setVisible(false);
p0.add(Box.createVerticalStrut(5));
// Start
@ -165,78 +221,168 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
startDownloadButton.addActionListener(e -> {
new Thread(DownloadPictures.this).start();
startDownloadButton.setEnabled(false);
checkBox.setEnabled(false);
});
p0.add(Box.createVerticalStrut(5));
// Progress
bar = new JProgressBar(this);
p0.add(bar);
bar.setStringPainted(true);
int count = cards.size();
float mb = (count * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format(cardIndex == cards.size() ? "%d of %d cards finished! Please close!"
: "%d of %d cards finished! Please wait! [%.1f Mb]", 0, cards.size(), mb));
Dimension d = bar.getPreferredSize();
d.width = 300;
d = bar.getPreferredSize();
d.width = WIDTH;
bar.setPreferredSize(d);
p0.add(Box.createVerticalStrut(5));
checkBox = new JCheckBox("Download images for Standard (Type2) only");
p0.add(checkBox);
p0.add(Box.createVerticalStrut(5));
checkBox.addActionListener(e -> updateCardsToDownload());
bar.setVisible(false);
// JOptionPane
Object[] options = {startDownloadButton, closeButton = new JButton("Cancel")};
startDownloadButton.setVisible(false);
closeButton.addActionListener(e -> dialog.setVisible(false));
closeButton.setVisible(false);
dlg = new JOptionPane(p0, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[1]);
dialog = this.dlg.createDialog(frame, "Downloading images");
}
public static boolean checkForMissingCardImages(List<CardInfo> allCards) {
AtomicBoolean missedCardTFiles = new AtomicBoolean();
allCards.parallelStream().forEach(card -> {
if (!missedCardTFiles.get()) {
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()) {
CardDownloadData url = new CardDownloadData(card.getName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(),
0, "", "", false, card.isDoubleFaced(), card.isNightCard());
TFile file = new TFile(CardImageUtils.generateImagePath(url));
if (!file.exists()) {
missedCardTFiles.set(true);
public void setAllMissingCards() {
updateAndViewMessage("Get all available cards from the repository...");
List<CardInfo> cards = CardRepository.instance.findCards(new CardCriteria());
updateAndViewMessage("Check which images are missing ...");
this.allCardsMissingImage = getNeededCards(cards);
updateAndViewMessage("Check which images the current source is providing ...");
jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
jComboBoxServer.setVisible(true);
jLabelServer.setVisible(true);
jComboBoxSet.setVisible(true);
jLabelSet.setVisible(true);
bar.setVisible(true);
startDownloadButton.setVisible(true);
closeButton.setVisible(true);
updateAndViewMessage("");
}
private void comboBoxServerItemSelected(ItemEvent evt) {
if (jComboBoxServer.isEnabled()) {
cardImageSource = ((DownloadSources) evt.getItem()).getSource();
// update the available sets / token comboBox
jComboBoxSet.setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
}
}
public void updateAndViewMessage(String text) {
jLabelMessage.setText(text);
if (dialog != null) {
dialog.pack();
dialog.validate();
dialog.repaint();
}
}
private Object[] getSetsForCurrentImageSource() {
// Set the available sets to the combo box
ArrayList<String> supportedSets = cardImageSource.getSupportedSets();
List<String> setNames = new ArrayList<>();
if (supportedSets != null) {
setNames.add(ALL_IMAGES);
setNames.add(ALL_STANDARD_IMAGES);
}
if (cardImageSource.isTokenSource()) {
setNames.add(ALL_TOKENS);
}
if (supportedSets != null) {
for (String setCode : supportedSets) {
ExpansionSet expansionSet = Sets.findSet(setCode);
if (expansionSet != null) {
setNames.add(expansionSet.getName());
} else {
logger.error(cardImageSource.getSourceName() + ": Expansion set for code " + setCode + " not found!");
}
}
}
if (setNames.isEmpty()) {
logger.error("Source " + cardImageSource.getSourceName() + " creates no selectable items.");
setNames.add("not avalable");
}
return setNames.toArray(new String[0]);
}
private void updateCardsToDownload(String itemText) {
selectedSetCodes.clear();
switch (itemText) {
case ALL_IMAGES:
if (cardImageSource.getSupportedSets() == null) {
selectedSetCodes = cardImageSource.getSupportedSets();
} else {
selectedSetCodes.addAll(cardImageSource.getSupportedSets());
}
break;
case ALL_STANDARD_IMAGES:
List<String> standardSets = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
for (String setCode : cardImageSource.getSupportedSets()) {
if (standardSets.contains(setCode)) {
selectedSetCodes.add(setCode);
} else {
logger.debug("Set code " + setCode + " from download source " + cardImageSource.getSourceName());
}
}
break;
case ALL_TOKENS:
break;
default:
int nonSetEntries = 0;
if (cardImageSource.getSupportedSets() != null) {
nonSetEntries = 2;
}
if (cardImageSource.isTokenSource()) {
nonSetEntries++;
}
selectedSetCodes.add(cardImageSource.getSupportedSets().get(jComboBoxSet.getSelectedIndex() - nonSetEntries));
}
cardsToDownload.clear();
int numberTokenImagesAvailable = 0;
int numberCardImagesAvailable = 0;
for (CardDownloadData data : allCardsMissingImage) {
if (data.isToken()) {
if (cardImageSource.isTokenSource() && cardImageSource.isImageProvided(data.getSet(), data.getName())) {
numberTokenImagesAvailable++;
cardsToDownload.add(data);
}
} else {
if (selectedSetCodes != null && selectedSetCodes.contains(data.getSet())) {
if (cardImageSource.isSetSupportedComplete(data.getSet()) || cardImageSource.isImageProvided(data.getSet(), data.getName())) {
numberCardImagesAvailable++;
cardsToDownload.add(data);
}
}
}
});
return missedCardTFiles.get();
}
private void updateCardsToDownload() {
List<CardDownloadData> cardsToDownload = cards;
if (type2cardsOnly()) {
selectType2andTokenCardsIfNotYetDone();
cardsToDownload = type2cards;
}
updateProgressText(cardsToDownload.size());
updateProgressText(numberCardImagesAvailable, numberTokenImagesAvailable);
}
private boolean type2cardsOnly() {
return checkBox.isSelected();
private void comboBoxSetItemSelected(ItemEvent event) {
// Update the cards to download related to the selected set
updateCardsToDownload(event.getItem().toString());
}
private void selectType2andTokenCardsIfNotYetDone() {
if (type2cards == null) {
type2cards = new ArrayList<>();
for (CardDownloadData data : cards) {
if (data.isType2() || data.isToken()) {
type2cards.add(data);
}
private void updateProgressText(int cardCount, int tokenCount) {
missingTokens = 0;
for (CardDownloadData card : allCardsMissingImage) {
if (card.isToken()) {
missingTokens++;
}
}
}
private void updateProgressText(int cardCount) {
float mb = (cardCount * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format(cardIndex == cardCount ? "%d of %d cards finished! Please close!"
: "%d of %d cards finished! Please wait! [%.1f Mb]", 0, cardCount, mb));
missingCards = allCardsMissingImage.size() - missingTokens;
jLabelAllMissing.setText("Missing: " + missingCards + " card images / " + missingTokens + " token images");
int imageSum = cardCount + tokenCount;
float mb = (imageSum * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format(cardIndex == imageSum ? "%d of %d (%d cards/%d tokens) image downloads finished! Please close!"
: "%d of %d (%d cards/%d tokens) image downloads finished! Please wait! [%.1f Mb]", 0, imageSum, cardCount, tokenCount, mb));
}
private static String createDownloadName(CardInfo card) {
@ -262,11 +408,8 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
logger.warn("No formats defined. Try connecting to a server first!");
}
int numberCardImages = allCards.size();
int numberWithoutTokens = 0;
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
try {
offlineMode = true;
allCards.parallelStream().forEach(card -> {
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()
&& !ignoreUrls.contains(card.getSetCode())) {
@ -308,14 +451,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
logger.error("Card has no set name and won't be sent to client:" + card.getName());
}
});
numberWithoutTokens = allCards.size();
allCardsUrls.addAll(getTokenCardUrls());
} catch (Exception e) {
logger.error(e);
}
int numberAllTokenImages = allCardsUrls.size() - numberWithoutTokens;
/**
* check to see which cards we already have
*/
@ -329,22 +469,13 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
}
});
int tokenImages = 0;
for (CardDownloadData card : cardsToDownload) {
logger.debug((card.isToken() ? "Token" : "Card") + " image to download: " + card.getName() + " (" + card.getSet() + ')');
if (card.isToken()) {
tokenImages++;
}
}
logger.info("Check download images (total card images: " + numberCardImages + ", total token images: " + numberAllTokenImages + ')');
logger.info(" => Missing card images: " + (cardsToDownload.size() - tokenImages));
logger.info(" => Missing token images: " + tokenImages);
return new ArrayList<>(cardsToDownload);
}
public static ArrayList<CardDownloadData> getTokenCardUrls() throws RuntimeException {
ArrayList<CardDownloadData> list = new ArrayList<>();
InputStream in = DownloadPictures.class.getClassLoader().getResourceAsStream("card-pictures-tok.txt");
InputStream in = DownloadPictures.class
.getClassLoader().getResourceAsStream("card-pictures-tok.txt");
if (in == null) {
logger.error("resources input stream is null");
@ -446,9 +577,8 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
if (p != null) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
List<CardDownloadData> cardsToDownload = this.checkBox.isSelected() ? type2cards : cards;
update(0, cardsToDownload.size());
logger.info("Started download of " + cardsToDownload.size() + " images from source: " + cardImageSource.getSourceName());
int numberOfThreads = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_THREADS, "10"));
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
@ -457,7 +587,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
CardDownloadData card = cardsToDownload.get(i);
logger.debug("Downloading card: " + card.getName() + " (" + card.getSet() + ')');
logger.debug("Downloading image: " + card.getName() + " (" + card.getSet() + ')');
String url;
if (ignoreUrls.contains(card.getSet()) || card.isToken()) {
@ -482,7 +612,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
} catch (Exception ex) {
}
} else if (cardImageSource.getTotalImages() == -1) {
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
logger.info("Image not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
synchronized (sync) {
update(cardIndex + 1, cardsToDownload.size());
}
@ -513,6 +643,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
System.gc();
}
closeButton.setText("Close");
updateCardsToDownload(jComboBoxSet.getSelectedItem().toString());
}
static String convertStreamToString(java.io.InputStream is) {
@ -604,6 +735,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
if (temporaryFile != null && temporaryFile.length() > 100) {
useTempFile = true;
} else {
cardImageSource.doPause(url.getPath());
httpConn = url.openConnection(p);
httpConn.connect();
@ -708,29 +840,52 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
if (cardIndex < count) {
float mb = ((count - card) * cardImageSource.getAverageSize()) / 1024;
bar.setString(String.format("%d of %d cards finished! Please wait! [%.1f Mb]",
bar.setString(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]",
card, count, mb));
} else {
List<CardDownloadData> remainingCards = Collections.synchronizedList(new ArrayList<>());
DownloadPictures.this.cards.parallelStream().forEach(cardDownloadData -> {
DownloadPictures.this.allCardsMissingImage.parallelStream().forEach(cardDownloadData -> {
TFile file = new TFile(CardImageUtils.generateImagePath(cardDownloadData));
if (!file.exists()) {
remainingCards.add(cardDownloadData);
}
});
DownloadPictures.this.cards = new ArrayList<>(remainingCards);
// remove the cards not downloaded to get the siccessfull downloaded cards
DownloadPictures.this.cardsToDownload.removeAll(remainingCards);
DownloadPictures.this.allCardsMissingImage.removeAll(DownloadPictures.this.cardsToDownload);
count = DownloadPictures.this.cards.size();
count = remainingCards.size();
if (count == 0) {
bar.setString("0 cards remaining! Please close!");
bar.setString("0 images remaining! Please close!");
} else {
bar.setString(String.format("%d cards remaining! Please choose another source!", count));
// bar.setString(String.format("%d cards remaining! Please choose another source!", count));
startDownloadButton.setEnabled(true);
}
}
}
private static final long serialVersionUID = 1L;
}
class LoadMissingCardData implements Runnable {
private static DownloadPictures downloadPictures;
public LoadMissingCardData(DownloadPictures downloadPictures) {
LoadMissingCardData.downloadPictures = downloadPictures;
}
@Override
public void run() {
downloadPictures.setAllMissingCards();
}
public static void main() {
(new Thread(new LoadMissingCardData(downloadPictures))).start();
}
}

View file

@ -222,7 +222,7 @@ Eldrazi Spawn, 1a, -, -, -, Creature - Eldrazi Spawn, Aleksi Briclot, Sacrifice
Eldrazi Spawn, 1b, -, -, -, Creature - Eldrazi Spawn, Mark Tedin, Sacrifice this creature: Add {1} to your mana pool.
Eldrazi Spawn, 1c, -, -, -, Creature - Eldrazi Spawn, Veronique Meignaud, Sacrifice this creature: Add {1} to your mana pool.
Elemental, 2, R, *|*, -, Creature - Elemental, Jung Park, -
Hellion, 3, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Hellion, 1, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Ooze, 4, G, *|*, -, Creature - Ooze, Daniel Ljunggren, -
Tuktuk The Returned, 5, -, 5|5, -, Legendary Artifact Creature - Goblin Golem, Franz Vohwinkel, -
@ -344,7 +344,7 @@ Soldier, 3, W, 1|1, -, Creature - Soldier, Greg Staples, -
Drake, 4, U, 2|2, -, Creature - Drake, Svetlin Velinov, Flying
Zombie, 5, B, 2|2, -, Creature - Zombie, Lucas Graciano, -
Goblin, 6, R, 1|1, -, Creature - Goblin, Karl Kopinski, -
Hellion, 7, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Hellion, 1, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Beast, 8, G, 3|3, -, Creature - Beast, John Donahue, -
Saproling, 9, G, 1|1, -, Creature - Saproling, Brad Rigney, -
Wurm, 10, G, 6|6, -, Creature - Wurm, Anthony Francisco, -
@ -664,7 +664,7 @@ DDP - Duel Decks: Zendikar vs. Eldrazi (2015-08-28)
Eldrazi Spawn, 076, -, -, -, Creature - Eldrazi Spawn, Aleksi Briclot, Sacrifice this creature: Add {1} to your mana pool.
Eldrazi Spawn, 077, -, -, -, Creature - Eldrazi Spawn, Veronique Meignaud, Sacrifice this creature: Add {1} to your mana pool.
Eldrazi Spawn, 078, -, -, -, Creature - Eldrazi Spawn, Mark Tedin, Sacrifice this creature: Add {1} to your mana pool.
Hellion, 079, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Hellion, 1, R, 4|4, -, Creature - Hellion, Anthony Francisco, -
Plant, 080, G, -, -, Creature - Plant, Daren Bader, -
BFZ - Battle for Zendikar (2015-10-09)
@ -745,3 +745,20 @@ Clue, 015, -, -, -, Artifact - Clue, James Paick, {2} Sacrifice this Artifact
Clue, 016, -, -, -, Artifact - Clue, Franz Vohwinkel, {2} Sacrifice this Artifact: Draw a card.
Jace Emblem, 017, -, -, -, Emblem - Jace, Tyler Jacobson, Whenever an opponent casts his or her first spell each turn<72> counter that spell.
Arlinn Emblem, 018, -, -, -, Emblem - Arlinn, Winona Nelson, Creatures you control have haste and '{T}: This creature deals damage equal to its power to target creature or player.'
SWS - Star Wars Custom set
Rebel, 001, W, 1|1, -, Creature - Rebel, Alex Konstad, -
Trooper, 002, W, 1|1, -, Creature - Trooper, Darren Tan, -
Tusken Raider, 003, W, 1|1, -, Creature - Tusken Raider, William O'Connor, -
Ewok, 004, G, 1|1, -, Creature - Ewok, Chris NG, -
Hunter, 005, R, 4|4, -, Creature - Hunter, Steve Argyle, -
Royal Guard, 006, R, 2|2, -, Creature - Soldier, Aldo Katayanagi, First Strike
AT-AT, 007, -, 5|5, -, Artifact Creature - AT-AT, Prokhoda, When this creature dies<65> create two 1/1 white Trooper creature tokens.
B-Wing, 008, -, 1|1, -, Artifact Creature - Rebel Starship, Anthony Devine, Spaceflight
Droid, 009, -, 1|1, -, Artifact Creature - Droid, PeetuGee, -
TIE Fighter, 010, -, 1|1, -, Artifact Creature - Starship, Darren Tan, Spaceflight
Yoda Emblem, 011, -, -, -, Emblem - Yoda, Jerry Vanderstelt, Hexproof<6F> you and your creatures have.
Obi-Wan Kenobi Emblem, 012, -, -, -, Emblem - Obi-Wan Kenobi, Jerry Vanderstelt, Creatures you control get +1/+1 and have vigilance<63> first strike<6B> and lifelink.
Aurra Sing Emblem, 013, -, -, -, Emblem - Aurra Sing, Willman1701, Whenever a nontoken creature you control leaves the battlefield<6C> discard a card.

Can't render this file because it contains an unexpected character in line 549 and column 140.

View file

@ -1,5 +1,5 @@
#Generated by Maven
#Mon Aug 28 09:53:46 CEST 2017
version=1.4.26
groupId=org.mage
artifactId=mage-game-pennydreadfulcommanderfreeforall
#Generated by Maven
#Fri Sep 15 22:14:29 CEST 2017
version=1.4.26
groupId=org.mage
artifactId=mage-game-pennydreadfulcommanderfreeforall

View file

@ -44,6 +44,7 @@ public class EssenceScatter extends CardImpl {
public EssenceScatter(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}");
// Counter target creature spell.
this.getSpellAbility().addTarget(new TargetSpell(new FilterCreatureSpell()));
this.getSpellAbility().addEffect(new CounterTargetEffect());
}