Delete empty directories after rip

Closes #33

Also better error message handling when ripper errors.
This commit is contained in:
4pr0n 2014-05-04 22:40:53 -07:00
parent b5e10c0149
commit ab018abf03
4 changed files with 75 additions and 3 deletions

View File

@ -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);
}
}
}
}

View File

@ -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<String,String> 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;
}
}

View File

@ -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())) {

View File

@ -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) {