Search in sources :

Example 21 with MagicEdition

use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.

the class DeckMasterPicturesProvider method getPicture.

@Override
public BufferedImage getPicture(MagicCard mc, MagicEdition ed) throws IOException {
    MagicEdition selected = ed;
    if (ed == null)
        selected = mc.getEditions().get(0);
    for (String k : getString("CALL_MCI_FOR").split(",")) {
        if (selected.getId().startsWith(k)) {
            return new MagicCardInfoPicturesProvider().getPicture(mc, selected);
        }
    }
    if (MTGControler.getInstance().getEnabledCache().getPic(mc, selected) != null) {
        return resizeCard(MTGControler.getInstance().getEnabledCache().getPic(mc, selected), newW, newH);
    }
    BufferedImage im = getPicture(selected.getMultiverse_id());
    if (im != null)
        MTGControler.getInstance().getEnabledCache().put(im, mc, ed);
    return resizeCard(im, newW, newH);
}
Also used : MagicEdition(org.magic.api.beans.MagicEdition) BufferedImage(java.awt.image.BufferedImage)

Example 22 with MagicEdition

use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.

the class GathererPicturesProvider method getPicture.

@Override
public BufferedImage getPicture(MagicCard mc, MagicEdition ed) throws IOException {
    MagicEdition selected = ed;
    if (ed == null)
        selected = mc.getEditions().get(0);
    for (String k : getArray("CALL_MCI_FOR")) {
        if (selected.getId().equalsIgnoreCase(k)) {
            if (mciProv == null)
                mciProv = new MagicCardInfoPicturesProvider();
            return mciProv.getPicture(mc, selected);
        }
    }
    if (MTGControler.getInstance().getEnabledCache().getPic(mc, selected) != null) {
        logger.trace("cached " + mc + "(" + selected + ") found");
        return resizeCard(MTGControler.getInstance().getEnabledCache().getPic(mc, selected), newW, newH);
    }
    BufferedImage im = getPicture(selected.getMultiverse_id());
    if (im != null)
        MTGControler.getInstance().getEnabledCache().put(im, mc, ed);
    return resizeCard(im, newW, newH);
}
Also used : MagicEdition(org.magic.api.beans.MagicEdition) BufferedImage(java.awt.image.BufferedImage)

Example 23 with MagicEdition

use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.

the class MagidexPicturesProvider method getPicture.

@Override
public BufferedImage getPicture(MagicCard mc, MagicEdition me) throws IOException {
    String cardName = mc.getName().toLowerCase();
    MagicEdition edition = me;
    if (me == null)
        edition = mc.getEditions().get(0);
    if (MTGControler.getInstance().getEnabledCache().getPic(mc, edition) != null) {
        logger.trace("cached " + mc + "(" + edition + ") found");
        return resizeCard(MTGControler.getInstance().getEnabledCache().getPic(mc, edition), newW, newH);
    }
    String cardSet = edition.getId();
    if (mc.getName().contains("//")) {
        cardName = cardName.replaceAll("//", "");
    }
    // This will properly escape the url
    URI uri;
    try {
        uri = new URI("http", "magidex.com", "/extstatic/card/" + cardSet.toUpperCase() + '/' + cardName + ".jpg", null, null);
    } catch (URISyntaxException e1) {
        throw new IOException(e1);
    }
    logger.debug("get card from " + uri.toURL());
    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    connection.setInstanceFollowRedirects(true);
    connection.setRequestProperty("User-Agent", getString("USER_AGENT"));
    connection.connect();
    try {
        BufferedImage bufferedImage = ImageIO.read(connection.getInputStream());
        if (bufferedImage != null)
            MTGControler.getInstance().getEnabledCache().put(bufferedImage, mc, edition);
        return resizeCard(bufferedImage, newW, newH);
    } catch (Exception e) {
        logger.error(e);
        return getBackPicture();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) MagicEdition(org.magic.api.beans.MagicEdition) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 24 with MagicEdition

use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.

the class MythicSpoilerPicturesProvider method getPicture.

@Override
public BufferedImage getPicture(MagicCard mc, MagicEdition me) throws IOException {
    MagicEdition edition = me;
    if (me == null)
        edition = mc.getEditions().get(0);
    if (MTGControler.getInstance().getEnabledCache().getPic(mc, edition) != null) {
        logger.trace("cached " + mc + "(" + edition + ") found");
        return resizeCard(MTGControler.getInstance().getEnabledCache().getPic(mc, edition), newW, newH);
    }
    String cardSet = edition.getId();
    String cardName = mc.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "").replaceAll("'", "").replaceAll(",", "").replaceAll("/", "");
    // This will properly escape the url
    URI uri;
    try {
        uri = new URI("http", "mythicspoiler.com", "/" + cardSet.toLowerCase() + "/cards/" + cardName + ".jpg", null, null);
    } catch (URISyntaxException e1) {
        throw new IOException(e1);
    }
    logger.debug("get card from " + uri.toURL());
    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    connection.setInstanceFollowRedirects(true);
    connection.setRequestProperty("User-Agent", getString("USER_AGENT"));
    connection.connect();
    try {
        BufferedImage bufferedImage = ImageIO.read(connection.getInputStream());
        if (bufferedImage != null)
            MTGControler.getInstance().getEnabledCache().put(bufferedImage, mc, edition);
        return resizeCard(bufferedImage, newW, newH);
    } catch (Exception e) {
        logger.error(e);
        return getBackPicture();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) MagicEdition(org.magic.api.beans.MagicEdition) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 25 with MagicEdition

use of org.magic.api.beans.MagicEdition in project MtgDesktopCompanion by nicho92.

the class Search method run.

@Override
public void run(String[] args, IoSession session, MTGConsoleHandler mtgConsoleHandler) throws ParseException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    CommandLine cl = parser.parse(opts, args);
    this.session = session;
    if (cl.hasOption("c")) {
        String att = cl.getOptionValue("c").split("=")[0];
        String val = cl.getOptionValue("c").split("=")[1];
        List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(att, val, null, false);
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCards())));
    }
    if (cl.hasOption("s")) {
        List<MagicEdition> list = MTGControler.getInstance().getEnabledProviders().loadEditions();
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttSet())));
    }
    if (cl.hasOption("col")) {
        List<MagicCollection> list;
        try {
            list = MTGControler.getInstance().getEnabledDAO().getCollections();
        } catch (SQLException e) {
            throw new IOException(e);
        }
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCols())));
    }
    if (cl.hasOption("?")) {
        usage();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MagicCard(org.magic.api.beans.MagicCard) SQLException(java.sql.SQLException) MagicEdition(org.magic.api.beans.MagicEdition) IOException(java.io.IOException) MagicCollection(org.magic.api.beans.MagicCollection)

Aggregations

MagicEdition (org.magic.api.beans.MagicEdition)67 MagicCard (org.magic.api.beans.MagicCard)38 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)18 MagicCollection (org.magic.api.beans.MagicCollection)11 MagicDeck (org.magic.api.beans.MagicDeck)10 JsonObject (com.google.gson.JsonObject)9 InputStreamReader (java.io.InputStreamReader)9 JsonReader (com.google.gson.stream.JsonReader)8 List (java.util.List)8 JsonParser (com.google.gson.JsonParser)7 MalformedURLException (java.net.MalformedURLException)7 SQLException (java.sql.SQLException)7 Date (java.util.Date)7 JLabel (javax.swing.JLabel)7 Before (org.junit.Before)7 JsonArray (com.google.gson.JsonArray)6 BufferedImage (java.awt.image.BufferedImage)6 URL (java.net.URL)6 Map (java.util.Map)6