use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.
the class CardFrames method generateDownloadJob.
private DownloadJob generateDownloadJob(String dirName, String name) {
File dst = new File(outDir, name + ".png");
String url = BASE_DOWNLOAD_URL + dirName + '/' + name + ".png";
return new DownloadJob("frames-" + dirName + '-' + name, fromURL(url), toFile(dst));
}
use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.
the class GathererSets method generateDownloadJob.
private DownloadJob generateDownloadJob(String set, String rarity, String urlRarity) {
File dst = new File(outDir, set + '-' + rarity + ".jpg");
if (codeReplacements.containsKey(set)) {
set = codeReplacements.get(set);
}
String url = "https://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=" + set + "&size=small&rarity=" + urlRarity;
return new DownloadJob(set + '-' + rarity, fromURL(url), toFile(dst));
}
use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.
the class GathererSets method iterator.
@Override
public Iterator<DownloadJob> iterator() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, DAYS_BEFORE_RELEASE_TO_DOWNLOAD);
Date compareDate = c.getTime();
List<DownloadJob> jobs = new ArrayList<>();
boolean canDownload;
setsToDownload.clear();
for (String symbol : symbolsBasic) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "C", "C"));
jobs.add(generateDownloadJob(symbol, "U", "U"));
jobs.add(generateDownloadJob(symbol, "R", "R"));
}
CheckSearchResult(symbol, exp, canDownload, true, true, true, false);
}
for (String symbol : symbolsBasicWithMyth) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "C", "C"));
jobs.add(generateDownloadJob(symbol, "U", "U"));
jobs.add(generateDownloadJob(symbol, "R", "R"));
jobs.add(generateDownloadJob(symbol, "M", "M"));
}
CheckSearchResult(symbol, exp, canDownload, true, true, true, true);
}
for (String symbol : symbolsOnlyMyth) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "M", "M"));
}
CheckSearchResult(symbol, exp, canDownload, false, false, false, true);
}
for (String symbol : symbolsOnlySpecial) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "M", "S"));
}
CheckSearchResult(symbol, exp, canDownload, false, false, false, true);
}
// check wrong settings
AnalyseSearchResult();
return jobs.iterator();
}
use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.
the class CardPluginImpl method downloadSymbols.
/**
* Download various symbols (mana, tap, set).
*
* @param imagesDir Path to check in and store symbols to. Can't be null.
*/
@Override
public void downloadSymbols(String imagesDir) {
final Downloader downloader = new Downloader();
final DownloadGui downloadGui = new DownloadGui(downloader);
LOGGER.info("Symbols download prepare...");
Iterable<DownloadJob> jobs;
jobs = new GathererSymbols();
for (DownloadJob job : jobs) {
downloader.add(job);
}
jobs = new GathererSets();
for (DownloadJob job : jobs) {
downloader.add(job);
}
jobs = new ScryfallSymbolsSource();
for (DownloadJob job : jobs) {
downloader.add(job);
}
/*
it = new CardFrames(imagesDir); // TODO: delete frames download (not need now)
for (DownloadJob job : it) {
g.getDownloader().add(job);
}
*/
jobs = new DirectLinksForDownload();
for (DownloadJob job : jobs) {
downloader.add(job);
}
LOGGER.info("Symbols download needs " + downloader.getJobs().size() + " files");
// download GUI dialog
JDialog dialog = new JDialog((Frame) null, "Download symbols", false);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// user force to close window/downloader
downloader.cleanup();
}
});
dialog.setLayout(new BorderLayout());
dialog.add(downloadGui);
dialog.pack();
dialog.setVisible(true);
// downloader controller thread
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
downloader.publishAllJobs();
downloader.waitFinished();
downloader.cleanup();
return null;
}
};
// downloader finisher
worker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("state")) {
if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
// all done, can close dialog and refresh symbols for UI
LOGGER.info("Symbols download finished");
dialog.dispose();
ManaSymbols.loadImages();
ImageCache.clearCache();
}
}
}
});
worker.execute();
}
use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.
the class DirectLinksForDownload method iterator.
@Override
public Iterator<DownloadJob> iterator() {
List<DownloadJob> jobs = new ArrayList<>();
for (Map.Entry<String, String> url : directLinks.entrySet()) {
File dst = new File(outDir, url.getKey());
jobs.add(new DownloadJob(url.getKey(), fromURL(url.getValue()), toFile(dst)));
}
return jobs.iterator();
}
Aggregations