JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 08.12.2024, 12:56
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default Moving packages and files after completion

I'm hoping to move packages to a separate folder after completion. I know the feature does not exist in JDownload 2. I found a script at https://board.jdownloader.org/showpo...7&postcount=29 .

However, it moves all download files to a single directory, without preserving any of the original directory structure. Is there any way to fix that ?

If this was C or C++, I wouldn't have any issue doing it myself, but I'm unfortunately useless with JavaScript, and ChatGPT doesn't seem sufficiently versed in EventScripter to make the change for me, despite the very clear prompt I gave it. It keeps producing code using identifiers that are not part of EventScripter.
Reply With Quote
  #2  
Old 09.12.2024, 10:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Code:
/*
    move finished
    trigger : jdownloader started
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        var curFolder = package.downloadFolder;
        var newFolder = curFolder.replace("\\downloading", "\\finished");

        if (curFolder != newFolder) {
            package.downloadFolder = newFolder;
        }
    }
})

Should work fine, but better run/try it on test install first.
Reply With Quote
  #3  
Old 10.12.2024, 04:48
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Thanks for your answer. Response below.

Quote:
Originally Posted by mgpai View Post
Code:
/*
    move finished
    trigger : jdownloader started
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        var curFolder = package.downloadFolder;
        var newFolder = curFolder.replace("\\downloading", "\\finished");

        if (curFolder != newFolder) {
            package.downloadFolder = newFolder;
        }
    }
})

Should work fine, but better run/try it on test install first.
Thanks for your response.
I tried it, as the following :

Code:
/*
    move finished
    trigger : jdownloader started
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        var curFolder = package.downloadFolder;
        var newFolder = curFolder.replace("d:\\Downloads\\JDownloader", "d:\\Downloads\\Complete");

        if (curFolder != newFolder) {
            package.downloadFolder = newFolder;
        }
    }
})
Unfortunately, it had no effect, even after I restarted JDownloader. It seems to be a no-op. I have recently downloaded packages under D:\Downloads\JDownloader, each with their own directory structure, and nothing got moved to d:\Downloads\Complete .

Thanks again.

Last edited by rabidman; 10.12.2024 at 13:55.
Reply With Quote
  #4  
Old 10.12.2024, 09:19
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Only files which were downloaded by JD into that folder (and still exist there) will be moved. Files subsequently copied or extracted to that folder will not be moved.

This is by design, since multiple packages can share a (that) common download folder and it might contain files belonging to other packages.

I haver read your reply in the other thread. You can test/use this to to move the entire folder, keeping in mind it moves ALL the files/folders in it.

Code:
/*
    demo
    trigger : click test run in top panel
*/    

var myPackage = getPath("d:\\downloads\\jdownloader\\myPackage");
var complete = "d:\\downloads\\complete";
var moved = getPath(myPackage).moveTo(complete);

alert(moved);

If you prefer, you can also use CLI commands in eventscripter (using callSync/callAsync) to do the same.
Reply With Quote
  #5  
Old 10.12.2024, 10:17
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Thanks again for your response. More inline.

Quote:
Originally Posted by mgpai View Post
Only files which were downloaded by JD into that folder (and still exist there) will be moved. Files subsequently copied or extracted to that folder will not be moved.
Why / how would files be subsequently copied, without manual intervention ?
And why would extraction cause an issue, as long as the extraction is performed inside the package folder ?

Quote:
This is by design, since multiple packages can share a (that) common download folder and it might contain files belonging to other packages.
Is there a way to prevent this, ie. creating unique folder names for each package ?
Or alternately, perform the move only after the last package with a shared folder name has completed downloading ?

Quote:
Quote:
I haver read your reply in the other thread. You can test/use this to to move the entire folder, keeping in mind it moves ALL the files/folders in it.

Code:
/*
    demo
    trigger : click test run in top panel
*/    

var myPackage = getPath("d:\\downloads\\jdownloader\\myPackage");
var complete = "d:\\downloads\\complete";
var moved = getPath(myPackage).moveTo(complete);

alert(moved);

If you prefer, you can also use CLI commands in eventscripter (using callSync/callAsync) to do the same.
Thank you ! That script worked. But of course, I had to hardcode the package name in there, which I don't want to do. How can I fix that ?

