Code:
// Writes link comment to text file // Trigger: "A download has stopped" // Has some settings, just search for "settings" in this code // Main function that runs the script based on the early return principle function run() { // Early return if the download is not finished if (!link.isFinished()) { // console.log("Link is not yet downloaded"); return; } var comment = link.getComment(); // Retrieve the comment from the link // Early return if the comment is empty if (!comment) { return; } // Retrieve the link's file name and download folder path var fileName = link.name; var sourcePath = package.getDownloadFolder(); // "Settings", see vars down below // Define allowed file types (set to null or undefined to allow all types) var allowedFileTypes = null; // Example: set to null to allow all file types // var allowedFileTypes = [".mp3"]; // Option to overwrite existing files var overwriteExisting = false; // Set to true to overwrite existing files // Check if the file type is allowed (skip check if allowedFileTypes is null or undefined) if (allowedFileTypes && !allowedFileTypes.some(function(extension) { return fileName.endsWith(extension); })) { return; } // Change the file name to add ".txt" as the new extension var outputPath = sourcePath + "/" + fileName + ".txt"; // Early return if the file exists and overwriting is disabled if (!overwriteExisting && getPath(outputPath).exists()) { return; } // Write the comment to the file writeFile(outputPath, comment, true); } // Execute the run function run();