JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 08.07.2024, 21:16
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default Event Scripter scripts doubs

I made two scripts.
Every time that links is added into a package:
Code:
if (true) { //url.includes("www3.animeflv.net"))
    var filename = link.getName();
    if (filename !== null && filename.includes(" Episodio ")) {
        var newFilename = filename.replace("Episodio ", "");
        var regex = /(\d+)\./g;
        var match = newFilename.match(regex);
        if (match !== null && match.length > 0) {
            var number = match[match.length - 1];
            if (number < 10) {
                newFilename = newFilename.replace(number, "0" + number);
            }
        }
        link.setName(newFilename);
    }
}
This script fixes the name of the files.
Ex: "Ookami to Koushinryou; Merchant Meets the Wise Wolf Episodio 5" => "Ookami to Koushinryou; Merchant Meets the Wise Wolf 05"

When I press a button, the script ensures the best favorite link must be enabled, the rest should be disabled. If there is no one favorite these remain untouched:
Code:
if (name = "EST") {
    function includes(array, valor) {
        for (var i = 0; i < array.length; i++) {
            if (array[i] == valor) {
                return i;
            }
        }
        return -1;
    }
    var favoritos = ['mega.nz', 'streamtape.com'];
    var links = getAllDownloadLinks(); 
    var packages = {};
    var favs = {};
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        var package = link.getPackage().getName();
        if (!packages[package]) {
            packages[package] = [];
        }
        packages[package].push(link);
        var dominio = link.getContentURL().split('/')[2];
        var ind = includes(favoritos, dominio, packages[package].length - 1);
        if (ind >= 0 && (!favs[package] || favs[package] > ind)) {
            favs[package] = ind;
        }
    }
    for (var package in packages) {
        if (favs[package] !== undefined) {
            var fav = favs[package];
            for (var i = 0; i < packages[package].length; i++) {
                var link = packages[package][i];
                var dominio = link.getContentURL().split('/')[2];
                link.setEnabled(favoritos[fav] == dominio);
                //link.setPriority(-2);//Do nothing!!!???
            }
        }
    }
}


I'd like to apply the first script for the videos I download from "www3.animeflv.net" only.

And the second rule I would like to apply after the package is formed before sending it down.

Where can I find more information on which functions are available for each script depending on the trigger that triggers it?

Is it possible to change the priority of a download link?

Is it possible to sort the links?
Attached Images
File Type: png 06.png (70.6 KB, 14 views)

Last edited by RydemStorm; 08.07.2024 at 21:17. Reason: Fix
Reply With Quote
  #2  
Old 08.07.2024, 22:14
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

You can find all available Objects/Methods... in the Scripteditor at top (Menu "Show/Hide Help"). The available Objects/Methods depend on current select event trigger.

Quote:
Originally Posted by RydemStorm View Post
I'd like to apply the first script for the videos I download from "www3.animeflv.net" only.
One simple idea would be in use of Packagizer and a rule that checks sourceURL - contains www3.animeflv.net
and then customize the comment to place some meta information, that you can later use your script.
You can also change trigger to "Packagizer Hook" and there you can make use of
PackagizerLinkSandbox.getSourceUrls which contains the source/animeflv reference.

Quote:
Originally Posted by RydemStorm View Post
Is it possible to change the priority of a download link?
Yes, there are set/getPriority methods available

Quote:
Originally Posted by RydemStorm View Post
Is it possible to sort the links?
You can use controller API endpoints and create new packages and then add the links in desired order.

Quote:
Originally Posted by RydemStorm View Post
And the second rule I would like to apply after the package is formed before sending it down.
Use the trigger "A new link has been added" that is triggered when new link is added to linkcollector list


I recommend to ask here for help/hints when it's about scripting/scripts
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 08.07.2024 at 22:26.
Reply With Quote
  #3  
Old 09.07.2024, 23:29
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default

