diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java index 49ebad57..3941b16e 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -11,6 +11,7 @@ import java.util.Map; import java.util.Observable; import org.apache.log4j.Logger; +import org.jsoup.HttpStatusException; import com.rarchives.ripme.ui.RipStatusHandler; import com.rarchives.ripme.ui.RipStatusMessage; @@ -287,9 +288,21 @@ public abstract class AbstractRipper public void run() { try { rip(); + } catch (HttpStatusException e) { + logger.error("Got exception while running ripper:", e); + sendUpdate(STATUS.RIP_ERRORED, "Status=" + e.getStatusCode() + ", URL=" + e.getUrl()); } catch (IOException e) { logger.error("Got exception while running ripper:", e); - waitForThreads(); + sendUpdate(STATUS.RIP_ERRORED, e.getMessage()); + } finally { + if (this.workingDir.list().length == 0) { + // No files, delete the dir + logger.info("Deleting empty directory " + this.workingDir); + boolean deleteResult = this.workingDir.delete(); + if (!deleteResult) { + logger.error("Unable to delete empty directory " + this.workingDir); + } + } } } diff --git a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java index 71488623..2cddc1ce 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java @@ -8,6 +8,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.jsoup.Connection; +import org.jsoup.Connection.Method; +import org.jsoup.Connection.Response; +import org.jsoup.Jsoup; + import com.rarchives.ripme.ui.RipStatusMessage; import com.rarchives.ripme.ui.RipStatusMessage.STATUS; import com.rarchives.ripme.utils.Utils; @@ -170,4 +175,46 @@ public abstract class AlbumRipper extends AbstractRipper { .append(", Errored: " ).append(itemsErrored.size()); return sb.toString(); } + + public Response getResponse(String url, + Method method, + String userAgent, + String referrer, + Map cookies, + boolean ignoreContentType) + throws IOException { + Connection connection = Jsoup.connect(url); + + if (method == null) { + method = Method.GET; + } + connection.method(method); + + if (userAgent == null) { + userAgent = USER_AGENT; + } + connection.userAgent(userAgent); + + if (cookies != null) { + connection.cookies(cookies); + } + + if (referrer != null) { + connection.referrer(referrer); + } + connection.ignoreContentType(ignoreContentType); + + Response response = null; + int retries = Utils.getConfigInteger("download.retries", 1);; + while (retries >= 0) { + retries--; + try { + response = connection.execute(); + } catch (IOException e) { + logger.warn("Error while loading " + url, e); + continue; + } + } + return response; + } } diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 47dd7a4a..682b8251 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -735,10 +735,21 @@ public class MainWindow implements Runnable, RipStatusHandler { case DOWNLOAD_ERRORED: appendLog( "Error: " + (String) msg.getObject(), Color.RED); break; - case DOWNLOAD_WARN: appendLog( "Warn: " + (String) msg.getObject(), Color.ORANGE); break; + + case RIP_ERRORED: + appendLog( "Error: " + (String) msg.getObject(), Color.RED); + ripButton.setVisible(true); + stopButton.setVisible(false); + ripTextfield.setEnabled(true); + statusProgress.setValue(0); + statusProgress.setVisible(false); + openButton.setVisible(false); + mainFrame.pack(); + statusWithColor("Error: " + (String) msg.getObject(), Color.RED); + break; case RIP_COMPLETE: if (!historyListModel.contains(ripTextfield.getText())) { diff --git a/src/main/java/com/rarchives/ripme/ui/RipStatusMessage.java b/src/main/java/com/rarchives/ripme/ui/RipStatusMessage.java index fee3fc59..46c5de95 100644 --- a/src/main/java/com/rarchives/ripme/ui/RipStatusMessage.java +++ b/src/main/java/com/rarchives/ripme/ui/RipStatusMessage.java @@ -13,7 +13,8 @@ public class RipStatusMessage { RIP_COMPLETE("Rip Complete"), DOWNLOAD_WARN("Download problem"), TOTAL_BYTES("Total bytes"), - COMPLETED_BYTES("Completed bytes"); + COMPLETED_BYTES("Completed bytes"), + RIP_ERRORED("Rip Errored"); String value; STATUS(String value) {