View Single Post
  #120  
Old 16.06.2017, 08:54
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 945
Default

Quote:
Originally Posted by Informativ View Post
i have running crawljob and some files offline or captcha not work.
now i have folder with only txt or txt and image file. It is possible this folder delete over event script?
Note: This script will delete packages from download list and files/folders from disk.

Code:
// Delete 'jpg' and 'txt' files and remove download folder if empty.
// Trigger required: "A Download Stopped"

var links = link.getPackage().getDownloadLinks();

var packageMatch = links.some(function(link) {
    var ext = getPath(link.getDownloadPath()).getExtension();
    return ext == "jpg" || ext == "txt";
});

if (packageMatch) {
    var packageTried = links.every(function(link) {
        var status = link.getStatus();
        return status == "Skipped - Captcha is required" || status !== null;
    });

    if (packageTried) {
        var otherLinks = links.filter(function(link) {
            var ext = getPath(link.getDownloadPath()).getExtension();
            return !(/jpg|txt/).test(ext);
        });

        if (otherLinks.length) {
            var packageFailed = otherLinks.every(function(link) {
                var status = link.getStatus();
                return status == "Skipped - Captcha is required" || status == "File not found";
            });

            if (packageFailed) {
                package.remove();
                getPath(package.getDownloadFolder()).getChildren().forEach(function(file) {
                    var ext = getPath(file).getExtension();
                    if (ext == "txt" || ext == "jpg") {
                        file.delete();
                        file.getParent().delete();
                    }
                });
            }
        }
    }
}
Reply With Quote