JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 20.10.2020, 08:47
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Question Event Script - Move Completed Downloads.

I don't plan on using the RAR Extension and would rather unrar the files myself. I had a look at the event scripter as an option of moving downloaded files once they were complete but the scripting language I'm unfamiliar with. Could someone whip up a quick script that moves files from the download directory to another directory if file is complete?

Just a script that moves ANY file type, including archives. As I won't be extracting them using JD2.

I should be able to adjust the script to accommodate for the proper directories.

If it helps, I'm running headless JD2 on Linux Ubuntu server, so directory structure is ~/ or /home/ (if absolute).

I appreciate anyone willing to assist. In the meantime, I will continue reading up on the language used and see if I can't figure things out.

Last edited by dbrown1986; 20.10.2020 at 09:26.
Reply With Quote
  #2  
Old 20.10.2020, 10:13
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,528
Default

Quote:
Originally Posted by dbrown1986 View Post
... script that moves files from the download directory to another directory if file is complete?
Code:
// Move downloaded files to user-specified folder
// Trigger: A Download Stopped

if (link.finished) {
    var destinationFolder = "/home/";
    getPath(link.downloadPath).moveTo(destinationFolder);
}
Reply With Quote
  #3  
Old 20.10.2020, 11:31
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

@mgpai: thanks for your fast help

@dbrown1986: Just out of interest, why don't you want to use the out-of-the-box extraction support?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #4  
Old 20.10.2020, 12:20
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Quote:
Originally Posted by mgpai View Post
Code:
// Move downloaded files to user-specified folder
// Trigger: A Download Stopped

if (link.finished) {
    var destinationFolder = "/home/";
    getPath(link.downloadPath).moveTo(destinationFolder);
}
Huge thanks mgpai, that should do nicely. Though, I didn't think of it at first, is there a way you could add a function to clear the download from the download list after it has been moved? My apologies.

Quote:
Originally Posted by Jiaz View Post
@mgpai: thanks for your fast help

@dbrown1986: Just out of interest, why don't you want to use the out-of-the-box extraction support?
Just a few issues I have run into on the headless install over the remote server. Also being that I'm syncing it to a team drive over rClone, sometimes the rar.part files don't get properly renamed when trying to download directly to the rClone mount or file conflict issues when trying to extract to the sync folder. Limitations of the OS or rClone, I'm sure, but I think it better to simply leave it in RAR format as well, so that they're easier to download via GDrive as well as keep googles built-in AV from complaining about any false-positives. I'm smart enough to scan files on my end with my own A/V.
Reply With Quote
  #5  
Old 20.10.2020, 12:45
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,528
Default

Quote:
Originally Posted by dbrown1986 View Post
... add a function to clear the download from the download list after it has been moved?
Code:
// Move downloaded files to user-specified folder and remove the link from download list
// Trigger: A Download Stopped

if (link.finished) {
    var destinationFolder = "/home/";
    getPath(link.downloadPath).moveTo(destinationFolder);
    link.remove();
}
Reply With Quote
  #6  
Old 20.10.2020, 14:10
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

@dbrown1986: Thanks for the feedback!
__________________
JD-Dev & Server-Admin
Reply With Quote
  #7  
Old 20.10.2020, 15:13
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Well, already ran into an issue. The script removes finished links, but does nothing else. The web gui would not allow me to import, so I used the Android app to do so. That resulted in the following:

Code:
[ {
  "eventTrigger" : "ON_DOWNLOAD_CONTROLLER_STOPPED",
  "enabled" : true,
  "name" : "Move Completed Downloads",
  "script" : "if (link.finished) {var destinationFolder = \"/home/seedit4me/drive/debrid/\"; getPath(link.downloadPath).moveTo(destinationFolder); link.remove(); }",
  "eventTriggerSettings" : {
    "isSynchronous" : false
  },
  "id" : 1603194963402
} ]
It would appear the path variable is being truncated by the script engine when it saves it to the JSON settings file. I went to edit the JSON and when I tried to remove those extra slashes; they seemingly commented out the rest of the script.
Reply With Quote
  #8  
Old 20.10.2020, 15:28
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

@dbrown1986: The webUI you have to correct format the script! You cannot directly copy/paste in there. The script of mgpai is for script editor. Best is to use JDownloader with gui and edit/test your scripts there and later copy/paste them via Settings->Advanced Settings->EventScripter.scripts
__________________
JD-Dev & Server-Admin
Reply With Quote
  #9  
Old 20.10.2020, 15:36
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Quote:
Originally Posted by Jiaz View Post
@dbrown1986: The webUI you have to correct format the script! You cannot directly copy/paste in there. The script of mgpai is for script editor. Best is to use JDownloader with gui and edit/test your scripts there and later copy/paste them via Settings->Advanced Settings->EventScripter.scripts
I did that too, and the engine on the GUI also truncates it. Something isn't quite working, but I will keep looking. So far I'ev tried JD2 Gui on windows, web panel and android app and they all do that to the above script.

Last edited by dbrown1986; 20.10.2020 at 15:45.
Reply With Quote
  #10  
Old 20.10.2020, 15:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

Can you copy paste the exact input to pastebin and give me link, so I can check?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 20.10.2020, 16:31
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Input Script:
**External links are only visible to Support Staff****External links are only visible to Support Staff**

Produces Output Script in JSON:
**External links are only visible to Support Staff****External links are only visible to Support Staff**

This is using JD2 GUI on Windows.
Reply With Quote
  #12  
Old 20.10.2020, 17:01
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

Is all correct. What do you think is wrong?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #13  
Old 20.10.2020, 17:03
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,232
Default

