JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 24.03.2025, 19:23
FBD's Avatar
FBD FBD is offline
Fibre Channel User
 
Join Date: Nov 2018
Location: https://web.libera.chat/#jDownloader
Posts: 117
Post Script to automatically reverse sort links in packages

This scripts sorts files in packages descending when added to the linkgrabber.
Required trigger: A new link has been added
Special handling for TV shows: sorts part files descending but episode numbers ascending

Useful if you have external tools (ie. not jdownloader) move or extract files or if you want to partially extract episodes before the whole package is finished. Then you can just look for "part[0]1.rar" files. Or if you just like it more that way.

Code:
// Package sorter (FBD)
// Sorts links descending in the linkgrabber
// Special handling for TV Shows (parts descending, episodes ascending)
// Trigger : A new link has been added

// disablePermissionChecks(); // uncomment if you know what you're doing

var levelRegex = /[^a-zA-Z0-9](S[0-9]{2}E[0-9]{2})/i;
var myCrawledPackages = [];
// myCrawledPackages = getAllCrawledPackages();
myCrawledPackages.push(crawledLink.getPackage());

myCrawledPackages.forEach(function(thisPackage) {
    var myCrawledLinks = thisPackage.getDownloadLinks();
    var fileHash = [];
    
    myCrawledLinks.forEach(function(thisLink) {
        var level = "";
        const matches = thisLink.getDownloadPath().match(levelRegex);
        if (matches) level = matches[1];
        if (!fileHash[level]) fileHash[level] = {};
        fileHash[level][thisLink.getDownloadPath()] = thisLink.getUUID();
    });
    
    // want episodes sorted descending too? remove the ".reverse()" here
    var sortedLevels = Object.keys(fileHash).sort().reverse();
    sortedLevels.forEach(function(thisLevel) {
        var sortedLinks = Object.keys(fileHash[thisLevel]).sort();
        sortedLinks.forEach(function(thisPath) {
            callAPI("linkgrabberv2", "moveLinks", [fileHash[thisLevel][thisPath]], -1, thisPackage.getUUID());
        });
    });
});
direct link: raw.githubusercontent.com/FarBeyondDriven/JDscripts/refs/heads/main/PackageSorter.js
__________________
irc.libera.chat #jDownloader web.libera.chat/#jDownloader
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 13:20.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.