View Single Post
  #1581  
Old 05.11.2020, 05:46
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,553
Default

Quote:
Originally Posted by GreenXIII View Post
... combine multiple downloaded links, with the same package name and same download directory, into a single package?
Keep a backup of your link list before testing/using the script.

Code:
/*
    Merge download packages which have matching name and download folder, sorting links in descending order by ID.
    Trigger: Toolbar button pressed
    Customize main toolbar > Add a new "Eventscripter Trigger" button > Rename it to "Merge Packages" (case-sensitive) > Change Icon (optional)
*/

if (name == "Merge Packages") {
    
    getAllFilePackages().forEach(function(package) {

        if (package) {
            var packages = [];

            getAllFilePackages().forEach(function(package2) {
                if (package2.name + package2.downloadFolder == package.name + package.downloadFolder) {
                    packages.push(package2);
                }
            })

            if (packages.length > 1) {
                var linkIds = [];

                packages.forEach(function(package3) {
                    package3.downloadLinks.forEach(function(link) {
                        linkIds.push(link.UUID);
                    })
                })

                linkIds.sort().forEach(function(linkId) {
                    callAPI("downloadsV2", "moveLinks", [linkId], -1, package.UUID);
                })
            }
        }
    })
}
Reply With Quote