I put a Comment in Packagizer.
Then changed the validation:
if (link.getComment() === "animeflv") { ...

link.setPriority("HIGHEST");//Fixed, require string.

Sort, pending study.

Packagizer Hook: I don't know when it fired, but for this particular example it shot 22 times, with 2 packets, the first with 7/7 links shot up 16 times, and the second one with 0/1 link shot up 6 times.
https://board.jdownloader.org/attach...1&d=1720560519
Attached Images
File Type: png 07.png (116.2 KB, 0 views)
Reply With Quote
  #4  
Old 10.07.2024, 00:14
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default

I'm going to leave the latest version of the previous scripts, optimized and corrected in case it's of interest to anyone else.

Trigger: A new link has been added
Explain: Clean names files and set priority.
Code:
//crawledLink
if (link.getComment() === "animeflv") {
    var filename = link.getName();
    if (filename !== null && filename.includes(" Episodio ")) {
        var regex = /Episodio (\d+)/;
        var match = filename.match(regex);
        if (match) {
            var number = match[1];
            var num = number < 10 ? "0" + number : number;
            filename = filename.replace("Episodio " + number, num);
            link.setName(filename);
        }
    }
}

function getPriority(domain) {
    var favorites = ["mega.nz", "streamtape.com", "gofile.io"];
    for (var i = 0; i < favorites.length; i++) {
        if (favorites[i] === domain) {
            switch (i) {
                case 0:
                    return "HIGHEST";
                case 1:
                    return "HIGHER";
                case 2:
                    return "HIGH";
                default:
                    return "DEFAULT";
            }
        }
    }
    return "DEFAULT";
}
var domain = link.getURL().split('/')[2];
var priority = getPriority(domain);
link.setPriority(priority);
Trigger: Toolbar button pressed
Explain: I enable only the best favorite, disable the rest. If there are no favorites, I keep them all enabled.
Code:
if (name = "EST") {
    var favorites = ["mega.nz", "streamtape.com", "gofile.io"];

    function getFavoriteIndex(domain) {
        for (var i = 0; i < favorites.length; i++) {
            if (favorites[i] === domain) {
                return i;
            }
        }
        return -1;
    }
    for (var i = 0; i < getAllCrawledPackages().length; i++) {
        var best = -1;
        var package = getAllCrawledPackages()[i];
        for (var j = 0; j < package.getDownloadLinks().length; j++) {
            var link = package.getDownloadLinks()[j];
            var domain = link.getContentURL().split('/')[2];
            var favorite = getFavoriteIndex(domain);
            if (favorite >= 0 && (best == -1 || best > favorite)) {
                best = favorite;
            }
        }
        for (var j = 0; j < package.getDownloadLinks().length; j++) {
            var link = package.getDownloadLinks()[j];
            var domain = link.getContentURL().split('/')[2];
            link.setEnabled(favorites[best] == domain || best == -1);
        }
    }
}
https://board.jdownloader.org/attach...1&d=1720563493

https://board.jdownloader.org/attach...1&d=1720563493

https://board.jdownloader.org/attach...1&d=1720563493
Attached Images
File Type: png 08.png (100.3 KB, 0 views)
File Type: png 09.png (102.3 KB, 0 views)
File Type: png 10.png (95.8 KB, 0 views)

Last edited by RydemStorm; 10.07.2024 at 00:18.
Reply With Quote
  #5  
Old 10.07.2024, 09:59
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

Quote:
Originally Posted by RydemStorm View Post
Packagizer Hook: I don't know when it fired, but for this particular example it shot 22 times, with 2 packets, the first with 7/7 links shot up 16 times, and the second one with 0/1 link shot up 6 times.
It's fired for every link that is part of processing, this event is triggered and also before/after final linkcheck. see

Quote:
var myBoolean = linkcheckDone;
var myPackagizerLink = link;
var myString = state;
__________________
JD-Dev & Server-Admin
Reply With Quote
  #6  
Old 10.07.2024, 10:00
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

Priorities can also be set via Packagizer, see https://support.jdownloader.org/de/k...the-packagizer
__________________
JD-Dev & Server-Admin
Reply With Quote
  #7  
Old 10.07.2024, 10:02
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

Thanks for sharing your final nice/clean script, you should also link/reference it here https://board.jdownloader.org/showthread.php?t=70525
__________________
JD-Dev & Server-Admin
Reply With Quote
  #8  
Old 13.07.2024, 18:16
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default

How should I do that, just by doing Post Reply?
Reply With Quote
  #9  
Old 13.07.2024, 18:26
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default API?

I'd like to create a new package, starting from an existing one. I intend to sort the links during the creation of the same.
Can someone give me a basic example of how to use the API?

I think this would capture the package links, queryPackagesParameter.
I know that I should create the new package with the function movetoNewPackageParameter.

But I haven't even been able to invoke queryPackagesParameter and get it to work properly.
Reply With Quote
  #10  
Old 13.07.2024, 21:12
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

@RydemStorm: Just out of interest, why you wanna sort them? You are aware that order of links in list doesn't mean that this will also be the download order of the files. why the order that important to you? what you use/need it for?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 13.07.2024, 22:47
RydemStorm RydemStorm is offline
Junior Loader
 
Join Date: Jan 2023
Posts: 14
Default

Quote:
Originally Posted by Jiaz View Post
@RydemStorm: Just out of interest, why you wanna sort them? You are aware that order of links in list doesn't mean that this will also be the download order of the files. why the order that important to you? what you use/need it for?
Functionally, sorting may not be relevant at the time of downloading.
But if I have to manually make adjustments to make the download satisfactorily, having the links sorted makes things easier for me.
Sometimes some download links do not work in the best possible way due to payment issues, limitations of free services, or blocks for certain countries or servers.

Under these conditions, having the links in order helps me choose better download alternatives.

Also, I would be interested in knowing a little more about how to access the API, I am a programmer, I like to program, and I am making some tweaks to the JDownloader, to make it easier for me to use.

I've relatively covered the topics related to Packagizer, Link Crawler, Scripts Events, but I'm at zero with respect to the API.
Reply With Quote
  #12  
Old 14.07.2024, 21:58
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,519
Default

@RydemStorm: Understood. You can find the api docs here https://my.jdownloader.org/developers/
You can get the latest/live help via localhost:3128/help when enabling the deprecated api in Settings->Advanced Settings in JDownloader

Please see for example this script as reference
https://board.jdownloader.org/showpo...85&postcount=1
Quote:
callAPI("namespace","methodname", param1, param2...paramx)
Please don't hesitate to ask in case you're stuck or still have questions on this or need new methods
__________________
JD-Dev & Server-Admin
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 04:42.
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 - 2024, Jelsoft Enterprises Ltd.