Also, what would be the correct trigger to use ?

Thanks again !

Last edited by rabidman; 10.12.2024 at 10:32.
Reply With Quote
  #6  
Old 10.12.2024, 12:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
Why / how would files be subsequently copied, without manual intervention ?
And why would extraction cause an issue, as long as the extraction is performed inside the package folder ?
The script uses a package object method to 'set' the download folder. It will update the new path only to the links belonging to that package and moves the files correspondng to those links, to the new location. Thus, the connection between the download link and file on disk will be preserved. It will not be aware of any othe files in that folder, belonging to a different package or copied or extracted into it manually or otherwise, and hence they will not be moved.

Quote:
Originally Posted by rabidman View Post
Is there a way to prevent this, ie. creating unique folder names for each package ?
Or alternately, perform the move only after the last package with a shared folder
name has completed downloading ?
Extracted files would still not be moved.

Quote:
Originally Posted by rabidman View Post
Thank you ! That script worked. But of course, I had to hardcode the package name in there, which I don't want to do. How can I fix that ?

Also, what would be the correct trigger to use ?
That was just for you to check if it works as intended. "moveTo" can be used to replace "setFolder" method in the original script.

It would not be wise to 'set' the new path while extraction is active. So, the script uses 'jdownloader started' trigger, at which point extraction presumably will have been completed. A better option is to create a "toolbar button pressed" and manually run the script by clicking the button.

Point to note: "moveTo" is a filePath object method, when used to move files will sever all connection between the downloadPath and the file on disk. The link in the download list may no longer point to the correct location on disk

Recommedation:
  • Extract the files directly to the 'complete' folder. (Can be configured in Settings > Archive Extractor)
  • Use the first script in this thread, to move the downloaded files. (Any files in the folder belonging to other packages will continue to remain there.)
Reply With Quote
  #7  
Old 10.12.2024, 13:16
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
The script uses a package object method to 'set' the download folder. It will update the new path only to the links belonging to that package and moves the files correspondng to those links, to the new location. Thus, the connection between the download link and file on disk will be preserved. It will not be aware of any othe files in that folder, belonging to a different package or copied or extracted into it manually or otherwise, and hence they will not be moved.
Thanks, that explains it, but I didn't test the case where there are files from different packages in the same folder, so I don't know how it would behave.

Quote:
Extracted files would still not be moved.
Couldn't the "Archive extraction finished" trigger be used to deal with this, extract first in place, and then move ?

Quote:
That was just for you to check if it works as intended. "moveTo" can be used to replace "setFolder" method in the original script.
I see.

Quote:
It would not be wise to 'set' the new path while extraction is active. So, the script uses 'jdownloader started' trigger, at which point extraction presumably will have been completed. A better option is to create a "toolbar button pressed" and manually run the script by clicking the button.
Thanks. I'm really hoping for something automatic. Manually restarting JD2 isn't my favorite option, but perhaps a script could perform that action periodically ?

I do however see a slight a problem with doing extraction after move. I would prefer the move to be atomic, so that I can subsequently safely perform manual actions on anything under Complete, such as move, delete, etc. without running the risk of having extraction accidentally fail, due to not being aware of it running in any given subfolder. It's a similar problem for the move/copy operation. My preferred way would be to extracted everything in-place in the JDownloader directory, then just move/rename the directory, which works atomically under Windows if it's on the same drive.
However, I think I can work around this by checking the last modified date on any folders in the Complete directory before performing any further move/delete manually.

Quote:
Point to note: "moveTo" is a filePath object method, when used to move files will sever all connection between the downloadPath and the file on disk. The link in the download list may no longer point to the correct location on disk
Would it be OK to use the setting that automatically removes finished downloads in this case - say "when package is ready" ? Or will that cause problems for the move operation after extraction and restart ?

Quote:
Recommedation:[*]Extract the files directly to the 'complete' folder. (Can be configured in Settings > Archive Extractor)
Could you please be more specific as to how I should configure it ?
Would D:\Downloads\Complete\<jd:packagename> be OK for the destination ?

Quote:
[*]Use the first script in this thread, to move the downloaded files. (Any files in the folder belonging to other packages will continue to remain there.)

