Some more changes to image download.

This commit is contained in:
LevelX2 2017-09-05 00:12:09 +02:00
parent a2a454bfc9
commit 7329dc6c3f
4 changed files with 305 additions and 43 deletions

View file

@ -28,7 +28,11 @@
package org.mage.plugins.card.dl.sources;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
@ -37,12 +41,34 @@ import org.mage.plugins.card.images.CardDownloadData;
*
* @author spjspj
*/
public enum GrabbagImageSource implements CardImageSource {
public enum GrabbagImageSource implements CardImageSource {
instance;
private static final Logger logger = Logger.getLogger(GrabbagImageSource.class);
private static int maxTimes = 0;
private static final Set<String> supportedSets = new LinkedHashSet<String>() {
{
add("PTC");
add("EXP");
add("APAC");
add("ARENA");
add("FNMP");
add("GPX");
add("GRC");
add("JR");
add("MBP");
add("MGDC");
add("MLP");
add("MPRP");
add("MPS");
add("SUS");
add("UGIN");
add("WMCQ");
}
};
@Override
public String getSourceName() {
return "";
@ -55,36 +81,37 @@ public enum GrabbagImageSource implements CardImageSource {
@Override
public String getNextHttpImageUrl() {
if (copyUrlToImage == null) {
setupLinks();
}
for (String key : copyUrlToImageDone.keySet()) {
if (copyUrlToImageDone.get(key) < maxTimes) {
copyUrlToImageDone.put(key, maxTimes);
return getSourceName(key) + key;
}
}
if (maxTimes < 2) {
maxTimes++;
}
for (String key : copyUrlToImageDone.keySet()) {
if (copyUrlToImageDone.get(key) < maxTimes) {
copyUrlToImageDone.put(key, maxTimes);
return getSourceName(key) + key;
}
}
return null;
// if (copyUrlToImage == null) {
// setupLinks();
// }
//
// for (String key : copyUrlToImageDone.keySet()) {
// if (copyUrlToImageDone.get(key) < maxTimes) {
// copyUrlToImageDone.put(key, maxTimes);
// return getSourceName(key) + key;
// }
// }
// if (maxTimes < 2) {
// maxTimes++;
// }
// for (String key : copyUrlToImageDone.keySet()) {
// if (copyUrlToImageDone.get(key) < maxTimes) {
// copyUrlToImageDone.put(key, maxTimes);
// return getSourceName(key) + key;
// }
// }
// return null;
}
@Override
public String getFileForHttpImage(String httpImageUrl) {
String copy = httpImageUrl;
if (copy != null) {
copy = copy.replaceFirst("http:\\/\\/static.starcitygames.com\\/sales\\/cardscans\\/", "");
copy = copy.replaceFirst("http:\\/\\/magiccards.info\\/scans\\/en\\/", "");
return copyUrlToImage.get(copy);
}
// String copy = httpImageUrl;
// if (copy != null) {
// copy = copy.replaceFirst("http:\\/\\/static.starcitygames.com\\/sales\\/cardscans\\/", "");
// copy = copy.replaceFirst("http:\\/\\/magiccards.info\\/scans\\/en\\/", "");
// return copyUrlToImage.get(copy);
// }
return null;
}
@ -93,6 +120,11 @@ public enum GrabbagImageSource implements CardImageSource {
if (copyUrlToImage == null) {
setupLinks();
}
for (Map.Entry<String, String> urlInfo : copyUrlToImage.entrySet()) {
if (urlInfo.getValue().contains(card.getSet()) && urlInfo.getValue().contains(card.getName())) {
return getSourceName(urlInfo.getValue()) + urlInfo.getKey();
}
}
return null;
}
@ -108,16 +140,16 @@ public enum GrabbagImageSource implements CardImageSource {
copyImageToUrl = new HashMap<>();
copyUrlToImageDone = new HashMap<>();
//http://anonymouse.org/cgi-bin/anon-www.cgi/http://magiccards.info/scans/en/arena/42.jpg
copyUrlToImage.put("MTG/BNG/en/promo/ArbiterOfTheIdeal.jpg", "PTC.zip/PTC/Arbiter of the Ideal.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/CourserOfKruphix.jpg", "PTC.zip/PTC/Courser of Kruphix.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/EaterOfHope.jpg", "PTC.zip/PTC/Eater of Hope.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/FatedReturn.jpg", "PTC.zip/PTC/Fated Return.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/ForgestokerDragon.jpg", "PTC.zip/PTC/Forgestoker Dragon.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/NessianWildsRavager.jpg", "PTC.zip/PTC/Nessian Wilds Ravager.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/PainSeer.jpg", "PTC.zip/PTC/Pain Seer.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/SilentSentinel.jpg", "PTC.zip/PTC/Silent Sentinel.full.jpg");
copyUrlToImage.put("MTG/BNG/en/promo/Tromokratis.jpg", "PTC.zip/PTC/Tromokratis.full.jpg");
copyUrlToImage.put("PTC/Arbiter of the Ideal", "MTG/BNG/en/promo/ArbiterOfTheIdeal.jpg");
copyUrlToImage.put("PTC/Courser of Kruphix", "MTG/BNG/en/promo/CourserOfKruphix.jpg");
copyUrlToImage.put("PTC/Eater of Hope", "MTG/BNG/en/promo/EaterOfHope.jpg");
copyUrlToImage.put("PTC/Fated Return", "MTG/BNG/en/promo/FatedReturn.jpg");
copyUrlToImage.put("PTC/Forgestoker Dragon", "MTG/BNG/en/promo/ForgestokerDragon.jpg");
copyUrlToImage.put("PTC/Nessian Wilds Ravager", "MTG/BNG/en/promo/NessianWildsRavager.jpg");
copyUrlToImage.put("PTC/Pain Seer", "MTG/BNG/en/promo/PainSeer.jpg");
copyUrlToImage.put("PTC/Silent Sentinel", "MTG/BNG/en/promo/SilentSentinel.jpg");
copyUrlToImage.put("PTC/Tromokratis", "MTG/BNG/en/promo/Tromokratis.jpg");
copyUrlToImage.put("MTG/FRF/en/promo/prerelease/AleshaWhoSmilesAtDeath.jpg", "PTC.zip/PTC/Alesha, Who Smiles at Death.full.jpg");
copyUrlToImage.put("MTG/FRF/en/promo/prerelease/Arcbond.jpg", "PTC.zip/PTC/Arcbond.full.jpg");
copyUrlToImage.put("MTG/FRF/en/promo/prerelease/ArchfiendOfDepravity.jpg", "PTC.zip/PTC/Archfiend of Depravity.full.jpg");
@ -1687,6 +1719,13 @@ public enum GrabbagImageSource implements CardImageSource {
}
}
@Override
public ArrayList<String> getSupportedSets() {
ArrayList<String> supportedSetsCopy = new ArrayList<>();
supportedSetsCopy.addAll(supportedSets);
return supportedSetsCopy;
}
@Override
public void doPause(String httpImageUrl) {
if (!httpImageUrl.startsWith("/MTG")) {

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

@ -674,6 +674,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();