JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 04.12.2024, 00:43
Nimboid Nimboid is offline
Super Loader
 
Join Date: Jan 2023
Location: UK
Posts: 25
Default Script to distribute incoming links by Property?

I'm trying to segregate incoming links based on a link Property: 'Date' provided by the plugin, so that links before a given date are directed to a different package than those on or after the date, which continue to the default package for the job.

Code:
callAPI("linkgrabberv2", "addLinks"
doesn't work for me unless its destination package exists; it doesn't error, just ignores. I can create a new package with
Code:
callAPI("linkgrabberv2", "movetoNewPackage"
for the initial link.

Question is, how to efficiently check whether package:<packageName> exists within the link grabber table, so that I call the "movetoNewPackage" version only once? Or is it possible to write a flag to an environment variable perhaps? I can see a getEnv(myString), but no equivalent setEnv().
Reply With Quote
  #2  
Old 04.12.2024, 07:16
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,654
Default

Use 'packagizer hook' trigger.

Code:
if (state == "BEFORE") {
    compare link date property

    if (link date property is before date) {
        check if "old package" exists in "allCrawledPackages()"
        
        if ("old package" exists) {
            set package name "old package";
        )
    }
)
Reply With Quote
  #3  
Old 04.12.2024, 11:44
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,654
Default

Quote:
Originally Posted by Nimboid View Post
... how to efficiently check whether package:<packageName> exists within the link grabber table
Code:
function packageExists(str) {
    return getAllCrawledPackages().some(function(package) {
        return package.name == str;
    })
}

//usage
alert(packageExists("before date"));
Reply With Quote
  #4  
Old 04.12.2024, 12:42
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,648
Default

Quote:
Originally Posted by Nimboid View Post
Code:
callAPI("linkgrabberv2", "addLinks"
Should work just fine as the package will be auto created if not existing. Can you please provide a working example? or show the full addLinks method call? Most likely some error in using it.

Quote:
Originally Posted by Nimboid View Post
Question is, how to efficiently check whether package:<packageName> exists within the link grabber table, so that I call the "movetoNewPackage" version only once? Or is it possible to write a flag to an environment variable perhaps? I can see a getEnv(myString), but no equivalent setEnv().
Instead of packageName you should use packageID as that lookup/use will be fast and will ensure that the correct package will be used. names may not be unique
And getEnv is for System Environment variables. You want to use
Quote:
getProperty and setProperty with global=true
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 05.12.2024, 01:08
Nimboid Nimboid is offline
Super Loader
 
Join Date: Jan 2023
Location: UK
Posts: 25
Default

Here's a minimal script:

Code:
//Trigger: A new link has been added

log('Trigger: A new link has been added');
log('getName(): ' + link.getName());

var myCrawledLink = crawledLink;
var linkURL;
linkURL = myCrawledLink.getContentURL();

try {
    // Next only works if the package already exists!
    // Otherwise, package with name supplied in 'Analyse and Add Links' dialog is created.

    callAPI("linkgrabberv2", "addLinks", {
        "links": linkURL,
        "overwritePackagizerRules": true,
        "packageName": "Date - before"
    });

} catch (err) {
    log("API call failed");
    log("Error: " + err + "");
}

I now suspect that the package is|has already been created with the externally-supplied package name when this is called, then the 'addLinks' call creates a new link on the queue, which gets discarded as a duplicate. I notice the crawler icons in the status bar increase in number. If I'm quick enough to delete the initial package from the link table, links still in progress do get re-added to a package with the script-supplied name.

However, if I manually rename the generated package to the script-supplied one, and delete some of its contents, then re-submit the same test links via the 'Analyse and Add Links' dialog, all the non-duplicates are deposited in the renamed package, the behaviour described in the previous paragraph does not occur.

I've tried the above with a Packagizer Hook trigger, as suggested earlier in the thread, link crawl jobs appear to get created recursively, and I have to restart to regain control.

The test links used were direct links to jpeg images.

Last edited by Nimboid; 05.12.2024 at 03:20. Reason: Clarification
Reply With Quote
  #6  
Old 05.12.2024, 01:15
Nimboid Nimboid is offline
Super Loader
 
Join Date: Jan 2023
Location: UK
Posts: 25
Default

Quote:
Originally Posted by Jiaz View Post
And getEnv is for System Environment variables. You want to use
Quote:
getProperty and setProperty with global=true
What is the scope and lifetime of a Property set with global=false, please?
Reply With Quote
  #7  
Old 05.12.2024, 06:04
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,654
Default

Quote:
Originally Posted by Nimboid View Post
I've tried the above with a Packagizer Hook trigger, as suggested earlier in the thread, link crawl jobs appear to get created recursively, and I have to restart to regain control.
You don't need to use 'addLinks' or 'moveToNewPackage' with the 'packagizer hook' script. The script is executed before the links are processed by the packagizer and will set the package name only if you condition is matched, else it will use the default package name (if it is set by the plugin) or the one generated by the packagizer.
Reply With Quote
  #8  
Old 07.12.2024, 22:34
Nimboid Nimboid is offline
Super Loader
 
Join Date: Jan 2023
Location: UK
Posts: 25
Default

I'm still working on this! Is there a way to determine from a script, whether the "Information overwrites packagizer rule" checkbox on the "Analyse and Add Links" dialog was set or unset?
Reply With Quote
  #9  
Old 08.12.2024, 06:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,654
Default

Quote:
Originally Posted by Nimboid View Post
I'm still working on this! Is there a way to determine from a script, whether the "Information overwrites packagizer rule" checkbox on the "Analyse and Add Links" dialog was set or unset?
Code:
function isAddLinksDialogOverwritesPackagizerRulesEnabled() {
    var interfaceName = "org.jdownloader.gui.views.linkgrabber.addlinksdialog.LinkgrabberSettings";
    var key = "AddLinksDialogOverwritesPackagizerRulesEnabled";

    return callAPI("config", "get", interfaceName, null, key);
}
Reply With Quote
  #10  
Old 09.12.2024, 16:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,648
Default

Quote:
Originally Posted by Nimboid View Post
What is the scope and lifetime of a Property set with global=false, please?
global = true -> all script can *see* the property value with key X
global = false -> only the script itself can *see* the property value with X
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 09.12.2024, 16:46
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,648
Default

Quote:
Originally Posted by Nimboid View Post
I'm still working on this! Is there a way to determine from a script, whether the "Information overwrites packagizer rule" checkbox on the "Analyse and Add Links" dialog was set or unset?
With next core update, you can check this via
Quote:
isOverwritesPackagizerRulesEnabled
method on the CrawlerJobSandbox
__________________
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 17:22.
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.