JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #301  
Old 10.02.2018, 19:21
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Question

Hi, I am running a Pi2 with Ubuntu Mate 16.04 and JDownloader headless. How can I go about making the following work using event scripter:

Event: when download controller starts
Code:
*if files exist in folder /home/myuser/myfolder*
then "killall transmission-gtk" #This is a Linux command normally run in terminal
*end*
Event: when download starts
Code:
"killall transmission-gtk"
Event: when download controller stops
Code:
call home/myuser/myscript.sh
"transmission-gtk %U -m" #must only run after myscript.sh has finished
The contents of myscript.sh is as follows:
Code:
#!/bin/bash

for i in /home/myuser/myfolder/*.mp4
do
/usr/local/bin/gdrive upload --delete "$i" #uploads file to google drive and then deletes it from disk
done
Any help is appreciated, thanks !
Reply With Quote
  #302  
Old 11.02.2018, 07:52
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 300
Default

Something like this should work. Jiaz should be able to confirm.

Event: when download controller starts
Code:
var myFolder = "/home/myuser/myfolder";
var fileExists = getPath(myFolder).getChildren().length;
if (fileExists) callAsync(null, "killall", "transmission-gtk");

Event: when download starts
Code:
callAsync(null, "killall", "transmission-gtk");

Event: when download controller stops
Code:
var myScript = "home/myuser/myscript.sh";
callSync(myScipt);
callAsync(null, "transmission-gtk", "%U", "-m");
  • Install/test the scripts in a desktop install.
  • Copy/paste "Settings>Advanced Settings>EventScripter.scripts" contents to WebUI (headless install)
Reply With Quote
  #303  
Old 11.02.2018, 12:17
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Question

Quote:
Originally Posted by mgpai View Post
Something like this should work. Jiaz should be able to confirm.
  • Install/test the scripts in a desktop install.
  • Copy/paste "Settings>Advanced Settings>EventScripter.scripts" contents to WebUI (headless install)
Thank-you very much ! I will test it and let you know.

Quick question, is there any difference in running the "transmission-gtk" commands Synchronous or Asynchronous ? And all the event scripts should be set as Synchronous ?

EDIT: Also is it possible to update and restart Jdownloader at a certain time of the day if and only if updates are available ? I noticed that you set a "start time" on page 1 and used the interval trigger.

Last edited by RPH; 11.02.2018 at 12:53.
Reply With Quote
  #304  
Old 11.02.2018, 15:34
Hartm Hartm is offline
Junior Loader
 
Join Date: Sep 2017
Posts: 11
Default

Quote:
Originally Posted by mgpai View Post
If a download is fully stopped, an additional check to verify the download duration is required to ensure sufficient time is given to reach its normal speed again.

Code:
github.com/mgpai/resources/blob/master/jdownloader/eventscripter/scripts/Hartm_2.js
thank you very much works like a charm =)
Reply With Quote
  #305  
Old 11.02.2018, 19:45
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Question

Based on my earlier question about updating & restarting JDownloader at a specific time of the day if an update is available, I wrote this script:

Code:
var t = [03, 45]; //Set Starting Time 

if (isDownloadControllerIdle() && isUpdateAvailable()) {
    interval = 1000;
    restartAndUpdate();
} else {
    var timeDiff = (new Date().setHours(t[0], t[1])) - (new Date());
    if (timeDiff <= 0) {
        interval = (86400000) - Math.abs(timeDiff);
    } else {
        interval = timeDiff;
    }
}

//Functions

function isUpdateAvailable() {
    return callAPI("update", "isUpdateAvailable");
}

function restartAndUpdate() {
    callAPI("update", "restartAndUpdate");
}
However, when the current time is after the starting time it doesn't work. For some reason the "if" statement will not evaluate the negative resulting number from the modulus.

I didn't want to have the interval running every second or every minute until the starting time....

EDIT: I changed the code to not use the modulus and it seems to be working fine now. But how can I check if another script is running ??? I don't want the update to run if my "Event: when download controller stops" script is running.

Last edited by RPH; 12.02.2018 at 16:32. Reason: Corrected script.
Reply With Quote
  #306  
Old 12.02.2018, 00:40
netgearjd netgearjd is offline
JD Fan
 
Join Date: Aug 2014
Posts: 76
Default

First of all, thanks a lot for the script. Simple, yet 100% effective.

Quote:
Originally Posted by mgpai View Post
It might also be possible (new API method required) to set comment (e.g. "Duplicate File") to the matching links. Of these methods, disabling the links might be the most convenient, as they can then be easily removed using "Delete Links: disabled" option.
I would prefer setting the comment field actually, since I have links in other packages enabled/disabled as per my requirement and I don't see how "Delete Links: disabled" can be restricted only to a particular package.

@Jiaz: Can we have a new API method to set the link comment from a script?

@mgpai: As for the script itself, I want to make one small improvement if possible - how can I add a check to see whether the file exists or not before it is read, and display a simple warning dialog and abort execution if it doesn't exist?
Reply With Quote
  #307  
Old 13.02.2018, 06:33
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 300
Default

Quote:
Originally Posted by RPH View Post
... Quick question, is there any difference in running the "transmission-gtk" commands Synchronous or Asynchronous ? And all the event scripts should be set as Synchronous ?...
Use callSync() to call an external process and wait for the process to return (end) before executing the next line in the code.

Enable the "Synchronous Execution" in a script, to wait for the current instance of the script to end, before executing subsequent instance(s) of the same script, if/when triggered.
Reply With Quote
  #308  
Old 13.02.2018, 06:41
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 300
Default

Quote:
Originally Posted by netgearjd View Post
... add a check to see whether the file exists or not before it is read, and display a simple warning dialog and abort execution if it doesn't exist?
Script Updated:
Code:
github.com/mgpai/resources/blob/master/jdownloader/eventscripter/scripts/netgearjd.js

Last edited by mgpai; 13.02.2018 at 06:41. Reason: Made link to the script visible
Reply With Quote
  #309  
Old 13.02.2018, 10:09
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 300
Default

Quote:
Originally Posted by RPH View Post
... how can I check if another script is running ??? I don't want the update to run if my "Event: when download controller stops" script is running.
Use setProperty() to set a global property in your "Event: when download controller stops" script to indicate that it is running and use getProperty() in your update script to access/check that property before restarting to update.
Reply With Quote
  #310  
Old 13.02.2018, 14:13
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Default

Quote:
Originally Posted by mgpai View Post
Use callSync() to call an external process and wait for the process to return (end) before executing the next line in the code.

Enable the "Synchronous Execution" in a script, to wait for the current instance of the script to end, before executing subsequent instance(s) of the same script, if/when triggered.
Quote:
Originally Posted by mgpai View Post
Use setProperty() to set a global property in your "Event: when download controller stops" script to indicate that it is running and use getProperty() in your update script to access/check that property before restarting to update.
Alright, thanks !
Reply With Quote
  #311  
Old 13.02.2018, 17:50
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 57,418
Default

@mgpai: Thanks for providing great support here !

@RPH: mgpai will be great eventscript teacher for you be nice and you will become master like him
__________________
JD-Dev & Server-Admin
Reply With Quote
  #312  
Old 16.02.2018, 12:51
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Default

Hi guys, I got a big problem. While testing my scripts, I set the "updateAndRestart" command to run if JDownloader is idle with the interval as 1000ms. Now as soon as JDownloader starts, it restarts and I cannot use it.

How can I disable this ? Thanks
Reply With Quote
  #313  
Old 16.02.2018, 13:09
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 300
Default

@RPH: You can disable the script by editing "org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json" which can be found in 'cfg' folder.
Reply With Quote
  #314  
Old 16.02.2018, 13:13
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 57,418
Default

In your cfg folder you will find org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json
either remove it or edit and search enabled and set to false
__________________
JD-Dev & Server-Admin
Reply With Quote
  #315  
Old 16.02.2018, 13:16
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Default

Quote:
Originally Posted by mgpai View Post
@RPH: You can disable the script by editing "org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json" which can be found in 'cfg' folder.
Thanks ! The restart and update command kept asking me for permission so I was trying to force it to run so I could give it permission and set it to never ask again. I removed the update check in the "if" statement but completely forgot to change the interval from 1s.

Once I have given it permission it will not ask for it again, correct ? Even if JDownloader shuts down and turns on again with say a power outage ? Because I am sure I have given it permissions before but it still asks.

Last edited by RPH; 16.02.2018 at 13:31.
Reply With Quote
  #316  
Old 16.02.2018, 13:38
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 57,418
Default

Ah, its about permission. This one is saved in JDownloader. Yes, the permission is saved and not asked again. Permissions are on per method basis
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 16.02.2018 at 13:46.
Reply With Quote
  #317  
Old 16.02.2018, 13:54
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Default

Quote:
Originally Posted by Jiaz View Post
Ah, its about permission. This one is saved in JDownloader. Yes, the permission is saved and not asked again. Permissions are on per method basis
It seems though like every time I change this block of code it asks for permission again:

Code:
if (isDownloadControllerIdle() && isUpdateAvailable()) {
    interval = 1000;
    restartAndUpdate();
}
Is there a config file where I can just manually set the permission to allowed or check if it is allowed ?

Last edited by RPH; 16.02.2018 at 14:24.
Reply With Quote
  #318  
Old 16.02.2018, 15:49
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 57,418
Default

@RPH: I just checked, permissions are stored for that script. when you change it, permissions are lost
__________________
JD-Dev & Server-Admin
Reply With Quote
  #319  
Old 16.02.2018, 16:00
RPH RPH is offline
Super Loader
 
Join Date: Jul 2017
Posts: 28
Default

Quote:
Originally Posted by Jiaz View Post
@RPH: I just checked, permissions are stored for that script. when you change it, permissions are lost
Thanks for checking. So you mean if any line of code is changed in the script, all permissions for that script are lost ?

How would I go about allowing permissions for my "update check" then, because it is set to run in the early hours of the morning and only when an update is available ? It's thus not possible for me to sit and wait for the permission dialog box to appear on myJDownloader.
Reply With Quote
  #320  
Old 16.02.2018, 16:05
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 57,418
Default

I will add easy method to disable permission checks
__________________
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 18:48.
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 - 2018, Jelsoft Enterprises Ltd.