mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
spjspj - Fix for mtg.onl
This commit is contained in:
parent
959eaf6dab
commit
08df195bc3
9 changed files with 94 additions and 58 deletions
|
@ -14,4 +14,5 @@ public interface CardImageSource {
|
|||
String getFileForHttpImage(String httpImageUrl);
|
||||
String getSourceName();
|
||||
Float getAverageSize();
|
||||
Integer getTotalImages();
|
||||
}
|
||||
|
|
|
@ -216,4 +216,9 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
public Float getAverageSize() {
|
||||
return 70.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,4 +105,9 @@ public class MtgImageSource implements CardImageSource {
|
|||
public Float getAverageSize() {
|
||||
return 70.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -41,8 +41,8 @@ import org.mage.plugins.card.images.DownloadPictures;
|
|||
public class MtgOnlTokensImageSource implements CardImageSource {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MtgOnlTokensImageSource.class);
|
||||
|
||||
private static CardImageSource instance = new MtgOnlTokensImageSource();
|
||||
private static int maxTimes = 0;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
|
@ -68,8 +68,17 @@ public class MtgOnlTokensImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
for (String key : copyUrlToImageDone.keySet()) {
|
||||
if (copyUrlToImageDone.get(key) == false) {
|
||||
copyUrlToImageDone.put(key, true);
|
||||
if (copyUrlToImageDone.get(key) < maxTimes) {
|
||||
copyUrlToImageDone.put(key, maxTimes);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
if (maxTimes < 2) {
|
||||
maxTimes++;
|
||||
}
|
||||
for (String key : copyUrlToImageDone.keySet()) {
|
||||
if (copyUrlToImageDone.get(key) < maxTimes) {
|
||||
copyUrlToImageDone.put(key, maxTimes);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +100,7 @@ public class MtgOnlTokensImageSource implements CardImageSource {
|
|||
|
||||
HashMap<String, String> copyUrlToImage = null;
|
||||
HashMap<String, String> copyImageToUrl = null;
|
||||
HashMap<String, Boolean> copyUrlToImageDone = null;
|
||||
HashMap<String, Integer> copyUrlToImageDone = null;
|
||||
|
||||
private void setupLinks() {
|
||||
if (copyUrlToImage != null) {
|
||||
|
@ -99,7 +108,7 @@ public class MtgOnlTokensImageSource implements CardImageSource {
|
|||
}
|
||||
copyUrlToImage = new HashMap<String, String>();
|
||||
copyImageToUrl = new HashMap<String, String>();
|
||||
copyUrlToImageDone = new HashMap<String, Boolean>();
|
||||
copyUrlToImageDone = new HashMap<String, Integer>();
|
||||
copyUrlToImage.put("Angel_B_3_3.jpg", "ANGEL.B.ANGEL.CREATURE.3.3.full.jpg");
|
||||
copyUrlToImage.put("Angel_W_3_3.jpg", "ANGEL.W.ANGEL.CREATURE.3.3.full.jpg");
|
||||
copyUrlToImage.put("Angel_W_4_4.jpg", "ANGEL.W.ANGEL.CREATURE.4.4.full.jpg");
|
||||
|
@ -338,21 +347,30 @@ public class MtgOnlTokensImageSource implements CardImageSource {
|
|||
copyUrlToImage.put("Zombie_B_X_X.jpg", "ZOMBIE.B.ZOMBIE.CREATURE.X.X.full.jpg");
|
||||
copyUrlToImage.put("Zombie_Horror_B_X_X.jpg", "ZOMBIEHORROR.B.ZOMBIEHORROR.CREATURE.X.X.full.jpg");
|
||||
copyUrlToImage.put("Zombie_U_X_X.jpg", "ZOMBIE.U.ZOMBIE.CREATURE.X.X.full.jpg");
|
||||
copyUrlToImage.put("Zombie_Wizard_UB_1_1.jpg", "ZOMBIEWIZARD.BG.ZOMBIEWIZARD.CREATURE.1.1.full.jpg");
|
||||
copyUrlToImage.put("Zombie_Wizard_UB_1_1.jpg", "ZOMBIEWIZARD.UB.ZOMBIEWIZARD.CREATURE.1.1.full.jpg");
|
||||
|
||||
for (String key : copyUrlToImage.keySet()) {
|
||||
copyUrlToImageDone.put(key, false);
|
||||
copyUrlToImageDone.put(key, maxTimes);
|
||||
copyImageToUrl.put(copyUrlToImage.get(key), key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTokenUrl(CardDownloadData card) throws IOException {
|
||||
|
||||
if (copyUrlToImage == null) {
|
||||
setupLinks();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
if (copyUrlToImage == null) {
|
||||
setupLinks();
|
||||
}
|
||||
if (copyUrlToImage != null) {
|
||||
return copyImageToUrl.size();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,4 +244,9 @@ public class MythicspoilerComSource implements CardImageSource {
|
|||
public String getFileForHttpImage(String httpImageUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -168,7 +167,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
tokenData = matchedTokens.get(card.getType() - 1);
|
||||
}
|
||||
|
||||
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + "_"
|
||||
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + "_"
|
||||
+ tokenData.getNumber().trim() + "-" + tokenData.getName().trim()+ ".jpg";
|
||||
url = url.replace(' ', '-');
|
||||
return url;
|
||||
|
@ -269,19 +268,19 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
} else {
|
||||
if (state == 0) {
|
||||
set = line.substring(0, 3);
|
||||
state = 1;
|
||||
} else {
|
||||
if (state == 1) {
|
||||
state = 2;
|
||||
}
|
||||
String[] split = line.split(",");
|
||||
// replace special comma for cards like 'Ashaya‚ the Awoken World'
|
||||
String name = split[0].replace('‚', ',');
|
||||
String number = split[1];
|
||||
TokenData token = new TokenData(name, number, set);
|
||||
tokensData.add(token);
|
||||
set = line.substring(0, 3);
|
||||
state = 1;
|
||||
} else {
|
||||
if (state == 1) {
|
||||
state = 2;
|
||||
}
|
||||
String[] split = line.split(",");
|
||||
// replace special comma for cards like 'Ashaya‚ the Awoken World'
|
||||
String name = split[0].replace('‚', ',');
|
||||
String number = split[1];
|
||||
TokenData token = new TokenData(name, number, set);
|
||||
tokensData.add(token);
|
||||
}
|
||||
}
|
||||
|
||||
line = reader.readLine();
|
||||
|
@ -307,6 +306,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
final class TokenData {
|
||||
|
||||
final private String name;
|
||||
final private String number;
|
||||
final private String expansionSetCode;
|
||||
|
@ -330,4 +330,8 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,4 +512,8 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,7 +285,6 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
|
||||
try {
|
||||
offlineMode = true;
|
||||
|
||||
for (CardInfo card : allCards) {
|
||||
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()
|
||||
&& !ignoreUrls.contains(card.getSetCode())) {
|
||||
|
@ -328,10 +327,10 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
}
|
||||
allCardsUrls.addAll(getTokenCardUrls());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
|
||||
int numberTokenImages = allCardsUrls.size() - numberCardImages;
|
||||
TFile file;
|
||||
|
||||
|
@ -504,17 +503,14 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
imageRef = cardImageSource.getSourceName() + imageRef;
|
||||
try {
|
||||
URL imageUrl = new URL(imageRef);
|
||||
|
||||
Runnable task = new DownloadTask(imageUrl, fileName, 1);
|
||||
Runnable task = new DownloadTask(imageUrl, fileName, cardImageSource.getTotalImages());
|
||||
executor.execute(task);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
} else {
|
||||
if (card != null) {
|
||||
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ")");
|
||||
synchronized (sync) {
|
||||
update(cardIndex + 1, cardsToDownload.size());
|
||||
}
|
||||
} else if (card != null && cardImageSource.getTotalImages() == -1) {
|
||||
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ")");
|
||||
synchronized (sync) {
|
||||
update(cardIndex + 1, cardsToDownload.size());
|
||||
}
|
||||
}
|
||||
} else if (url != null) {
|
||||
|
@ -587,9 +583,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
String imagePath;
|
||||
if (useSpecifiedPaths) {
|
||||
imagePath = CardImageUtils.getTokenBasePath(); // temporaryFile = plugins/images\NUM.jace, telepath unbound.jpg
|
||||
imagePath += actualFilename; // imagePath = d:\xmage_images\ORI.zip\ORI\Jace,telepathunbound.jpg
|
||||
String tmpFile = filePath + actualFilename + ".2";
|
||||
imagePath = CardImageUtils.getTokenBasePath();
|
||||
imagePath += actualFilename;
|
||||
String tmpFile = filePath + "ADDTOTOK" + actualFilename;
|
||||
temporaryFile = new File(tmpFile.toString());
|
||||
} else {
|
||||
imagePath = CardImageUtils.generateImagePath(card);
|
||||
|
@ -663,7 +659,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
new TFile(temporaryFile).cp_rp(outputFile);
|
||||
}
|
||||
} else {
|
||||
if (card != null) {
|
||||
if (card != null && !useSpecifiedPaths) {
|
||||
logger.warn("Image download for " + card.getName()
|
||||
+ (!card.getDownloadName().equals(card.getName()) ? " downloadname: " + card.getDownloadName() : "")
|
||||
+ "(" + card.getSet() + ") failed - responseCode: " + responseCode + " url: " + url.toString());
|
||||
|
|
|
@ -120,24 +120,22 @@ public class CardImageUtils {
|
|||
|
||||
public static String getTokenBasePath() {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesPath + TFile.separator + "TOK" + ".zip" + TFile.separator;
|
||||
} else {
|
||||
return imagesPath + TFile.separator + "TOK" + TFile.separator;
|
||||
String imagesPath = useDefault.equals("true") ? Constants.IO.imageBaseDir : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
if (!imagesPath.endsWith(TFile.separator)) {
|
||||
imagesPath += TFile.separator;
|
||||
}
|
||||
|
||||
String finalPath = "";
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
finalPath = imagesPath + "TOK" + ".zip" + TFile.separator;
|
||||
} else {
|
||||
finalPath = imagesPath + "TOK" + TFile.separator;
|
||||
}
|
||||
return finalPath;
|
||||
}
|
||||
|
||||
private static String getTokenDescriptorImagePath(CardDownloadData card) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesPath + TFile.separator + "TOK" + ".zip" + TFile.separator + card.getTokenDescriptor() + ".full.jpg";
|
||||
} else {
|
||||
return imagesPath + TFile.separator + "TOK" + TFile.separator + card.getTokenDescriptor() + ".full.jpg";
|
||||
}
|
||||
return getTokenBasePath() + card.getTokenDescriptor() + ".full.jpg";
|
||||
}
|
||||
|
||||
private static String buildTokenPath(String imagesDir, String set) {
|
||||
|
|
Loading…
Reference in a new issue