JDownloader Community - Appwork GmbH
 

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 14.03.2016, 15:51
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Post [Event Scripter] Execute script after package completely finished

I want to call my own program after a package is complete.

So far I have two scripts, one for ON_PACKAGE_FINISHED and one for ON_ARCHIVE_EXTRACTED, but neither is working exactly the way I want it:
Code:
**External links are only visible to Support Staff**
ON_PACKAGE_FINISHED works as expected IF the download doesn't contain any archives. But if there are archives than the script is called before or during extraction.

ON_ARCHIVE_EXTRACTED is tricky when there's multiple or nested archives, because it's called for each of them. So one finished package might result in multiple user script calls, and also run in parallel with JD continuing with extracting stuff.



Is there any event to make JD call my script exactly once and only once the download/extraction/etc is completely finished.

Or some other state that I can check in the script to abort the user script if the package isn't completely finished?
Reply With Quote
  #2  
Old 14.03.2016, 16:18
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

A package can contain multiple archives or a mix of archives/non archives files.
I suggest to
1.) check for all non finished archives files on *download finished* event and call your script for them
and
2.) use ON_ARCHIVE_EXTRACTED for all archives.

There is no single event that provides what you want.
You could also use a script on interval that checks the package for ongoing downloads and only calls your tool once all links are finished and extracted. Then check every 30 secs and loop through all available packages.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 16.03.2016, 08:47
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default Script for Filebot integration

Would this better solution ? Will still require 2 scripts, but filebot should be called only once either by Script 1 or by Script 2, when package is finished.

Script 1:
Code:
//Trigger: "A Download Stopped"

var notArchive = link.getArchive() == null;
var packageFinished = link.getPackage().isFinished();

var folder = link.getPackage().getDownloadFolder();
var name = link.getPackage().getName();

if (notArchive && packageFinished) {
    alert("External Command " + " Parameter1: " + folder + " Parameter2: " + name);
}
Script 2:
Code:
//Trigger: "Archive Extraction Finished"

var packageFinished = archive.getDownloadLinks()[0].getPackage().isFinished();

var folder = archive.getDownloadLinks()[0].getPackage().getDownloadFolder();
var name = archive.getDownloadLinks()[0].getPackage().getName();


if (packageFinished) {
    alert("External Command " + " Parameter1: " + folder + " Parameter2: " + name);
}

Last edited by mgpai; 16.03.2016 at 08:54. Reason: Correction
Reply With Quote
  #4  
Old 16.03.2016, 08:58
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

Using the state is a good idea. Is there a state that can only be reached after download/extract has been completed that I can check in the script and abort if something is still going on?

I assume Package.isFinished() is true as soon as download is complete, so during extraction it will already be true, correct? Otherwise I could just do nothing whenever !package.isFinished().
Reply With Quote
  #5  
Old 16.03.2016, 09:20
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Script 1: Runs filebot when non-archive "finishes" the package.
First script > not an archive > no extraction necessary > check if package finished > run filebot

Script 2: Runs filebot when an archive file "finishes" the package.
Second script > archive > extraction necessary and completed (Trigger: Archive Extraction Finished) > check if package finished > run filebot

Package.isFinished() can be true when extraction is pending. You can check extraction status using var isExtracting = link.getExtractionStatus() == "RUNNING"; and abort.

Last edited by mgpai; 16.03.2016 at 09:37.
Reply With Quote
  #6  
Old 16.03.2016, 11:48
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

@mgpai: Thanks for your great help/support on these topics!
__________________
JD-Dev & Server-Admin
Reply With Quote
  #7  
Old 16.03.2016, 12:09
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

@Jiaz: My pleasure.

Quote:
Originally Posted by rednoah View Post
Is there any event to make JD call my script exactly once and only once the download/extraction/etc is completely finished.
Have not tested it with filebot, but I think these scripts might just do the trick.

Code:
//Trigger: "Package Finished"

var links = package.getDownloadLinks();
var runFilebot = true;

for (var i = 0; i < links.length; i++) {
    var link = links[i];
    if (link.getArchive() != null && link.getExtractionStatus() != "SUCCESSFUL") {
        runFilebot = false;
        break;
    }
}

if (runFilebot) {
    alert("Filebot Triggerd by \"Package Finished\"");
}
Code:
//Trigger: "Archive Extraction Finished"

var package = archive.getDownloadLinks()[0].getPackage();
var links = package.getDownloadLinks();
var runFilebot = true;

for (var i = 0; i < links.length; i++) {
    var link = links[i];
    if (link.getArchive() != null && link.getExtractionStatus() != "SUCCESSFUL" || !package.isFinished()) {
        runFilebot = false;
        break;
    }
}

if (runFilebot) {
    alert("Filebot Triggered by \"Archive Extraction Finished\"");
}

Last edited by mgpai; 17.03.2016 at 07:25. Reason: Replaced "Download Stopped Script" with "Package Finished Script".
Reply With Quote
  #8  
Old 28.03.2016, 14:26
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

Does anyone why archive.getDownloadLinks() might be empty?

