#1
|
|||
|
|||
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 08:26. |
#2
|
|||
|
|||
Quote:
Code:
// Move downloaded files to user-specified folder // Trigger: A Download Stopped if (link.finished) { var destinationFolder = "/home/"; getPath(link.downloadPath).moveTo(destinationFolder); } |
#3
|
||||
|
||||
@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 |
#4
|
|||
|
|||
Quote:
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. |
#5
|
|||
|
|||
Quote:
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(); } |
#6
|
||||
|
||||
@dbrown1986: Thanks for the feedback!
__________________
JD-Dev & Server-Admin |
#7
|
|||
|
|||
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 } ] |
#8
|
||||
|
||||
@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 |
#9
|
|||
|
|||
Quote:
Last edited by dbrown1986; 20.10.2020 at 14:45. |
#10
|
||||
|
||||
Can you copy paste the exact input to pastebin and give me link, so I can check?
__________________
JD-Dev & Server-Admin |
#11
|
|||
|
|||
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. |
#12
|
||||
|
||||
Is all correct. What do you think is wrong?
__________________
JD-Dev & Server-Admin |
#13
|
||||
|
||||
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 |
#14
|
|||
|
|||
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/" ? |
#15
|
|||
|
|||
Quote:
Code:
var destinationFolder = getPath("/home/seedit4me/drive/debrid/" + link.package.name); |
#16
|
|||
|
|||
Code:
if (link.finished) {var destinationFolder = getPath("/home/seedit4me/drive/debrid/" + link.package.name); getPath(link.downloadPath).moveTo(destinationFolder); link.remove(); } Could you correct it for me? Not sure where that line should go. Last edited by dbrown1986; 23.10.2020 at 03:40. |
#17
|
|||
|
|||
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 |
#18
|
|||
|
|||
Quote:
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 16:50. |
#19
|
||||
|
||||
Quote:
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 |
#20
|
|||
|
|||
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(); } } |
#21
|
|||
|
|||
Missing "{" bracket:
if (link.finished) {var destinationFolder ... Best way to avoid such errors are to add/test it in GUI (Click "Test compile" to check for syntax errors) and then add it to headless. |
#22
|
|||
|
|||
Quote:
|
#23
|
|||
|
|||
You can find me in JD Chat for online assistance with it:
Code:
kiwiirc.com/nextclient/irc.freenode.net/#jdownloader |
#24
|
||||
|
||||
@mgpai: thanks for the hint. good sight
@dbrown1986: The script doesn't care about "environment variables" and yes, the previous post shows the missing bracket. I've just tested the exact same script (different path) and working fine. see pastebin.com/RmHZPg3F
__________________
JD-Dev & Server-Admin |
#25
|
|||
|
|||
Quote:
eg. move files which are less than 999 MB. |
#26
|
||||
|
||||
@xefeg: try
Quote:
__________________
JD-Dev & Server-Admin |
#27
|
|||
|
|||
Also, I use Packagizer to download all rapidgator links to FOLDER A. Is there anyway to move only that Folder A to a new folder?
The below code does not seem to work Quote:
|
#28
|
||||
|
||||
@xefeg: I'm sorry but can you try to explain better? after a single link is finished, you cannot move the folder. do you want to move the finished file to folder B ?
__________________
JD-Dev & Server-Admin |
#29
|
|||
|
|||
Quote:
So using Packagizer, There is a custom folder for all files downloaded from RG. After this download is finished from RG custom folder, I wanted to move the downloaded files to a new folder. My default download folder for all files is @Jdownloader folder. Rapidgator folder is @RG folder, So, I basically wanted to move the files from @RG Folder to a @NewFolder |
#30
|
||||
|
||||
@xefeg: and why move after download? why not directly download to correct folder?
see here for example https://board.jdownloader.org/showpo...9&postcount=22 Quote:
__________________
JD-Dev & Server-Admin |
#31
|
|||
|
|||
Because the program I used which monitor the downloaded folder does not detect anything. It detects only when the files are moved.
It is still not working, It seems like all the files inside "J:/JJ" are moved which is the default download folder. I need to move the files which are downloaded into "J:/JJ/RG/" to the "J:/JJ/RGMove/". Quote:
Last edited by xefeg; 09.06.2022 at 12:04. |
#32
|
||||
|
||||
Quote:
__________________
JD-Dev & Server-Admin |
#33
|
||||
|
||||
can you tell me what program that is?
__________________
JD-Dev & Server-Admin |
#34
|
|||
|
|||
Quote:
I wanted to move the files from the RG folder to a new folder but the script seems to move all files whether its in the RG folder or not. |
#35
|
|||
|
|||
Code:
/* Move downloaded files Trigger: A Download Stopped */ if (link.finished) { var curFolder = link.package.downloadFolder; var newFolder = curFolder.replace("/JJ/RG/", "/JJ/RGMove/"); newFolder != curFolder && getPath(link.downloadPath).moveTo(newFolder); } |
#36
|
|||
|
|||
Hello Sir, it still does not move. The downloaded files remains at "/JJ/RG/"
|
#37
|
|||
|
|||
Quote:
Code:
Try replacing "/" with "\\". |
#38
|
|||
|
|||
|
#39
|
||||
|
||||
@mgpai: with next core update you can access FilePath.getPathSeparator
which will return / or \ depending on current OS
__________________
JD-Dev & Server-Admin |
#40
|
|||
|
|||
Thanks @Jiaz.
|
Thread Tools | |
Display Modes | |
|
|