#1
|
|||
|
|||
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" Code:
callAPI("linkgrabberv2", "movetoNewPackage" 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(). |
#2
|
|||
|
|||
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"; ) } ) |
#3
|
|||
|
|||
Quote:
Code:
function packageExists(str) { return getAllCrawledPackages().some(function(package) { return package.name == str; }) } //usage alert(packageExists("before date")); |
#4
|
||||
|
||||
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:
And getEnv is for System Environment variables. You want to use Quote:
__________________
JD-Dev & Server-Admin |
#5
|
|||
|
|||
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 |
#6
|
|||
|
|||
What is the scope and lifetime of a Property set with global=false, please?
|
#7
|
|||
|
|||
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.
|
#8
|
|||
|
|||
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?
|
#9
|
|||
|
|||
Quote:
Code:
function isAddLinksDialogOverwritesPackagizerRulesEnabled() { var interfaceName = "org.jdownloader.gui.views.linkgrabber.addlinksdialog.LinkgrabberSettings"; var key = "AddLinksDialogOverwritesPackagizerRulesEnabled"; return callAPI("config", "get", interfaceName, null, key); } |
#10
|
||||
|
||||
Quote:
global = false -> only the script itself can *see* the property value with X
__________________
JD-Dev & Server-Admin |
#11
|
||||
|
||||
Quote:
Quote:
__________________
JD-Dev & Server-Admin |
Thread Tools | |
Display Modes | |
|
|