From 7f390962b6a83603a84a285a0258b0fcfa4aee7e Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Mon, 7 Apr 2014 22:37:21 -0700 Subject: [PATCH] 404'd images are marked as "errored" #13 --- pom.xml | 2 +- .../rarchives/ripme/ripper/DownloadFileThread.java | 14 +++++++++++++- .../java/com/rarchives/ripme/ui/UpdateUtils.java | 2 +- src/main/java/com/rarchives/ripme/utils/Utils.java | 2 -- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 6551c2fd..cbbb3f5d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.10 + 1.0.11 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java index f0c29b40..eef29c40 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java @@ -69,7 +69,19 @@ public class DownloadFileThread extends Thread { .timeout(TIMEOUT) .maxBodySize(MAX_BODY_SIZE) .execute(); - FileOutputStream out = (new FileOutputStream(saveAs)); + if (response.statusCode() != 200) { + logger.error("[!] Non-OK status code " + response.statusCode() + " while downloading from " + url); + observer.downloadErrored(url, "Non-OK status code " + response.statusCode() + " while downloading " + url.toExternalForm()); + return; + } + byte[] bytes = response.bodyAsBytes(); + if (bytes.length == 503 && url.getHost().endsWith("imgur.com")) { + // Imgur image with 503 bytes is "404" + logger.error("[!] Imgur image is 404 (503 bytes long): " + url); + observer.downloadErrored(url, "Imgur image is 404: " + url.toExternalForm()); + return; + } + FileOutputStream out = new FileOutputStream(saveAs); out.write(response.bodyAsBytes()); out.close(); break; // Download successful: break out of infinite loop diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 5dd97679..b1977525 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -17,7 +17,7 @@ import org.jsoup.nodes.Document; public class UpdateUtils { private static final Logger logger = Logger.getLogger(UpdateUtils.class); - private static final String DEFAULT_VERSION = "1.0.10"; + private static final String DEFAULT_VERSION = "1.0.11"; private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String mainFileName = "ripme.jar"; diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 4ae3ad9b..c8fe6e7c 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -12,7 +12,6 @@ import java.util.jar.JarFile; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; import org.apache.log4j.Logger; /** @@ -34,7 +33,6 @@ public class Utils { configPath = configFile; } config = new PropertiesConfiguration(configPath); - config.setReloadingStrategy(new FileChangedReloadingStrategy()); logger.info("Loaded " + config.getPath()); } catch (Exception e) { logger.error("[!] Failed to load properties file from " + configFile, e);