Search in sources :

Example 6 with RipStatusMessage

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);
            }
        }
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) RipStatusComplete(com.rarchives.ripme.ui.RipStatusComplete) RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage) IOException(java.io.IOException) Logger(org.apache.log4j.Logger) File(java.io.File)

Example 7 with RipStatusMessage

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;
}
Also used : RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage) FileWriter(java.io.FileWriter) IOException(java.io.IOException)

Example 8 with RipStatusMessage

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();
}
Also used : RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage)

Example 9 with RipStatusMessage

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());
}
Also used : RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage)

Example 10 with RipStatusMessage

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;
}
Also used : RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

RipStatusMessage (com.rarchives.ripme.ui.RipStatusMessage)16 IOException (java.io.IOException)7 MalformedURLException (java.net.MalformedURLException)4 File (java.io.File)2 FileWriter (java.io.FileWriter)2 RipStatusComplete (com.rarchives.ripme.ui.RipStatusComplete)1 FileAppender (org.apache.log4j.FileAppender)1 Logger (org.apache.log4j.Logger)1