Search in sources :

Example 1 with DownloadJob

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));
}
Also used : DownloadJob.toFile(org.mage.plugins.card.dl.DownloadJob.toFile) File(java.io.File) DownloadJob(org.mage.plugins.card.dl.DownloadJob)

Example 2 with DownloadJob

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));
}
Also used : DownloadJob.toFile(org.mage.plugins.card.dl.DownloadJob.toFile) File(java.io.File) DownloadJob(org.mage.plugins.card.dl.DownloadJob)

Example 3 with DownloadJob

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();
}
Also used : ExpansionSet(mage.cards.ExpansionSet) DownloadJob(org.mage.plugins.card.dl.DownloadJob)

Example 4 with DownloadJob

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();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) GathererSymbols(org.mage.plugins.card.dl.sources.GathererSymbols) PropertyChangeListener(java.beans.PropertyChangeListener) Downloader(org.mage.plugins.card.dl.Downloader) DirectLinksForDownload(org.mage.plugins.card.dl.sources.DirectLinksForDownload) WindowAdapter(java.awt.event.WindowAdapter) DownloadGui(org.mage.plugins.card.dl.DownloadGui) DownloadJob(org.mage.plugins.card.dl.DownloadJob) ScryfallSymbolsSource(org.mage.plugins.card.dl.sources.ScryfallSymbolsSource) WindowEvent(java.awt.event.WindowEvent) GathererSets(org.mage.plugins.card.dl.sources.GathererSets)

Example 5 with DownloadJob

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();
}
Also used : DownloadJob(org.mage.plugins.card.dl.DownloadJob) DownloadJob.toFile(org.mage.plugins.card.dl.DownloadJob.toFile) File(java.io.File)

Aggregations

DownloadJob (org.mage.plugins.card.dl.DownloadJob)6 File (java.io.File)4 DownloadJob.toFile (org.mage.plugins.card.dl.DownloadJob.toFile)4 AbstractIterator (com.google.common.collect.AbstractIterator)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ExpansionSet (mage.cards.ExpansionSet)1 DownloadGui (org.mage.plugins.card.dl.DownloadGui)1 Downloader (org.mage.plugins.card.dl.Downloader)1 DirectLinksForDownload (org.mage.plugins.card.dl.sources.DirectLinksForDownload)1 GathererSets (org.mage.plugins.card.dl.sources.GathererSets)1 GathererSymbols (org.mage.plugins.card.dl.sources.GathererSymbols)1 ScryfallSymbolsSource (org.mage.plugins.card.dl.sources.ScryfallSymbolsSource)1