The very first script in this thread was a no-op for me. Which one did you mean I should use ?

Thanks
Reply With Quote
  #8  
Old 10.12.2024, 13:18
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by Jiaz View Post
You manually move files somewhere else without JDownloader *being aware* of this. It looks at old location
for part files for extraction and other stuff. That's why the scripts should only move finished non archive files
or wait for extraction to finish and then move the extracted files.
OK. So, is there a better way to run the script only once extraction has completed, if any ?

Thanks.
Reply With Quote
  #9  
Old 10.12.2024, 13:20
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,742
Default

@mgpai: see here for desired behaviour, https://board.jdownloader.org/showpo...22&postcount=5
__________________
JD-Dev & Server-Admin
Reply With Quote
  #10  
Old 10.12.2024, 15:06
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

  • Do the packages contain only archives?
  • Do you want to keep the links in the downloadlist after they are downloads/extiracted/moved?
Reply With Quote
  #11  
Old 10.12.2024, 16:26
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 73,827
Default

Correct me if I'm wrong but at least for packages with only archives && when auto extract is enabled, you could use a Packagizer rule instead of a script or alternatively just define a custom global extraction path.
__________________
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
  #12  
Old 10.12.2024, 16:34
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by pspzockerscene View Post
Correct me if I'm wrong but at least for packages with only archives && when auto extract is enabled, you could use a Packagizer rule instead of a script or ...
Yes, if the destination folder is static or can be generated with packagizer variables. Can also be used if the package contains non-arhives, but then only extracted files will be moved.

Quote:
Originally Posted by pspzockerscene View Post
...alternatively just define a custom global extraction path.
Best solution, suggested in one of the posts above.
Reply With Quote
  #13  
Old 10.12.2024, 16:41
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 73,827
Default

Quote:
Originally Posted by mgpai View Post
Can also be used if the package contains non-arhives, but then only extracted files will be moved.
Yap.
This is a huge design flaw which a lot of users have asked us to properly implement.

It looks like the use case "move finished downloads to another place than the one they were initially downloaded to" is something that a lot of users want.
__________________
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
  #14  
Old 10.12.2024, 16:50
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
  • Do the packages contain only archives?
  • Do you want to keep the links in the downloadlist after they are downloads/extiracted/moved?
No to both.
Reply With Quote
  #15  
