* Some fixes to symbol download for sets.

This commit is contained in:
LevelX2 2016-10-13 02:06:11 +02:00
parent bb2044e70d
commit 8765f6ec45
2 changed files with 106 additions and 75 deletions

View file

@ -153,6 +153,10 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
} finally { } finally {
try { try {
os.close(); os.close();
if (!dst.isValid()) {
dst.delete();
logger.warn("Resource not found " + job.getName() + " from " + job.getSource().toString());
}
} catch (IOException ex) { } catch (IOException ex) {
logger.warn("While closing", ex); logger.warn("While closing", ex);
} }

View file

@ -2,8 +2,12 @@ package org.mage.plugins.card.dl.sources;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import org.mage.plugins.card.dl.DownloadJob; import org.mage.plugins.card.dl.DownloadJob;
import static org.mage.plugins.card.dl.DownloadJob.fromURL; import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile; import static org.mage.plugins.card.dl.DownloadJob.toFile;
@ -14,90 +18,97 @@ public class GathererSets implements Iterable<DownloadJob> {
private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + SETS_PATH); private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + SETS_PATH);
private static File outDir = DEFAULT_OUT_DIR; private static File outDir = DEFAULT_OUT_DIR;
private static final String[] symbols = {"10E", "9ED", "8ED", "7ED", "6ED", "5ED", "4ED", "3ED", "2ED", "LEB", "LEA", private static final String[] symbols = {"10E", "9ED", "8ED", "7ED", "6ED", "5ED", "4ED", "3ED", "2ED", "LEB", "LEA",
"HOP", "HOP",
"ARN", "ATQ", "LEG", "DRK", "FEM", "HML", "ARN", "ATQ", "LEG", "DRK", "FEM", "HML",
"ICE", "ALL", "CSP", "ICE", "ALL", "CSP",
"MIR", "VIS", "WTH", "MIR", "VIS", "WTH",
"TMP", "STH", "EXO", "TMP", "STH", "EXO",
"USG", "ULG", "UDS", "USG", "ULG", "UDS",
"MMQ", "NMS", "PCY", "MMQ", "NEM", "PCY",
"INV", "PLS", "APC", "INV", "PLS", "APC",
"ODY", "TOR", "JUD", "ODY", "TOR", "JUD",
"ONS", "LGN", "SCG", "ONS", "LGN", "SCG",
"MRD", "DST", "5DN", "MRD", "DST", "5DN",
"CHK", "BOK", "SOK", "CHK", "BOK", "SOK",
"RAV", "GPT", "DIS", "RAV", "GPT", "DIS",
"TSP", "TSB", "PLC", "FUT", "TSP", "TSB", "PLC", "FUT",
"LRW", "MOR", "LRW", "MOR",
"SHM", "EVE", "SHM", "EVE",
"MED", "ME2", "ME3", "ME4", "MED", "ME2", "ME3", "ME4",
"POR", "PO2", "PTK", "POR", "PO2", "PTK",
"ARC", "ARC", "DD3EVG",
"W16"}; "W16"};
private static final String[] withMythics = {"M10", "M11", "M12", "M13", "M14", "M15", "ORI", private static final String[] withMythics = {"M10", "M11", "M12", "M13", "M14", "M15", "ORI",
"ANB", "ANB",
"DDF", "DDG", "DDH", "DDI", "DDJ", "DDK", "DDL", "DDM", "DDN", "DDF", "DDG", "DDH", "DDI", "DDJ", "DDK", "DDL", "DDM", "DDN",
"DD3", "DD3B", "DDO", "DDP", "DDQ", "DDR", "DDS", "DD3DVD", "DD3GLV", "DD3JVC", "DDO", "DDP", "DDQ", "DDR", "DDS",
"FVD", "FVE", "FVL", "FVR", "ALA", "CON", "ARB",
"V12", "V13", "V14", "V15", "V16", "ZEN", "WWK", "ROE",
"ALA", "CON", "ARB", "SOM", "MBS", "NPH",
"ZEN", "WWK", "ROE", "CMD", "C13", "C14", "C15", "C16", "CMA",
"SOM", "MBS", "NPH", "PC2", "PCA",
"CMD", "C13", "C14", "C15", "C16", "CMA", "ISD", "DKA", "AVR",
"PC2", "PCA", "RTR", "GTC", "DGM",
"ISD", "DKA", "AVR", "MMA", "MM2", "EMA", "MM3",
"RTR", "GTC", "DGM", "THS", "BNG", "JOU",
"MMA", "MM2", "EMA", "MM3", "CNS", "CN2",
"THS", "BNG", "JOU", "VMA", "TPR",
"CNS", "CN2", "KTK", "FRF", "DTK",
"VMA", "TPR", "BFZ", "OGW",
"KTK", "FRF", "DTK", "SOI", "EMN",
"BFZ", "EXP", "OGW", "KLD", "MPS", "AER",
"SOI", "EMN", "AKH", "HOU"
"KLD", "MPS", "AER", };
"AKH", "HOU"
}; private static final String[] onlyMythics = {
"DRB", "V09", "V12", "V12", "V13", "V14", "V15", "V16", "EXP"
};
private static final HashMap<String, String> symbolsReplacements = new HashMap<>(); private static final HashMap<String, String> symbolsReplacements = new HashMap<>();
static { static {
symbolsReplacements.put("2ED", "2U");
symbolsReplacements.put("3ED", "3E");
symbolsReplacements.put("4ED", "4E");
symbolsReplacements.put("5ED", "5E");
symbolsReplacements.put("6ED", "6E");
symbolsReplacements.put("7ED", "7E");
symbolsReplacements.put("ALL", "AL");
symbolsReplacements.put("APC", "AP");
symbolsReplacements.put("ARN", "AN"); symbolsReplacements.put("ARN", "AN");
symbolsReplacements.put("ATQ", "AQ"); symbolsReplacements.put("ATQ", "AQ");
symbolsReplacements.put("LEG", "LE"); symbolsReplacements.put("CMA", "CM1");
symbolsReplacements.put("DD3DVD", "DD3_DVD");
symbolsReplacements.put("DD3EVG", "DD3_EVG");
symbolsReplacements.put("DD3GLV", "DD3_GLV");
symbolsReplacements.put("DD3JVC", "DD3_JVC");
symbolsReplacements.put("DRK", "DK"); symbolsReplacements.put("DRK", "DK");
symbolsReplacements.put("EXO", "EX");
symbolsReplacements.put("FEM", "FE"); symbolsReplacements.put("FEM", "FE");
symbolsReplacements.put("HML", "HM"); symbolsReplacements.put("HML", "HM");
symbolsReplacements.put("ICE", "IA"); symbolsReplacements.put("ICE", "IA");
symbolsReplacements.put("ALL", "AL");
symbolsReplacements.put("APC", "AP");
symbolsReplacements.put("TMP", "TE");
symbolsReplacements.put("INV", "IN"); symbolsReplacements.put("INV", "IN");
symbolsReplacements.put("LEA", "1E");
symbolsReplacements.put("LEB", "2E");
symbolsReplacements.put("LEG", "LE");
symbolsReplacements.put("MIR", "MI");
symbolsReplacements.put("MMQ", "MM");
symbolsReplacements.put("NEM", "NE");
symbolsReplacements.put("ODY", "OD");
symbolsReplacements.put("PCY", "PR");
symbolsReplacements.put("PLS", "PS"); symbolsReplacements.put("PLS", "PS");
symbolsReplacements.put("WTH", "WL"); symbolsReplacements.put("POR", "PO");
symbolsReplacements.put("PO2", "P2");
symbolsReplacements.put("PTK", "PK");
symbolsReplacements.put("STH", "ST");
symbolsReplacements.put("TMP", "TE");
symbolsReplacements.put("UDS", "CG");
symbolsReplacements.put("ULG", "GU"); symbolsReplacements.put("ULG", "GU");
symbolsReplacements.put("USG", "UZ"); symbolsReplacements.put("USG", "UZ");
symbolsReplacements.put("UDS", "CG");
symbolsReplacements.put("ODY", "OD");
symbolsReplacements.put("MMQ", "MM");
symbolsReplacements.put("NMS", "NE");
symbolsReplacements.put("PCY", "PR");
symbolsReplacements.put("STH", "ST");
symbolsReplacements.put("EXO", "EX");
symbolsReplacements.put("VIS", "VI"); symbolsReplacements.put("VIS", "VI");
symbolsReplacements.put("MIR", "MI"); symbolsReplacements.put("WTH", "WL");
symbolsReplacements.put("7ED", "7E");
symbolsReplacements.put("6ED", "6E");
symbolsReplacements.put("5ED", "5E");
symbolsReplacements.put("4ED", "4E");
symbolsReplacements.put("3ED", "3E");
symbolsReplacements.put("2ED", "2U");
symbolsReplacements.put("LEB", "2E");
symbolsReplacements.put("LEA", "1E");
symbolsReplacements.put("DD3A", "DD3");
symbolsReplacements.put("DD3B", "DD3");
symbolsReplacements.put("DD3C", "DD3");
symbolsReplacements.put("DD3D", "DD3");
} }
public GathererSets(String path) { public GathererSets(String path) {
@ -110,17 +121,33 @@ public class GathererSets implements Iterable<DownloadJob> {
@Override @Override
public Iterator<DownloadJob> iterator() { public Iterator<DownloadJob> iterator() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, -14);
Date compareDate = c.getTime();
ArrayList<DownloadJob> jobs = new ArrayList<>(); ArrayList<DownloadJob> jobs = new ArrayList<>();
for (String symbol : symbols) { for (String symbol : symbols) {
jobs.add(generateDownloadJob(symbol, "C")); ExpansionSet exp = Sets.findSet(symbol);
jobs.add(generateDownloadJob(symbol, "U")); if (exp != null && exp.getReleaseDate().before(compareDate)) {
jobs.add(generateDownloadJob(symbol, "R")); jobs.add(generateDownloadJob(symbol, "C"));
jobs.add(generateDownloadJob(symbol, "U"));
jobs.add(generateDownloadJob(symbol, "R"));
}
} }
for (String symbol : withMythics) { for (String symbol : withMythics) {
jobs.add(generateDownloadJob(symbol, "C")); ExpansionSet exp = Sets.findSet(symbol);
jobs.add(generateDownloadJob(symbol, "U")); if (exp != null && exp.getReleaseDate().before(compareDate)) {
jobs.add(generateDownloadJob(symbol, "R")); jobs.add(generateDownloadJob(symbol, "C"));
jobs.add(generateDownloadJob(symbol, "M")); jobs.add(generateDownloadJob(symbol, "U"));
jobs.add(generateDownloadJob(symbol, "R"));
jobs.add(generateDownloadJob(symbol, "M"));
}
}
for (String symbol : onlyMythics) {
ExpansionSet exp = Sets.findSet(symbol);
if (exp != null && exp.getReleaseDate().before(compareDate)) {
jobs.add(generateDownloadJob(symbol, "M"));
}
} }
return jobs.iterator(); return jobs.iterator();
} }