Code:
**External links are only visible to Support Staff**
Reply With Quote
  #9  
Old 28.03.2016, 14:30
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Hello together,

i am currently trying to figure out how to launch Filebot after jD did extract the archives.

On the Filebot Forums i found this Tutorial: **External links are only visible to Support Staff**...

I installed the EventScripter and inserted this script:

Code:
var script = '/home/pi/.jd2/jdownloader-postprocess.sh'

var path = archive.getFolder()
var name = archive.getName()
var label = archive.getDownloadLinks() && archive.getDownloadLinks()[0].getPackage().getComment() ? archive.getDownloadLinks()[0].getPackage().getComment() : 'N/A'

var command = [script, path, name, label, 'ARCHIVE_EXTRACTED']

log(command)
log(callSync(command))
In 70-80% of the cases it works just fine.. but every other day i get this error code:

Code:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot call method "getPackage" of undefined (#5)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3629)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3613)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3634)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3650)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3664)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2221)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2215)
   at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
   at script(:5)
   at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
   at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
   at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
   at org.jdownloader.scripting.JSHtmlUnitPermissionRestricter$SandboxContextFactory.doTopCall(JSHtmlUnitPermissionRestricter.java:121)
   at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
   at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
   at net.sourceforge.htmlunit.corejs.javascript.Context.evaluateString(Context.java:1212)
   at org.jdownloader.extensions.eventscripter.ScriptThread.evalUNtrusted(ScriptThread.java:196)
   at org.jdownloader.extensions.eventscripter.ScriptThread.run(ScriptThread.java:92)
I need jD to extract the packages because of its password entering/cracking capabilities... so i found this thread and the script above...

I am not sure whats wrong with my setup and why it shows me this error so often while in most if the cases everything works just fine..

Platform: Raspberry Pi 3 running the latest Raspbian, jDownloader 2 and Filebot:

Code:
pi@Plex:~ $ filebot -script fn:sysinfo
FileBot 4.6.2 (r3768)
JNA Native: 4.0.1
MediaInfo: MediaInfoLib - v0.7.70
Apache Commons VFS: [zip, ftps, rar, ftp, tar, tgz, tbz2, sftp]
Chromaprint: java.io.IOException: Cannot run program "fpcalc": error=2, No such file or directory
Extended Attributes: OK
Groovy Engine: 2.4.6
JRE: Java(TM) SE Runtime Environment 1.8.0_65 (headless)
JVM: 32-bit Java HotSpot(TM) Client VM
CPU/MEM: 4 Core / 224 MB Max Memory / 15 MB Used Memory
OS: Linux (arm)
Package: IPKG
Data: /opt/share/filebot/data/pi
uname: Linux Plex 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux
Done ヾ(@⌒ー⌒@)ノ

Does anyone know whats wrong? Will the script by mgpai help in any way?
Reply With Quote
  #10  
Old 28.03.2016, 15:52
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

Quote:
Originally Posted by rednoah View Post
Does anyone why archive.getDownloadLinks() might be empty?

Code:
**External links are only visible to Support Staff**
getDownloadLinks only works when the links are still in list. In case you have setup to remove finished links/packages, then links are no longer available
Same goes for deep extraction (archive in archve) those archives do not have any associated links
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 28.03.2016, 15:54
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

@jdjdjd123: same reason, see my previous answer. you also need to check for existance of DownloadLinks
__________________
JD-Dev & Server-Admin
Reply With Quote
  #12  
Old 28.03.2016, 16:17
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Ok so its best to keep the download links in jd and delete them manually afterwards?
Reply With Quote
  #13  
Old 28.03.2016, 16:42
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

Or you modify script to handle this situation. Wait for next core update, I've modified getDownloadlinks to be either undefined or contain at least 1 item.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #14  
Old 28.03.2016, 17:26
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

I am unable to modify any script... i am just a user to be honest and thankfully for your and rednoahs support. I guess i will just disable the auto deletion of finished packages and wait for the next coreupdate and hope it will work by then.. if not? Not a problem. I simply delete the links myself
Reply With Quote
  #15  
Old 28.03.2016, 17:28
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

@jdjdjd123: your script should work fine with next core update
__________________
JD-Dev & Server-Admin
Reply With Quote
  #16  
Old 28.03.2016, 17:34
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Thx for the info and update All credits regarding the script i posted go to rednoah

Edit: Do you know when approximately this core update will be delivered to the end user? I just ask because its hard to reproduce the error on purpose and i wonder when i might be able to reenable the switch

Last edited by jdjdjd123; 28.03.2016 at 17:37.
Reply With Quote
  #17  
Old 29.03.2016, 14:20
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

Later this day
__________________
JD-Dev & Server-Admin
Reply With Quote
  #18  
Old 06.04.2016, 16:47
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Hello again

i still have issues calling the script when i have the "delete links after extract" enabled. Is there maybe a way to let the links be deleted automatically but have a delay of up to 10 seconds or so until the script is called?
Reply With Quote
  #19  
Old 06.04.2016, 17:26
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

What issue exactly? maybe you need to update/fix the script. There should be no problems anymore
__________________
JD-Dev & Server-Admin
Reply With Quote
  #20  
Old 06.04.2016, 17:51
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

I use this script: **External links are only visible to Support Staff****External links are only visible to Support Staff**

And get this output: http://imgur.com/6iwX13Q

Talked to rednoah here: **External links are only visible to Support Staff****External links are only visible to Support Staff**

I thought maybe delaying the deletion of the links would solve the issue
Reply With Quote
  #21  
Old 06.04.2016, 18:01
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

The Script contains a lot of errors
1.) if links is empty, package will become null and then label will crash because of nullpointer exception
2.) redundant check. if there are links to the archive in archive.getDownloadLinks, then link.getArchive will never be null. this check does not make any sense
3.) no need to check package.isFinished for every link because it is always the same package