Old 10.12.2024, 17:41
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Script:
Code:
/*
    change download folder
    trigger : interval (set interval in ms as desired, e.g. 3600000 for 1 hour)
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished && !package.archives.length) {
        var curFolder = package.downloadFolder
        var newFolder = curFolder.replace("\\jdownloader\\", "\\complete\\");

        if (curFolder != newFolder) {
            package.downloadFolder = newFolder
            callAPI("downloadsV2", "removeLinks", [], [package.UUID]);
        }
    }
})

Archive extractor settings:


Workflow:
  • archive files will be extracted
  • if extracted file exists in the destination fodler it will be renamed
  • archive files will be removed
  • archive links will be removed from download list
  • script will run on interval and check if package does not contain any archives (wait till extraction process is finished)
  • new downloadFolder will be set (non-archive files will be moved)
  • package will be removed from downloadList

Please try on test install first.

Last edited by mgpai; 11.12.2024 at 08:16. Reason: Updated script
Reply With Quote
  #16  
Old 11.12.2024, 03:30
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Thank you ! This seems to be working, at least initially. I'll report if I find any issues.
Reply With Quote
  #17  
Old 11.12.2024, 04:08
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by rabidman View Post
Thank you ! This seems to be working, at least initially. I'll report if I find any issues.
OK, I spoke too soon. Only two packages were moved. I believe both were archives and extracted. The vast majority of the packages are not archived, and are not getting moved.
Reply With Quote
  #18  
Old 11.12.2024, 06:29
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Should be working fine:



Please note, while the archives will be removed immediately, the non-archive files will be removed only when the eventscript is triggered after that, which will depend on the interval you set in the script.
Reply With Quote
  #19  
Old 11.12.2024, 07:27
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
Should be working fine:



Please note, while the archives will be removed immediately, the non-archive files will be removed only when the eventscript is triggered after that, which will depend on the interval you set in the script.
I set the interval to 5 minutes. The non-archive files are really not getting moved.
Reply With Quote
  #20  
Old 11.12.2024, 07:57
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Check if the string used in replace function matches exactly to the one on disk. It is case-sensitve

Edit: The script has been updated to remove the package only if the replace was successful.

Last edited by mgpai; 11.12.2024 at 08:48.
Reply With Quote
  #21  
Old 11.12.2024, 09:24
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Quote:
Originally Posted by mgpai View Post
Check if the string used in replace function matches exactly to the one on disk. It is case-sensitve

Edit: The script has been updated to remove the package only if the replace was successful.
Thanks. This is what I'm using :

Code:
/*
    change download folder
    trigger : interval (set interval in ms as desired, e.g. 3600000 for 1 hour)
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished && !package.archives.length) {
        var curFolder = package.downloadFolder
        var newFolder = curFolder.replace("D:\\Downloads\\JDownloader\\", "D:\\Downloads\\Complete\\");

        if (curFolder != newFolder) {
            package.downloadFolder = newFolder
            callAPI("downloadsV2", "removeLinks", [], [package.UUID]);
        }
    }
})
My file system is NTFS on Windows, so the string should not be case-sensitive. Nevertheless, the case I used for these directory names is the same as shown by Windows explorer.

Unfortunately, the previously downloaded packages not containing archives are still not getting moved, even after a manual test run.
Reply With Quote
  #22  
Old 11.12.2024, 09:34
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
My file system is NTFS on Windows, so the string should not be case-sensitive. Nevertheless, the case I used for these directory names is the same as shown by Windows explorer.
While the file system is not case-sensitive, the replace function is. But since you confirm it is being replaced I cannot think of any reason why new path is not set.

Quote:
Originally Posted by rabidman View Post
Unfortunately, the previously downloaded packages not containing archives are still not getting moved, even after a manual test run.
Maybe @Jiaz or @psp can shed some light as to why it is working for me and not for you.
Reply With Quote
  #23  
Old 11.12.2024, 10:43
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
While the file system is not case-sensitive, the replace function is. But since you confirm it is being replaced I cannot think of any reason why new path is not set.
It worked earlier for 2 packages that had archives. It hasn't worked since., but I don't think I have any other extractible packages downloaded or pending. If you are able to give me a link to one, I could retest it.

Thanks.
Reply With Quote
  #24  
Old 11.12.2024, 10:55
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
If you are able to give me a link to one, I could retest it.
Here is the downloadlist I used to test the script. Just drag 'n' drop it to the download tab.

Code:
file.io/q1pSdqTxMtJG

Edit: move will fail if the file exists in the destination fodler.

Last edited by mgpai; 11.12.2024 at 10:58.
Reply With Quote
  #25  
Old 11.12.2024, 12:52
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Quote:
Originally Posted by mgpai View Post
Here is the downloadlist I used to test the script. Just drag 'n' drop it to the download tab.

Code:
file.io/q1pSdqTxMtJG

Edit: move will fail if the file exists in the destination fodler.
Thanks.

Should I drag the ZIP file, or its contents ?

The former results in an error : "Processing the following container failed for unknown reasons : D:\Downloads\downloadlist.zip"

The later appears to have no effect.
Reply With Quote
  #26  
Old 11.12.2024, 13:05
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
Hi,
Should I drag the ZIP file, or its contents ?

The former results in an error : "Processing the following container failed for unknown reasons : D:\Downloads\downloadlist.zip"

The later appears to have no effect.
Sorry. I posted the wrong link. Use this:
Code:
file.io/W2dGFbdzLuEP

Download it to disk and dran 'n' drop to downloads tab. JD will prompt to import 7 links click yes.

Alternatively, since the links are removed from ths list, the files can be moved independently, rather than set the package folder. Here too the move will fail if the file exists in the destination folder. Links will be removed from the list, only if the move is successful.

Code:
/*
    move non-archive links
    trigger : interval (set as desired)
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        package.downloadLinks.forEach(function(link) {
            if (!link.archive) {
                var curPath = link.downloadPath;
                var newPath = getPath(curPath.replace("\\jdownloader\\", "\\complete\\")).parent;
                var moved = getPath(curPath).moveTo(newPath);

                if (moved) {
                    link.remove();
                }
            }
        })
    }
})
Reply With Quote
  #27  
Old 11.12.2024, 13:30
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Quote:
Originally Posted by mgpai View Post
Sorry. I posted the wrong link. Use this:
Code:
file.io/W2dGFbdzLuEP

Download it to disk and dran 'n' drop to downloads tab. JD will prompt to import 7 links click yes.

Alternatively, since the links are removed from ths list, the files can be moved independently, rather than set the package folder. Here too the move will fail if the file exists in the destination folder. Links will be removed from the list, only if the move is successful.

Code:
/*
    move non-archive links
    trigger : interval (set as desired)
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        package.downloadLinks.forEach(function(link) {
            if (!link.archive) {
                var curPath = link.downloadPath;
                var newPath = getPath(curPath.replace("\\jdownloader\\", "\\complete\\")).parent;
                var moved = getPath(curPath).moveTo(newPath);

                if (moved) {
                    link.remove();
                }
            }
        })
    }
})
Thanks. Sadly, the result is the same. The folders for the extracted files got moved. The file-*.txt files did not get
moved. The links for these files got removed from the Downloads list, though.

Perhaps you could compare the before & after path to see if they truly got moved, rather than just checking for non-NULL string.

I see that there is a _MACOSX folder in one of your packages. I'm guessing you are using Mac OS X. I'm using Windows 11. Perhaps there is some sort of platform-specific bug here.

Last edited by rabidman; 11.12.2024 at 13:33.
Reply With Quote
  #28  
Old 11.12.2024, 14:20
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
Perhaps you could compare the before & after path to see if they truly got moved, rather than just checking for non-NULL string.
Can be compared, but not necesssary when using moveTo. The result will be True or False.

Quote:
Originally Posted by rabidman View Post
I see that there is a _MACOSX folder in one of your packages. I'm guessing you are using Mac OS X. I'm using Windows 11. Perhaps there is some sort of platform-specific bug here.
I too am on windows platform That folder was extracted from one of the sample fils. Most likely the files from it were moved and empty folder was left behind.

Try a script which uses native commands:
Code:
/*
    move non-archive links
    trigger : interval (set as disired)
*/

