mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-26 07:14:38 +02:00
Merge pull request #25 from ripmeapp2/feature/no-endless
Feature/no endless
This commit is contained in:
@@ -6,10 +6,12 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||||
@@ -22,9 +24,9 @@ import com.rarchives.ripme.ui.RipStatusMessage;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractHTMLRipper extends AbstractRipper {
|
public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||||
|
|
||||||
private Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>());
|
private final Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<>());
|
||||||
private Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>());
|
private final Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<>());
|
||||||
private Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>());
|
private final Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
protected AbstractHTMLRipper(URL url) throws IOException {
|
protected AbstractHTMLRipper(URL url) throws IOException {
|
||||||
super(url);
|
super(url);
|
||||||
@@ -104,7 +106,15 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
LOGGER.debug("Adding items from " + this.url + " to queue");
|
LOGGER.debug("Adding items from " + this.url + " to queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> doclocation = new ArrayList<>();
|
||||||
while (doc != null) {
|
while (doc != null) {
|
||||||
|
|
||||||
|
// catch if we saw a doc location already, save the ones seen in a list
|
||||||
|
if (doclocation.contains(doc.location())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
doclocation.add(doc.location());
|
||||||
|
|
||||||
if (alreadyDownloadedUrls >= Utils.getConfigInteger("history.end_rip_after_already_seen", 1000000000) && !isThisATest()) {
|
if (alreadyDownloadedUrls >= Utils.getConfigInteger("history.end_rip_after_already_seen", 1000000000) && !isThisATest()) {
|
||||||
sendUpdate(STATUS.DOWNLOAD_COMPLETE_HISTORY, "Already seen the last " + alreadyDownloadedUrls + " images ending rip");
|
sendUpdate(STATUS.DOWNLOAD_COMPLETE_HISTORY, "Already seen the last " + alreadyDownloadedUrls + " images ending rip");
|
||||||
break;
|
break;
|
||||||
@@ -195,7 +205,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
*/
|
*/
|
||||||
private String fileNameFromURL(URL url) {
|
private String fileNameFromURL(URL url) {
|
||||||
String saveAs = url.toExternalForm();
|
String saveAs = url.toExternalForm();
|
||||||
if (saveAs.substring(saveAs.length() - 1) == "/") { saveAs = saveAs.substring(0,saveAs.length() - 1) ;}
|
if (saveAs.substring(saveAs.length() - 1).equals("/")) { saveAs = saveAs.substring(0,saveAs.length() - 1) ;}
|
||||||
saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1);
|
saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1);
|
||||||
if (saveAs.indexOf('?') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('?')); }
|
if (saveAs.indexOf('?') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('?')); }
|
||||||
if (saveAs.indexOf('#') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('#')); }
|
if (saveAs.indexOf('#') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('#')); }
|
||||||
@@ -281,16 +291,16 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/*
|
||||||
* Returns total amount of files attempted.
|
Returns total amount of files attempted.
|
||||||
*/
|
*/
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return itemsCompleted.size() + itemsErrored.size();
|
return itemsCompleted.size() + itemsErrored.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/*
|
||||||
* Queues multiple URLs of single images to download from a single Album URL
|
Queues multiple URLs of single images to download from a single Album URL
|
||||||
*/
|
*/
|
||||||
public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies, Boolean getFileExtFromMIME) {
|
public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies, Boolean getFileExtFromMIME) {
|
||||||
// Only download one file if this is a test.
|
// Only download one file if this is a test.
|
||||||
@@ -352,8 +362,8 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/*
|
||||||
* Cleans up & tells user about successful download
|
Cleans up & tells user about successful download
|
||||||
*/
|
*/
|
||||||
public void downloadCompleted(URL url, File saveAs) {
|
public void downloadCompleted(URL url, File saveAs) {
|
||||||
if (observer == null) {
|
if (observer == null) {
|
||||||
@@ -388,9 +398,9 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/*
|
||||||
* Tells user that a single file in the album they wish to download has
|
Tells user that a single file in the album they wish to download has
|
||||||
* already been downloaded in the past.
|
already been downloaded in the past.
|
||||||
*/
|
*/
|
||||||
public void downloadExists(URL url, File file) {
|
public void downloadExists(URL url, File file) {
|
||||||
if (observer == null) {
|
if (observer == null) {
|
||||||
@@ -466,13 +476,12 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getStatusText() {
|
public String getStatusText() {
|
||||||
StringBuilder sb = new StringBuilder();
|
String sb = getCompletionPercentage() +
|
||||||
sb.append(getCompletionPercentage())
|
"% " +
|
||||||
.append("% ")
|
"- Pending: " + itemsPending.size() +
|
||||||
.append("- Pending: " ).append(itemsPending.size())
|
", Completed: " + itemsCompleted.size() +
|
||||||
.append(", Completed: ").append(itemsCompleted.size())
|
", Errored: " + itemsErrored.size();
|
||||||
.append(", Errored: " ).append(itemsErrored.size());
|
return sb;
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user