use of com.rarchives.ripme.ui.RipStatusMessage in project ripme by RipMeApp.
the class AbstractRipper method checkIfComplete.
/**
* Notifies observers and updates state if all files have been ripped.
*/
void checkIfComplete() {
if (observer == null) {
LOGGER.debug("observer is null");
return;
}
if (!completed) {
completed = true;
LOGGER.info(" Rip completed!");
RipStatusComplete rsc = new RipStatusComplete(workingDir, getCount());
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, rsc);
observer.update(this, msg);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
LOGGER.debug("Changing log file back to 'ripme.log'");
fa.setFile("ripme.log");
fa.activateOptions();
}
if (Utils.getConfigBoolean("urls_only.save", false)) {
String urlFile = this.workingDir + File.separator + "urls.txt";
try {
Desktop.getDesktop().open(new File(urlFile));
} catch (IOException e) {
LOGGER.warn("Error while opening " + urlFile, e);
}
}
}
}
use of com.rarchives.ripme.ui.RipStatusMessage in project ripme by RipMeApp.
the class VideoRipper method addURLToDownload.
@Override
public boolean addURLToDownload(URL url, File saveAs) {
if (Utils.getConfigBoolean("urls_only.save", false)) {
// Output URL to file
String urlFile = this.workingDir + File.separator + "urls.txt";
try (FileWriter fw = new FileWriter(urlFile, true)) {
fw.write(url.toExternalForm());
fw.write("\n");
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, urlFile);
observer.update(this, msg);
} catch (IOException e) {
LOGGER.error("Error while writing to " + urlFile, e);
return false;
}
} else {
if (isThisATest()) {
// Tests shouldn't download the whole video
// Just change this.url to the download URL so the test knows we found it.
LOGGER.debug("Test rip, found URL: " + url);
this.url = url;
return true;
}
threadPool.addThread(new DownloadVideoThread(url, saveAs, this));
}
return true;
}
use of com.rarchives.ripme.ui.RipStatusMessage in project ripme by RipMeApp.
the class VideoRipper method downloadErrored.
/**
* Runs if the download errored somewhere.
*
* @param url Target URL
* @param reason Reason why the download failed.
*/
@Override
public void downloadErrored(URL url, String reason) {
if (observer == null) {
return;
}
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_ERRORED, url + " : " + reason));
checkIfComplete();
}
use of com.rarchives.ripme.ui.RipStatusMessage in project ripme by RipMeApp.
the class RipStatusMessageTest method testConstructor.
public void testConstructor() {
RipStatusMessage.STATUS loadingResource = RipStatusMessage.STATUS.LOADING_RESOURCE;
String path = "path/to/file";
String toStringValue = "Loading Resource: " + path;
RipStatusMessage ripStatusMessage = new RipStatusMessage(loadingResource, path);
Assertions.assertEquals(loadingResource, ripStatusMessage.getStatus());
Assertions.assertEquals(path, ripStatusMessage.getObject());
Assertions.assertEquals(toStringValue, ripStatusMessage.toString());
}
use of com.rarchives.ripme.ui.RipStatusMessage in project ripme by RipMeApp.
the class AlbumRipper method addURLToDownload.
@Override
public /**
* Queues multiple URLs of single images to download from a single Album URL
*/
boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String, String> cookies) {
// Only download one file if this is a test.
if (super.isThisATest() && (itemsPending.size() > 0 || itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
stop();
return false;
}
if (!allowDuplicates() && (itemsPending.containsKey(url) || itemsCompleted.containsKey(url) || itemsErrored.containsKey(url))) {
// Item is already downloaded/downloading, skip it.
logger.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
return false;
}
if (Utils.getConfigBoolean("urls_only.save", false)) {
// Output URL to file
String urlFile = this.workingDir + File.separator + "urls.txt";
try {
FileWriter fw = new FileWriter(urlFile, true);
fw.write(url.toExternalForm());
fw.write("\n");
fw.close();
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, urlFile);
itemsCompleted.put(url, new File(urlFile));
observer.update(this, msg);
} catch (IOException e) {
logger.error("Error while writing to " + urlFile, e);
}
} else {
itemsPending.put(url, saveAs);
DownloadFileThread dft = new DownloadFileThread(url, saveAs, this);
if (referrer != null) {
dft.setReferrer(referrer);
}
if (cookies != null) {
dft.setCookies(cookies);
}
threadPool.addThread(dft);
}
return true;
}
Aggregations