getAllFilePackages().forEach(function(package) {
    if (package.finished) {
        package.downloadLinks.forEach(function(link) {
            if (!link.archive) {
                var src = link.downloadPath;
                var dest = getPath(src.replace("\\jdownloader\\", "\\complete\\")).parent;

                dest.mkdirs();

                callAsync(function(exitCode, stdOut, errOut) {
                    stdOut && alert(stdOut);
                    errOut && alert(errOut);
                }, "cmd", "/c", "move", "/-Y", src, dest);
            }
        })
    }
})
Reply With Quote
  #29  
Old 12.12.2024, 07:11
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Hi,

Your latest script still did not work, unfortunately. It think we were going around in circles, so I added some logging after the getPath call.

Quote:
var dest = getPath(src.replace("D:\\Downloads\\JDownloader", "D:\\Downloads\\Complete")).parent;
log("After getPath");
log("Destination is " + dest);
The result was this :

Quote:
--ID:2828TS:1733978490404-12/11/24, 8:41:30 PM - [org.jdownloader.extensions.eventscripter.sandboxobjects.ScriptEnvironment(log)] -> After getPath
--ID:2828TS:1733978490404-12/11/24, 8:41:30 PM - [org.jdownloader.extensions.eventscripter.sandboxobjects.ScriptEnvironment(log)] -> Destination is D:\downloads\jdownloader\myPackage
Ie, the destination is the same as the source, which is why nothing is getting moved.

I see above that the target directory is the wrong one. It points to the source directory, like because the src.replace call was a no-op. And it is logged with different case than it does in Windows Explorer. Explorer shows it as D:\Downloads\JDownloader . But dest is logged as D:\downloads\jdownloader . Ie. the drive letter in uppercase, but the directory names are in lowercase. That is quite strange, and I could never have guessed that's how it it worked.

So, I modified the getPath call as follows :

Code:
var dest = getPath(src.replace("D:\\downloads\\jdownloader\\", "D:\\Downloads\\Complete\\")).parent;
And this time, it worked ! The non-archive file-*.txt files were moved, finally.

