1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-25 14:51:11 +02:00

Merge stop test only if error or completed #1882

https://github.com/RipMeApp/ripme/pull/1882
This commit is contained in:
soloturn
2021-05-22 05:53:42 +02:00
5 changed files with 27 additions and 16 deletions

View File

@@ -138,7 +138,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
index += 1;
LOGGER.debug("Found image url #" + index + ": " + imageURL);
downloadURL(new URL(imageURL), index);
if (isStopped()) {
if (isStopped() || isThisATest()) {
break;
}
}
@@ -149,7 +149,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
if (!textURLs.isEmpty()) {
LOGGER.debug("Found description link(s) from " + doc.location());
for (String textURL : textURLs) {
if (isStopped()) {
if (isStopped() || isThisATest()) {
break;
}
textindex += 1;
@@ -303,10 +303,10 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
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) {
// Only download one file if this is a test.
if (super.isThisATest() &&
(itemsPending.size() > 0 || itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
// Only download one file if this is a test.
if (super.isThisATest() && (itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
stop();
itemsPending.clear();
return false;
}
if (!allowDuplicates()

View File

@@ -142,10 +142,10 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
* 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) {
// Only download one file if this is a test.
if (super.isThisATest() &&
(itemsPending.size() > 0 || itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
// Only download one file if this is a test.
if (super.isThisATest() && (itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
stop();
itemsPending.clear();
return false;
}
if (!allowDuplicates()

View File

@@ -14,9 +14,12 @@ import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jsoup.HttpStatusException;
import com.rarchives.ripme.App;
import com.rarchives.ripme.ui.RipStatusComplete;
@@ -48,17 +51,18 @@ public abstract class AbstractRipper
public boolean hasASAPRipping() { return false; }
// Everytime addUrlToDownload skips a already downloaded url this increases by 1
public int alreadyDownloadedUrls = 0;
private boolean shouldStop = false;
private final AtomicBoolean shouldStop = new AtomicBoolean(false);
private static boolean thisIsATest = false;
public void stop() {
shouldStop = true;
LOGGER.trace("stop()");
shouldStop.set(true);
}
public boolean isStopped() {
return shouldStop;
return shouldStop.get();
}
protected void stopCheck() throws IOException {
if (shouldStop) {
if (shouldStop.get()) {
throw new IOException("Ripping interrupted");
}
}
@@ -683,4 +687,4 @@ public abstract class AbstractRipper
protected boolean useByteProgessBar() { return false;}
// If true ripme will try to resume a broken download for this ripper
protected boolean tryResumeDownload() { return false;}
}
}

View File

@@ -51,10 +51,10 @@ public abstract class AlbumRipper extends AbstractRipper {
* 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) {
// Only download one file if this is a test.
if (super.isThisATest() &&
(itemsPending.size() > 0 || itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
// Only download one file if this is a test.
if (super.isThisATest() && (itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
stop();
itemsPending.clear();
return false;
}
if (!allowDuplicates()

View File

@@ -39,6 +39,13 @@ public class RippersTest {
ripper.setup();
ripper.markAsTest();
ripper.rip();
if (logger.isTraceEnabled()) {
logger.trace("working dir: " + ripper.getWorkingDir());
logger.trace("list files: " + ripper.getWorkingDir().listFiles().length);
for (int i = 0; i < ripper.getWorkingDir().listFiles().length; i++) {
logger.trace(" " + ripper.getWorkingDir().listFiles()[i]);
}
}
Assertions.assertTrue(ripper.getWorkingDir().listFiles().length >= 1,
"Failed to download a single file from " + ripper.getURL());
} catch (IOException e) {