Added timeouts and increased maximum file download sizes

This commit is contained in:
4pr0n 2014-03-12 19:29:11 -07:00
parent 1cdec765cc
commit 9576896117
2 changed files with 23 additions and 2 deletions

View File

@ -26,6 +26,9 @@ public class DownloadFileThread extends Thread {
private AbstractRipper observer;
private int retries;
private final int TIMEOUT;
private final int MAX_BODY_SIZE;
public DownloadFileThread(URL url, File saveAs, AbstractRipper observer) {
super();
this.url = url;
@ -33,6 +36,8 @@ public class DownloadFileThread extends Thread {
this.prettySaveAs = Utils.removeCWD(saveAs);
this.observer = observer;
this.retries = Utils.getConfigInteger("download.retries", 1);
this.TIMEOUT = Utils.getConfigInteger("download.timeout", 60000);
this.MAX_BODY_SIZE = Utils.getConfigInteger("download.max_bytes", 1024 * 1024 * 100);
}
/**
@ -60,13 +65,16 @@ public class DownloadFileThread extends Thread {
Response response;
response = Jsoup.connect(url.toExternalForm())
.ignoreContentType(true)
.userAgent(AbstractRipper.USER_AGENT)
.timeout(TIMEOUT)
.maxBodySize(MAX_BODY_SIZE)
.execute();
FileOutputStream out = (new FileOutputStream(saveAs));
out.write(response.bodyAsBytes());
out.close();
break; // Download successful: break out of infinite loop
} catch (IOException e) {
logger.error("[!] Exception while downloading file: " + url + " - " + e.getMessage());
logger.error("[!] Exception while downloading file: " + url + " - " + e.getMessage(), e);
}
if (tries > this.retries) {
logger.error("[!] Exceeded maximum retries (" + this.retries + ") for URL " + url);

View File

@ -1,6 +1,19 @@
# Download threads to use per ripper
threads.size = 5
# Overwrite existing files
file.overwrite = false
download.retries = 3
# Number of retries on failed downloads
download.retries = 1
# File download timeout (in milliseconds)
download.timeout = 60000
# Maximum size of downloaded files in bytes (required)
download.max_size = 104857600
# API creds
twitter.auth = VW9Ybjdjb1pkd2J0U3kwTUh2VXVnOm9GTzVQVzNqM29LQU1xVGhnS3pFZzhKbGVqbXU0c2lHQ3JrUFNNZm8=
tumblr.auth = v5kUqGQXUtmF7K0itri1DGtgTs0VQpbSEbh1jxYgj9d2Sq18F8
gw.api = gonewild