mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Reroute card images to scryfall.
Don't try to redownload if it fails during a session
This commit is contained in:
@@ -28,7 +28,12 @@ public class SwingImageFetcher extends ImageFetcher {
|
|||||||
this.notifyObservers = notifyObservers;
|
this.notifyObservers = notifyObservers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doFetch(String urlToDownload) throws IOException {
|
private boolean doFetch(String urlToDownload) throws IOException {
|
||||||
|
if (disableHostedDownload && urlToDownload.startsWith(ForgeConstants.URL_CARDFORGE) && !urlToDownload.contains("tokens")) {
|
||||||
|
// Don't try to download card images from cardforge servers
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String newdespath = urlToDownload.contains(".fullborder.jpg") || urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD) ?
|
String newdespath = urlToDownload.contains(".fullborder.jpg") || urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD) ?
|
||||||
TextUtil.fastReplace(destPath, ".full.jpg", ".fullborder.jpg") : destPath;
|
TextUtil.fastReplace(destPath, ".full.jpg", ".fullborder.jpg") : destPath;
|
||||||
if (!newdespath.contains(".full") && urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD))
|
if (!newdespath.contains(".full") && urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD))
|
||||||
@@ -48,6 +53,7 @@ public class SwingImageFetcher extends ImageFetcher {
|
|||||||
SwingUtilities.invokeLater(notifyObservers);
|
SwingUtilities.invokeLater(notifyObservers);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Failed to rename image to " + newdespath);
|
System.err.println("Failed to rename image to " + newdespath);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Failed to save image from " + url + " as jpeg");
|
System.err.println("Failed to save image from " + url + " as jpeg");
|
||||||
@@ -63,7 +69,10 @@ public class SwingImageFetcher extends ImageFetcher {
|
|||||||
} else {
|
} else {
|
||||||
System.err.println("Failed to save image from " + url + " as png");
|
System.err.println("Failed to save image from " + url + " as png");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String tofullBorder(String imageurl) {
|
private String tofullBorder(String imageurl) {
|
||||||
@@ -85,10 +94,13 @@ public class SwingImageFetcher extends ImageFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
boolean success = false;
|
||||||
for (String urlToDownload : downloadUrls) {
|
for (String urlToDownload : downloadUrls) {
|
||||||
try {
|
try {
|
||||||
doFetch(tofullBorder(urlToDownload));
|
if (doFetch(tofullBorder(urlToDownload))) {
|
||||||
break;
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
System.err.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
||||||
if (urlToDownload.contains("tokens")) {
|
if (urlToDownload.contains("tokens")) {
|
||||||
@@ -98,14 +110,17 @@ public class SwingImageFetcher extends ImageFetcher {
|
|||||||
String extension = urlToDownload.substring(typeIndex);
|
String extension = urlToDownload.substring(typeIndex);
|
||||||
urlToDownload = setlessFilename+extension;
|
urlToDownload = setlessFilename+extension;
|
||||||
try {
|
try {
|
||||||
doFetch(tofullBorder(urlToDownload));
|
if (doFetch(tofullBorder(urlToDownload))) {
|
||||||
break;
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (IOException t) {
|
} catch (IOException t) {
|
||||||
System.err.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
System.err.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If all downloads fail, mark this image as unfetchable so we don't try again.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,12 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
this.notifyObservers = notifyObservers;
|
this.notifyObservers = notifyObservers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doFetch(String urlToDownload) throws IOException {
|
private boolean doFetch(String urlToDownload) throws IOException {
|
||||||
|
if (disableHostedDownload && urlToDownload.startsWith(ForgeConstants.URL_CARDFORGE) && !urlToDownload.contains("tokens")) {
|
||||||
|
// Don't try to download card images from cardforge servers
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String newdespath = urlToDownload.contains(".fullborder.") || urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD) ?
|
String newdespath = urlToDownload.contains(".fullborder.") || urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD) ?
|
||||||
TextUtil.fastReplace(destPath, ".full.", ".fullborder.") : destPath;
|
TextUtil.fastReplace(destPath, ".full.", ".fullborder.") : destPath;
|
||||||
if (!newdespath.contains(".full") && urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD))
|
if (!newdespath.contains(".full") && urlToDownload.startsWith(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD))
|
||||||
@@ -54,6 +59,7 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
|
|
||||||
System.out.println("Saved image to " + newdespath);
|
System.out.println("Saved image to " + newdespath);
|
||||||
GuiBase.getInterface().invokeInEdtLater(notifyObservers);
|
GuiBase.getInterface().invokeInEdtLater(notifyObservers);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String tofullBorder(String imageurl) {
|
private String tofullBorder(String imageurl) {
|
||||||
@@ -75,14 +81,16 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
boolean success = false;
|
||||||
for (String urlToDownload : downloadUrls) {
|
for (String urlToDownload : downloadUrls) {
|
||||||
boolean isPlanechaseBG = urlToDownload.startsWith("https://downloads.cardforge.org/images/planes/");
|
boolean isPlanechaseBG = urlToDownload.startsWith("https://downloads.cardforge.org/images/planes/");
|
||||||
try {
|
try {
|
||||||
if (isPlanechaseBG) {
|
if (isPlanechaseBG) {
|
||||||
doFetch(urlToDownload);
|
success = doFetch(urlToDownload);
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
doFetch(tofullBorder(urlToDownload));
|
success = doFetch(tofullBorder(urlToDownload));
|
||||||
|
}
|
||||||
|
if (success) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -97,8 +105,10 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
String extension = urlToDownload.substring(typeIndex);
|
String extension = urlToDownload.substring(typeIndex);
|
||||||
urlToDownload = setlessFilename + extension;
|
urlToDownload = setlessFilename + extension;
|
||||||
try {
|
try {
|
||||||
doFetch(tofullBorder(urlToDownload));
|
success = doFetch(tofullBorder(urlToDownload));
|
||||||
break;
|
if (success) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (IOException t) {
|
} catch (IOException t) {
|
||||||
System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ public final class ForgeConstants {
|
|||||||
CACHE_PLANECHASE_PICS_DIR };
|
CACHE_PLANECHASE_PICS_DIR };
|
||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
private static final String URL_CARDFORGE = "https://downloads.cardforge.org";
|
public static final String URL_CARDFORGE = "https://downloads.cardforge.org";
|
||||||
private static final String GITHUB_ASSETS_BASE = "https://raw.githubusercontent.com/Card-Forge/forge-extras/refs/heads/main/";
|
private static final String GITHUB_ASSETS_BASE = "https://raw.githubusercontent.com/Card-Forge/forge-extras/refs/heads/main/";
|
||||||
|
|
||||||
public static final String URL_PIC_DOWNLOAD = URL_CARDFORGE + "/images/cards/";
|
public static final String URL_PIC_DOWNLOAD = URL_CARDFORGE + "/images/cards/";
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public abstract class ImageFetcher {
|
|||||||
// see https://scryfall.com/docs/api/languages and
|
// see https://scryfall.com/docs/api/languages and
|
||||||
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
||||||
private static final HashMap<String, String> langCodeMap = new HashMap<>();
|
private static final HashMap<String, String> langCodeMap = new HashMap<>();
|
||||||
|
protected static final boolean disableHostedDownload = true;
|
||||||
|
private static final HashSet<String> fetching = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
langCodeMap.put("en-US", "en");
|
langCodeMap.put("en-US", "en");
|
||||||
@@ -92,9 +94,12 @@ public abstract class ImageFetcher {
|
|||||||
if (imageKey.length() < 2)
|
if (imageKey.length() < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (imageKey.equalsIgnoreCase("t:null"))
|
||||||
|
return;
|
||||||
|
|
||||||
//planechaseBG file...
|
//planechaseBG file...
|
||||||
|
final ArrayList<String> downloadUrls = new ArrayList<>();
|
||||||
if (imageKey.startsWith("PLANECHASEBG:")) {
|
if (imageKey.startsWith("PLANECHASEBG:")) {
|
||||||
final ArrayList<String> downloadUrls = new ArrayList<>();
|
|
||||||
final String filename = imageKey.substring("PLANECHASEBG:".length());
|
final String filename = imageKey.substring("PLANECHASEBG:".length());
|
||||||
downloadUrls.add("https://downloads.cardforge.org/images/planes/" + filename);
|
downloadUrls.add("https://downloads.cardforge.org/images/planes/" + filename);
|
||||||
FileUtil.ensureDirectoryExists(ForgeConstants.CACHE_PLANECHASE_PICS_DIR);
|
FileUtil.ensureDirectoryExists(ForgeConstants.CACHE_PLANECHASE_PICS_DIR);
|
||||||
@@ -105,12 +110,9 @@ public abstract class ImageFetcher {
|
|||||||
setupObserver(destFile.getAbsolutePath(), callback, downloadUrls);
|
setupObserver(destFile.getAbsolutePath(), callback, downloadUrls);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (imageKey.equalsIgnoreCase("t:null"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
boolean useArtCrop = "Crop".equals(FModel.getPreferences().getPref(ForgePreferences.FPref.UI_CARD_ART_FORMAT));
|
boolean useArtCrop = "Crop".equals(FModel.getPreferences().getPref(ForgePreferences.FPref.UI_CARD_ART_FORMAT));
|
||||||
final String prefix = imageKey.substring(0, 2);
|
final String prefix = imageKey.substring(0, 2);
|
||||||
final ArrayList<String> downloadUrls = new ArrayList<>();
|
|
||||||
File destFile = null;
|
File destFile = null;
|
||||||
if (prefix.equals(ImageKeys.CARD_PREFIX)) {
|
if (prefix.equals(ImageKeys.CARD_PREFIX)) {
|
||||||
PaperCard paperCard = ImageUtil.getPaperCardFromImageKey(imageKey);
|
PaperCard paperCard = ImageUtil.getPaperCardFromImageKey(imageKey);
|
||||||
@@ -266,10 +268,14 @@ public abstract class ImageFetcher {
|
|||||||
// Already in the queue, simply add the new observer.
|
// Already in the queue, simply add the new observer.
|
||||||
observers.add(callback);
|
observers.add(callback);
|
||||||
return;
|
return;
|
||||||
|
} else if (fetching.contains(destPath)) {
|
||||||
|
// Already fetching, but somehow no observers?
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
observers = new HashSet<>();
|
observers = new HashSet<>();
|
||||||
observers.add(callback);
|
observers.add(callback);
|
||||||
|
fetching.add(destPath);
|
||||||
currentFetches.put(destPath, observers);
|
currentFetches.put(destPath, observers);
|
||||||
|
|
||||||
final Runnable notifyObservers = () -> {
|
final Runnable notifyObservers = () -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user