mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Updated WizardCardsImageSource (can get images from an uncomplete spoiler now)
This commit is contained in:
parent
2a408cfc13
commit
49435820d1
5 changed files with 52 additions and 39 deletions
|
|
@ -6,7 +6,7 @@ package org.mage.plugins.card.dl.sources;
|
|||
*/
|
||||
public interface CardImageSource {
|
||||
|
||||
String generateURL(Integer collectorId, String cardSet) throws Exception;
|
||||
String generateURL(Integer collectorId, String cardName, String cardSet) throws Exception;
|
||||
String generateTokenUrl(String name, String set);
|
||||
Float getAverageSize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String generateURL(Integer collectorId, String cardSet) throws Exception {
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet) throws Exception {
|
||||
if (collectorId == null || cardSet == null) {
|
||||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class MtgatheringRuImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String generateURL(Integer collectorId, String cardSet) throws Exception {
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet) throws Exception {
|
||||
if (collectorId == null || cardSet == null) {
|
||||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
|
@ -29,7 +27,9 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
public WizardCardsImageSource() {
|
||||
sets = new HashMap();
|
||||
setsAliases = new HashMap();
|
||||
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");
|
||||
|
|
@ -43,13 +43,25 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
setsAliases.put("ALA", "shardsofalara/spoiler");
|
||||
}
|
||||
|
||||
private List<String> getSetLinks(String cardSet) {
|
||||
List<String> setLinks = new ArrayList<String>();
|
||||
private Map<String, String> getSetLinks(String cardSet) {
|
||||
Map<String, String> setLinks = new HashMap<String, String>();
|
||||
try {
|
||||
Document doc = Jsoup.connect("http://www.wizards.com/magic/tcg/article.aspx?x=mtg/tcg/" + (String) setsAliases.get(cardSet)).get();
|
||||
Elements cardsImages = doc.select("img[height$=370]");
|
||||
for (int i = 0; i < cardsImages.size(); i++) {
|
||||
setLinks.add(cardsImages.get(i).attr("src"));
|
||||
String cardName = cardsImages.get(i).attr("title").replace("Æ", "AE");
|
||||
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) != null) {
|
||||
landNumber++;
|
||||
}
|
||||
cardName += landNumber;
|
||||
}
|
||||
setLinks.put(cardName, 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());
|
||||
|
|
@ -58,22 +70,26 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String generateURL(Integer collectorId, String cardSet) throws Exception {
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet) throws Exception {
|
||||
if (collectorId == null || cardSet == null) {
|
||||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
if (setsAliases.get(cardSet) != null) {
|
||||
List<String> setLinks = (List<String>) sets.get(cardSet);
|
||||
Map<String, String> setLinks = (Map<String, String>) sets.get(cardSet);
|
||||
if (setLinks == null) {
|
||||
setLinks = getSetLinks(cardSet);
|
||||
sets.put(cardSet, setLinks);
|
||||
}
|
||||
String link;
|
||||
if (setLinks.size() >= collectorId) {
|
||||
link = setLinks.get(collectorId - 1);
|
||||
} else {
|
||||
link = setLinks.get(collectorId - 21);
|
||||
link = link.replace(Integer.toString(collectorId - 20), (Integer.toString(collectorId - 20) + "a"));
|
||||
String link = setLinks.get(cardName);
|
||||
if (link == null) {
|
||||
if (setLinks.size() >= collectorId) {
|
||||
link = setLinks.get(Integer.toString(collectorId - 1));
|
||||
} else {
|
||||
link = setLinks.get(Integer.toString(collectorId - 21));
|
||||
if (link != null) {
|
||||
link = link.replace(Integer.toString(collectorId - 20), (Integer.toString(collectorId - 20) + "a"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!link.startsWith("http://")) {
|
||||
link = "http://www.wizards.com" + link;
|
||||
|
|
|
|||
|
|
@ -20,13 +20,9 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.management.ImmutableDescriptor;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ComboBoxModel;
|
||||
import javax.swing.DefaultBoundedRangeModel;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
|
|
@ -39,14 +35,11 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import mage.cards.Card;
|
||||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.remote.Connection;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -156,7 +149,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
|
||||
p0.add(jLabel1);
|
||||
p0.add(Box.createVerticalStrut(5));
|
||||
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "magiccards.info", "wizards.com", "mtgathering.ru HQ", "mtgathering.ru MQ", "mtgathering.ru LQ"});
|
||||
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "magiccards.info", "wizards.com"/*, "mtgathering.ru HQ", "mtgathering.ru MQ", "mtgathering.ru LQ"*/});
|
||||
jComboBox1 = new JComboBox();
|
||||
|
||||
cardImageSource = MagicCardsImageSource.getInstance();
|
||||
|
|
@ -266,20 +259,24 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
try {
|
||||
offlineMode = true;
|
||||
|
||||
for (Card card : allCards) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
|
||||
CardInfo url = new CardInfo(card.getName(), card.getExpansionSetCode(), card.getCardNumber(), false);
|
||||
allCardsUrls.add(url);
|
||||
} else {
|
||||
if (card.getCardNumber() < 1) {
|
||||
System.err.println("There was a critical error!");
|
||||
log.error("Card has no collector ID and won't be sent to client: " + card);
|
||||
} else if (card.getExpansionSetCode().isEmpty()) {
|
||||
System.err.println("There was a critical error!");
|
||||
log.error("Card has no set name and won't be sent to client:" + card);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Card card : allCards) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
|
||||
String cardName = card.getName();
|
||||
if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
|
||||
cardName = card.getClass().getName().replace(card.getClass().getPackage().getName() + ".", "");
|
||||
}
|
||||
CardInfo url = new CardInfo(cardName, card.getExpansionSetCode(), card.getCardNumber(), false);
|
||||
allCardsUrls.add(url);
|
||||
} else {
|
||||
if (card.getCardNumber() < 1) {
|
||||
System.err.println("There was a critical error!");
|
||||
log.error("Card has no collector ID and won't be sent to client: " + card);
|
||||
} else if (card.getExpansionSetCode().isEmpty()) {
|
||||
System.err.println("There was a critical error!");
|
||||
log.error("Card has no set name and won't be sent to client:" + card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allCardsUrls.addAll(getTokenCardUrls());
|
||||
} catch (Exception e) {
|
||||
|
|
@ -442,7 +439,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
url = cardImageSource.generateTokenUrl(card.getName(), card.getSet());
|
||||
} else {
|
||||
url = cardImageSource.generateURL(card.getCollectorId(), card.getSet());
|
||||
url = cardImageSource.generateURL(card.getCollectorId(), card.getName(), card.getSet());
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue