Search in sources :

Example 6 with DownloadJob

use of org.mage.plugins.card.dl.DownloadJob in project mage by magefree.

the class GathererSymbols method iterator.

@Override
public Iterator<DownloadJob> iterator() {
    return new AbstractIterator<DownloadJob>() {

        private int sizeIndex, symIndex, numeric = minNumeric;

        private File dir = new File(outDir, sizes[sizeIndex]);

        @Override
        protected DownloadJob computeNext() {
            while (true) {
                String sym;
                if (symIndex < symbols.length) {
                    sym = symbols[symIndex++];
                } else if (numeric <= maxNumeric) {
                    sym = String.valueOf(numeric++);
                } else {
                    sizeIndex++;
                    if (sizeIndex == sizes.length) {
                        return endOfData();
                    }
                    symIndex = 0;
                    numeric = 0;
                    dir = new File(outDir, sizes[sizeIndex]);
                    continue;
                }
                String symbol = sym.replaceAll("/", "");
                File dst = new File(dir, symbol + ".gif");
                /**
                 * Handle a bug on Gatherer where a few symbols are missing
                 * at the large size. Fall back to using the medium symbol
                 * for those cases.
                 */
                int modSizeIndex = sizeIndex;
                if (sizeIndex == 2) {
                    switch(sym) {
                        case "WP":
                        case "UP":
                        case "BP":
                        case "RP":
                        case "GP":
                        case "E":
                        case "C":
                            modSizeIndex = 1;
                            break;
                        default:
                    }
                }
                switch(symbol) {
                    case "T":
                        symbol = "tap";
                        break;
                    case "Q":
                        symbol = "untap";
                        break;
                    case "S":
                        symbol = "snow";
                        break;
                }
                String url = format(urlFmt, sizes[modSizeIndex], symbol);
                return new DownloadJob(sym, fromURL(url), toFile(dst));
            }
        }
    };
}
Also used : AbstractIterator(com.google.common.collect.AbstractIterator) DownloadJob.toFile(org.mage.plugins.card.dl.DownloadJob.toFile) File(java.io.File) DownloadJob(org.mage.plugins.card.dl.DownloadJob)

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