I'm guessing your directory names don't have any uppercase letters, and that's why the script worked for you, but not for me.

I have a few remarks here :
a) link.downloadPath probably shouldn't have an upper-case drive letter, and lowercase directory names
b) a case-sensitive function like replace probably isn't the right one to use for substitution on a case-insensitive file system path name

A few issues remain :

1) When running the script again, it tries to move the same non-archive files again. I know this because the pop-ups continue to show up every time the script runs. This is presumably because these moved files need to be removed from the Downloads list. I can of course just remove the pop-ups, but the script should be cleaned up too.

2) For archived files, the source files do not get deleted. That's an issue with the Archive extractor rather than the script, though. It wastes disk space, and requires manual cleanup. Archives should be deleted after extraction.

3) The source directory structure does not get deleted, whether for archive or non-archive files.

4) The move and extraction process is non-atomic, with some files being moved, some extracted to the destination, and so on. I feel like :
a) everything should be moved/extracted to a temporary subdirectory on the same file system as the target
b) once that's complete, move that temporary subdirectory to the target directory
c) delete all source archive files & paths
That's more of a "want" than a "must", though. And it isn't trivial to achieve. I'm not sure if it's possible to do in a script or not. But I hope we can get there some day, still. In the meantime, the current working script will do ! Thanks again.
Reply With Quote
  #30  
Old 12.12.2024, 07:26
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Spoke too soon. Standalone files, ie. in the multiple virtual "Various files" packages, do not get moved.

Last edited by rabidman; 12.12.2024 at 10:44.
Reply With Quote
  #31  
Old 12.12.2024, 11:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

b) can use regex:
Code:
var newPath = link.downloadPath.replace(/\\JDownloader\\/i,"\\complete\\");
1)
Code:
if(moved){
    link.remove();
}


2) There is a setting to delete archives after (check my screenshot above) If they are not being deleted, report here so that the devs. can look into it.

3)
Code:
if (moved) {
    getPath(srcPath).delete();
}
4)
a) You can insert timepstamp to the save path before package name and get unique folder.
b & c) When the package is finished and archive files are not present (extracted/moved/deleted) in the package, move the entire folder. (no empty folders will be left behind).
Reply With Quote
  #32  
Old 12.12.2024, 11:47
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
Spoke too soon. Standalone files, ie. in the multiple virtual "Various files" packages, do not get moved.
Found out why?

Since the archive part is handled by the archive extractor, the script will have only to deal with non-archive files. Also, since you are using a pattern to save and move files, it is also possible to just move the non-archive files to the new location using a pattern.

Code:
/*
    move finished file
    trigger : download stopped
*/

if (link.finished && !link.archive) {
    var src = getPath(link.downloadPath);
    var packageName = link.package.name;
    var dest = getPath("d:/downloads/complete/" + packageName);
    var moved = src.moveTo(dest);

    if (moved) {
        link.remove();
        getPath(src.parent).delete();
    } else {
        alert(src + " was not moved.");
    }
}
Edit: added !link.archive check.

Last edited by mgpai; 12.12.2024 at 12:20.
Reply With Quote
  #33  
Old 13.12.2024, 15:07
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
Found out why?

Since the archive part is handled by the archive extractor, the script will have only to deal with non-archive files. Also, since you are using a pattern to save and move files, it is also possible to just move the non-archive files to the new location using a pattern.

Code:
/*
    move finished file
    trigger : download stopped
*/

if (link.finished && !link.archive) {
    var src = getPath(link.downloadPath);
    var packageName = link.package.name;
    var dest = getPath("d:/downloads/complete/" + packageName);
    var moved = src.moveTo(dest);

    if (moved) {
        link.remove();
        getPath(src.parent).delete();
    } else {
        alert(src + " was not moved.");
    }
}
Edit: added !link.archive check.
Thanks ! It seems to be working well so far. I'm going to do more testing, but this is looking good.
Reply With Quote
  #34  
Old 13.12.2024, 15:14
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,656
Default

Quote:
Originally Posted by rabidman View Post
Thanks ! It seems to be working well so far. I'm going to do more testing, but this is looking good.
If necessary, additanol alerts when move fails can be added. e.g 'src file does not exist' and 'dest file exists".
Reply With Quote
  #35  
