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);
}
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);
}
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();
}
}
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();
}
}
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();
}
}
Aggregations