I dont see what *deletion of the links* has to do with filebot. The links itself are not used at all for filebot. I guess the script simply fails because of the errors.
You can inform rednoah about my comments and maybe he/she can fix the script.

He/she can also contact us via support@jdownloader.org, so we can provide better help on this
__________________
JD-Dev & Server-Admin
Reply With Quote
  #22  
Old 06.04.2016, 18:44
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Thx, just forwarded this thread to him
Reply With Quote
  #23  
Old 06.04.2016, 20:03
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

I'm happy to accept pull requests:
Code:
**External links are only visible to Support Staff**

Since there's people that know the API:

* How do I get the package in the onArchiveExtracted event if there's no links? package isn't predefined like in the onPackageFinished call.
* What variables can be null or empty? I'm just checking everything cause I have no idea.
* I use the links[i].getArchive() in the onPackageFinished script as well, so the same code should work for both events this way.


We can email if you want, but here in the forums is probably better so that this stuff is public and so that people can find it via Google.

Last edited by rednoah; 06.04.2016 at 20:10.
Reply With Quote
  #24  
Old 06.04.2016, 20:35
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

I will check those scripts tomorrow inform you about possible changes/ideas.
For "onArchiveExtracted " there is no need to access the links. All important information should be available from archive itself.

Maybe a native java solution (extension to JDownloader) would be better. That way ppl just place the .jar in their installation and it works after restart.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #25  
Old 06.04.2016, 22:08
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

Having people copy the jar around is probably more tricky for most people than just using the installer packages and just making a command-line call.

I could get around the JD-glue-logic bash script. But since a bash script is the entry point for all the other filebot integrations, there's more help and support for that approach.
Reply With Quote
  #26  
Old 07.04.2016, 08:18
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

Okay, I will check the existings script and provide feedback how to change them to also work in all situations (eg no links are available)
__________________
JD-Dev & Server-Admin
Reply With Quote
  #27  
Old 12.04.2016, 10:25
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Hey,

great to see you working together on this! Thx a lot!
Reply With Quote
  #28  
Old 16.04.2016, 15:32
jdjdjd123 jdjdjd123 is offline
Super Loader
 
Join Date: Nov 2014
Posts: 25
Default

Hey all,

may i ask if you already took a look at those scripts?
Reply With Quote
  #29  
Old 16.04.2016, 15:51
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

What's not working?
Reply With Quote
  #30  
Old 17.04.2016, 10:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,290
Default

I did not find time yet to review them. I saw some possible issues in situations like (links already gone or deep decrypt)
__________________
JD-Dev & Server-Admin
Reply With Quote
  #31  
Old 11.08.2018, 13:22
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by rednoah View Post
... Is there any event to make JD call my script exactly once and only once the download/extraction/etc is completely finished ...
Seems it might be possible after all. Haven't tested it with filebot though. Perhaps you can check and confirm.

Code:
github.com/mgpai/resources/blob/master/jdownloader/eventscripter/scripts/rednoah.js
Reply With Quote
  #32  
Old 12.08.2018, 05:45
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

Here's examples for the Event Scripter plugin:
Code:
github.com/filebot/plugins/tree/master/jdownloader
Reply With Quote
  #33  
Old 12.08.2018, 08:04
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by rednoah View Post
Here's examples for the Event Scripter plugin:
Code:
github.com/filebot/plugins/tree/master/jdownloader
Thanks. I am not a filebot user so was not looking for scripts. I had previously (in this thread) suggested to make use of 2 triggers, but found it might be possible to call filebot using only 1 trigger. Thought I'll let you know.
Reply With Quote
  #34  
Old 12.08.2018, 09:15
rednoah rednoah is offline
JD Alpha
 
Join Date: Dec 2015
Posts: 22
Default

If you never process archives, then just PackageFinished will be fine. If you always process archives, then just ArchiveExtracted will be fine. However, if your downloads are mixed, then you will need both, because PackageFinished is called before ArchiveExtracted, unless you don't use JD for archive extraction, in which case ArchiveExtracted won't be necessary either.
Reply With Quote
  #35  
Old 12.08.2018, 09:34
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by rednoah View Post
... if your downloads are mixed, then you will need both ...
This script is designed to work for mixed downloads, using a single "Remote API Event Fired" trigger.
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 01:05.
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.