Delete empty directories after rip
Closes #33 Also better error message handling when ripper errors.
This commit is contained in:
parent
b5e10c0149
commit
ab018abf03
@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jsoup.HttpStatusException;
|
||||||
|
|
||||||
import com.rarchives.ripme.ui.RipStatusHandler;
|
import com.rarchives.ripme.ui.RipStatusHandler;
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage;
|
import com.rarchives.ripme.ui.RipStatusMessage;
|
||||||
@ -287,9 +288,21 @@ public abstract class AbstractRipper
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
rip();
|
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) {
|
} catch (IOException e) {
|
||||||
logger.error("Got exception while running ripper:", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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;
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
@ -170,4 +175,46 @@ public abstract class AlbumRipper extends AbstractRipper {
|
|||||||
.append(", Errored: " ).append(itemsErrored.size());
|
.append(", Errored: " ).append(itemsErrored.size());
|
||||||
return sb.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -735,10 +735,21 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
case DOWNLOAD_ERRORED:
|
case DOWNLOAD_ERRORED:
|
||||||
appendLog( "Error: " + (String) msg.getObject(), Color.RED);
|
appendLog( "Error: " + (String) msg.getObject(), Color.RED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOWNLOAD_WARN:
|
case DOWNLOAD_WARN:
|
||||||
appendLog( "Warn: " + (String) msg.getObject(), Color.ORANGE);
|
appendLog( "Warn: " + (String) msg.getObject(), Color.ORANGE);
|
||||||
break;
|
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:
|
case RIP_COMPLETE:
|
||||||
if (!historyListModel.contains(ripTextfield.getText())) {
|
if (!historyListModel.contains(ripTextfield.getText())) {
|
||||||
|
@ -13,7 +13,8 @@ public class RipStatusMessage {
|
|||||||
RIP_COMPLETE("Rip Complete"),
|
RIP_COMPLETE("Rip Complete"),
|
||||||
DOWNLOAD_WARN("Download problem"),
|
DOWNLOAD_WARN("Download problem"),
|
||||||
TOTAL_BYTES("Total bytes"),
|
TOTAL_BYTES("Total bytes"),
|
||||||
COMPLETED_BYTES("Completed bytes");
|
COMPLETED_BYTES("Completed bytes"),
|
||||||
|
RIP_ERRORED("Rip Errored");
|
||||||
|
|
||||||
String value;
|
String value;
|
||||||
STATUS(String value) {
|
STATUS(String value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user