You can verify via json parser and json decoder, eg
jsonformatter.org/json-pretty-print and **External links are only visible to Support Staff****External links are only visible to Support Staff**
__________________
JD-Dev & Server-Admin
Reply With Quote
  #14  
Old 22.10.2020, 18:21
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Quote:
Originally Posted by Jiaz View Post
Is all correct. What do you think is wrong?
I got it to work on the GUI and headless now. Yay!
I didn't think about it, but if I wanted to have the downloads that are moved; be in there own subfolder, would I just add <jd:packagename> to the end of {var destinationFolder = "/home/" ?
Reply With Quote
  #15  
Old 22.10.2020, 18:49
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,528
Default

Quote:
Originally Posted by dbrown1986 View Post
... if I wanted to have the downloads that are moved; be in there own subfolder, would I just add <jd:packagename> to the end of {var destinationFolder = "/home/" ?
Example:
Code:
var destinationFolder = getPath("/home/seedit4me/drive/debrid/" + link.package.name);
Reply With Quote
  #16  
Old 22.10.2020, 19:57
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Code:
if (link.finished) {var destinationFolder = getPath("/home/seedit4me/drive/debrid/" + link.package.name); getPath(link.downloadPath).moveTo(destinationFolder); link.remove(); }
can't be parsed.

Could you correct it for me? Not sure where that line should go.

Last edited by dbrown1986; 23.10.2020 at 04:40.
Reply With Quote
  #17  
Old 23.10.2020, 07:09
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,528
Default

Quote:
Originally Posted by dbrown1986 View Post
... can't be parsed.
Quote characters must be escaped:
Code:
var destinationFolder = getPath(\"/home/seedit4me/drive/debrid/\" + link.package.name);

Better to install it in GUI and then copy the JSON value from advanced setings and paste it in the headless install via corresponding WebUI advanced settings.
Code:
Settings > Advanced Settings > EventScripter.scripts

Alternatively, after you install the script in GUI, you can copy the following file from GUI to headless:
Code:
<JDdownloader Folder>\cfg\org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json
Reply With Quote
  #18  
Old 23.10.2020, 17:34
dbrown1986 dbrown1986 is offline
Junior Loader
 
Join Date: Oct 2020
Posts: 11
Default

Quote:
Originally Posted by mgpai View Post
Quote characters must be escaped:
Code:
var destinationFolder = getPath(\"/home/seedit4me/drive/debrid/\" + link.package.name);

Better to install it in GUI and then copy the JSON value from advanced setings and paste it in the headless install via corresponding WebUI advanced settings.
Code:
Settings > Advanced Settings > EventScripter.scripts

Alternatively, after you install the script in GUI, you can copy the following file from GUI to headless:
Code:
<JDdownloader Folder>\cfg\org.jdownloader.extensions.eventscripter.EventScripterExtension.scripts.json
Okay. One last request and then I will leave this be. I PROMISE. On the headless install, I am trying to move the file from local to Google Drive via rClone; but as I mentioned in a few posts ago, it was only clearing the downloaded file and not moving it.

I was able to determine that this was because of something in the way the rClone mount is managed. The move is failing, so the script moves on to the next instruction, which is to clear the downloaded file from the download list.

As a test, I manually moved it in WinSCP and got Error 4; so I copied it instead and the copy worked without any flaws. Can you make one more adjustment to the script for me? Can you take what you've done so far, including the sub-folder by package adjustment, and modify it to copy instead of move?

I will use the COPY w/ sub-folder script on the headless,
but I will have a fallback machine as well for a MOVE w/ sub-folder script.

would replacing moveTo with copyTo do the trick?

@mgpai @Jiaz
So immensely thankful! If you have a "Buy me a coffee" or similar thing, send it to me in a private message. I'll throw you both a couple bucks for all the help you've provided.

EDIT: Somehow I broke it. JSON Pretty says the script checks out but now that I modified the var destinationFolder it won't move or copy the file at all on the windows gui or on the headless linux box.

This is how I modified the script:

Code:
[
  {
    "eventTrigger": "ON_DOWNLOAD_CONTROLLER_STOPPED",
    "enabled": true,
    "name": "Move Completed Downloads",
    "script": "if (link.finished) var destinationFolder = getPath(\"/home/seedit4me/drive/debrid/\" + link.package.name); getPath(link.downloadPath).moveTo(destinationFolder); link.remove(); }",
    "eventTriggerSettings": {
      "isSynchronous": false
    },
    "id": 1603260255137
  }
]

Last edited by dbrown1986; 23.10.2020 at 17:50.
Reply With Quote
  #19  
Old 23.10.2020, 17:42
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 71,044
Default

Quote:
Originally Posted by dbrown1986 View Post
@mgpai @Jiaz
So immensely thankful! If you have a "Buy me a coffee" or similar thing, send it to me in a private message. I'll throw you both a couple bucks for all the help you've provided.
You can donate through the JD "Contribute/Donate" tab.

If you want to buy a coffee for mgpai, you will have to contact him separately

Thanks again mgpai!

-psp-
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #20  
Old 23.10.2020, 17:51
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,528
Default

Quote:
Originally Posted by dbrown1986 View Post
... would replacing moveTo with copyTo do the trick?
Yes. It is also possible to use eventscripter method to delete the source file if/after it is successfully copied.

Code:
// Move downloaded files to user-specified folder and remove the link from download list
// Trigger: A Download Stopped

if (link.finished) {
    var destinationFolder = getPath("/home/seedit4me/drive/debrid/" + link.package.name);
    var copied = getPath(link.downloadPath).copyTo(destinationFolder);

    if (copied) {
        getPath(link.downloadPath).delete()
        link.remove();
    }
}
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 05:16.
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.