Quote:
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(); } }); } } } } |