Old 19.12.2024, 18:59
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

Quote:
Originally Posted by mgpai View Post
If necessary, additanol alerts when move fails can be added. e.g 'src file does not exist' and 'dest file exists".
I haven't seen the first case, but I believe I have seen the later. Sometimes, the same file exists in multiple packages of the same name. Thus, the move for the 2nd+ fails.

I would prefer fewer pop-ups, if possible. Ideally, comparing the files, and just deleting the source if it's identical to the destination, with an alert only if it's different, or the move fails.
Reply With Quote
  #36  
Old 20.12.2024, 11:08
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 73,827
Default

Instead of popups you could also just write all possible alerts into one text-file.
If in the end, you got that error text-file left in your folder, you can look into it without unnerving alerts.
__________________
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
  #37  
Old 19.01.2025, 04:13
rabidman rabidman is offline
DSL Light User
 
Join Date: Dec 2024
Location: San Jose, California
Posts: 31
Default

I have gotten numerous problems with this script.

1. thousands upon thousands of files that did not get moved.
That is a lot of popups to dismiss. I had ChatGPT write an Autohotkey script to dismiss them. But this is not a solution. I'm not sure of the root cause, or how to solve the problem.

2. unwanted renaming of files and directories
I have noticed that files and directories that are downloaded have very different names in the target "Complete" directory. I don't understand why that is. The script should move files, but should not rename them, or rename the directory structure.

3. move is not atomic at the package level
I really want the package to be moved all at once when it is complete. I do not want to move one file at a time. This is so that I can manually move the folders to their final destination, without having to manually check in JDownloader whether there are still files pending download for that package. This is extremely tedious when there are dozens or even hundreds of folders, some of which can take days, weeks or even months to download due to hoster bandwidth limitations. Ie. there is never a time when my download list is empty, and I can confidently move anything out of Complete without any risk of race condition.

4. problems with DLC
I ran into a serious problem with JDownloader. It would no longer exit. It had to be killed from Windows Task manager every time. I saved my settings and my downloads into a DLC. When resuming downloads, the script got the following error stack :

net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "name" from null (#8)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3935)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3919)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3944)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3960)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3971)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1519)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1243)
at script(:8)
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(JSHtmlUnitP ermissionRestricter.java:134)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3286)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
at net.sourceforge.htmlunit.corejs.javascript.Context.evaluateString(Context.java:1361)
at org.jdownloader.extensions.eventscripter.ScriptThread.evalUNtrusted(ScriptThread.java:346)
at org.jdownloader.extensions.eventscripter.ScriptThread.executeScipt(ScriptThread.java:194)
at org.jdownloader.extensions.eventscripter.ScriptThread.run(ScriptThread.java:174)

If I add new downloads with a URL, I don't get this error stack.

Last edited by rabidman; 19.01.2025 at 05:28.
Reply With Quote
  #38  
Old 20.01.2025, 03:07
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,742
Default

@rabidman:
1.) instead of spending time to write autohotkey to auto dismiss the alerts, you should better spend time and find out why moving fails that often for you.
Are source and destination on same drive/location? maybe destination file already exists?
you should ask for help to modify script to 1.) retry and 2.) provide better logs on why it might have failed to move

2.) what script exactly are you using? the one shown in post 33 does not have any rename at all, so the different filename must be already in list before

3.) requires a total different sort of script as it has to wait for all links to reach sort of finished/final state and wait for any extractions to finish
Why not leave files at place and auto remove finished/downloaded files from list and setup a script that starts once the package is removed (no more links in it) and then start moving the files? That would be much easier to maintain as the package in JDownloader will become smaller and smaller while downloading and either its empty = finished = can move or some errors that you have to check first

4.) I've answered in your other thread.


Quote:
Originally Posted by rabidman View Post
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "name" from null (#8)
Quote:
var packageName = link.package.name;
link.package is only available while the link is in list. when you have enabled auto remove from list, then you have to enable synchronous execution of the script, else it may easily happen that at time of script execution, the entry is no longer in list and then the information is no longer available.
That would also explain the
Quote:
1. thousands upon thousands of files that did not get moved.
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 20.01.2025 at 03:10.
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:13.
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 - 2025, Jelsoft Enterprises Ltd.