Skip to content

Commit

Permalink
Added timeouts and increased maximum file download sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
4pr0n committed Mar 13, 2014
1 parent 1cdec76 commit 9576896
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ 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;
this.saveAs = saveAs;
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);
}

/**
Expand Down Expand Up @@ -60,13 +65,16 @@ public void run() {
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);
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/rip.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9576896

Please sign in to comment.