mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Added downloading flipped card images. Removed counting images for ignored sets.
This commit is contained in:
parent
20c57ef2d6
commit
3df5466d8a
16 changed files with 77 additions and 33 deletions
|
|
@ -6,7 +6,7 @@ package org.mage.plugins.card.dl.sources;
|
|||
*/
|
||||
public interface CardImageSource {
|
||||
|
||||
String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondFace, boolean isFlipCard) throws Exception;
|
||||
String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondFace, boolean isFlipCard, boolean flippedView) throws Exception;
|
||||
String generateTokenUrl(String name, String set);
|
||||
Float getAverageSize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondSide, boolean isFlipCard) throws Exception {
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondSide, boolean isFlipCard, boolean flippedView) throws Exception {
|
||||
if (collectorId == null || cardSet == null) {
|
||||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
|
|
@ -73,7 +73,11 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
url.append(secondSide ? "b" : "a");
|
||||
}
|
||||
if (isFlipCard) {
|
||||
url.append("a");
|
||||
if (flippedView) { // download rotated by 180 degree image
|
||||
url.append("b");
|
||||
} else {
|
||||
url.append("a");
|
||||
}
|
||||
}
|
||||
url.append(".jpg");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -91,10 +92,13 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondSide, boolean isFlipCard) throws Exception {
|
||||
public String generateURL(Integer collectorId, String cardName, String cardSet, boolean twoFacedCard, boolean secondSide, boolean isFlipCard, boolean flippedView) throws Exception {
|
||||
if (collectorId == null || cardSet == null) {
|
||||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
if (flippedView) { //doesn't support rotated images
|
||||
return null;
|
||||
}
|
||||
if (setsAliases.get(cardSet) != null) {
|
||||
Map<String, String> setLinks = (Map<String, String>) sets.get(cardSet);
|
||||
if (setLinks == null) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class CardInfo {
|
|||
private boolean twoFacedCard;
|
||||
private boolean secondSide;
|
||||
private boolean flipCard;
|
||||
private boolean flippedSide;
|
||||
private boolean usesVariousArt;
|
||||
|
||||
public CardInfo(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type) {
|
||||
|
|
@ -158,4 +159,11 @@ public class CardInfo {
|
|||
return usesVariousArt;
|
||||
}
|
||||
|
||||
public boolean isFlippedSide() {
|
||||
return flippedSide;
|
||||
}
|
||||
|
||||
public void setFlippedSide(boolean flippedSide) {
|
||||
this.flippedSide = flippedSide;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,14 +228,16 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
* read all card names and urls
|
||||
*/
|
||||
ArrayList<CardInfo> allCardsUrls = new ArrayList<CardInfo>();
|
||||
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
|
||||
|
||||
try {
|
||||
offlineMode = true;
|
||||
|
||||
for (Card card : allCards) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()
|
||||
&& !ignoreUrls.contains(card.getExpansionSetCode())) {
|
||||
String cardName = card.getName();
|
||||
CardInfo url = new CardInfo(cardName, card.getExpansionSetCode(),card.getCardNumber(), card.getUsesVariousArt(), 0, false, card.canTransform(), card.isNightCard());
|
||||
CardInfo url = new CardInfo(cardName, card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), 0, false, card.canTransform(), card.isNightCard());
|
||||
if (url.getUsesVariousArt()) {
|
||||
url.setDownloadName(card.getClass().getName().replace(card.getClass().getPackage().getName() + ".", ""));
|
||||
}
|
||||
|
|
@ -251,6 +253,15 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
url = new CardInfo(secondSide.getName(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), 0, false, card.canTransform(), true);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
if (card.isFlipCard()) {
|
||||
if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
|
||||
throw new IllegalStateException("Flipped card can't have empty name.");
|
||||
}
|
||||
url = new CardInfo(card.getFlipCardName(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), 0, false, card.canTransform(), card.isNightCard());
|
||||
url.setFlipCard(true);
|
||||
url.setFlippedSide(true);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
} else {
|
||||
if (card.getCardNumber() < 1) {
|
||||
System.err.println("There was a critical error!");
|
||||
|
|
@ -406,7 +417,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
url = cardImageSource.generateTokenUrl(card.getName(), card.getSet());
|
||||
} else {
|
||||
url = cardImageSource.generateURL(card.getCollectorId(), card.getDownloadName(), card.getSet(),
|
||||
card.isTwoFacedCard(), card.isSecondSide(), card.isFlipCard());
|
||||
card.isTwoFacedCard(), card.isSecondSide(), card.isFlipCard(), card.isFlippedSide());
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
|
|
@ -417,6 +428,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
update(cardIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error(ex, ex);
|
||||
}
|
||||
|
|
@ -554,7 +566,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
int count = DownloadPictures.this.cards.size();
|
||||
|
||||
if (cardIndex < count) {
|
||||
float mb = ((count - card) * cardImageSource.getAverageSize()) / 1024;
|
||||
float mb = ((count - card) * cardImageSource.getAverageSize()) / 1024;
|
||||
bar.setString(String.format("%d of %d cards finished! Please wait! [%.1f Mb]",
|
||||
card, count, mb));
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue