JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #2761  
Old 16.02.2024, 17:19
b00rn b00rn is offline
I will play nice!
 
Join Date: Feb 2024
Posts: 3
Question Ordner löschen nach Packetverwalter Regel

Ich könnte Unterstützung für ein script brauchen welches mir Ordner löscht nachdem die enthalten Videodatei(en) verschoben wurde.

Mein Ziel wäre: Video-Dateien (Filme/Serien) werden nach dem DL & entpacken in ein Verzeichnis meiner Wahl verschoben, und alles andere wird gelöscht
Anmerkung: die heruntergeladenen Pakete werden natürlich ohnedies nach dem entpacken gelöscht auf Basis der Standardeinstellungen in JD.

Bisher habe ich es zustande gebracht dass eine Paketverwalter Regel "wenn Video dann verschiebe" eine Teil der Aufgabe erledigt.

Derzeitige Situation (möglicherweise zu "umständlich"?): Es wird auf HD1 heruntergeladen und nach HD2 entpackt. Auf HD2 befindet sich dann ein Ordner mit der/den Videodatei(en) die mit der aktuellen Regel auch korrekt auf HD3 verschoben werden. Aber der Ordner ist noch da, meist mit einer .nfo Datei und tw. auch mit einer .txt und/oder .url Datei, und der ganze Ordner soll eben in solch einem Fall (wenn Video) gelöscht werden.

ABER, dies soll nur dann so wie beschrieben passieren, wenn es sich um "Video-downloads" handelt die vorher entpackt werden müssen, da ich hin und wieder zB auch Programm Pakete downloade soll dieser ganze Vorgang in solch einem Fall natürlich nicht passieren...

An was ich bisher noch nicht gedacht habe ist ob ich evtl. anhand bestimmter Kriterien die Dateien auch gleich in spezielle Ordner verschieben lassen kann zB Ordner "Filme" oder "Serien"? ZB haben Serienfolgen im Dateinamen immer ein zB s01e03 enthalten, vielleicht gibt es auch sinnvollere Kriterien?

Bin für jede Unterstützung dankbar!
Reply With Quote
  #2762  
Old 21.02.2024, 14:34
mostafatefa2009 mostafatefa2009 is offline
JD Alpha
 
Join Date: Feb 2024
Posts: 20
Default

Hello Team,

Can you make a script that will check all files in the LinkGrabber, then compare (Name+Size) and delete the duplicate files from LinkGrabber?

Thank you in advance.

Last edited by mostafatefa2009; 21.02.2024 at 15:01.
Reply With Quote
  #2763  
Old 25.02.2024, 12:30
JazzooRock JazzooRock is offline
Baby Loader
 
Join Date: Dec 2023
Posts: 8
Default

Quote:
Originally Posted by JazzooRock View Post
Hello everyone !
I hope you have a nice evening
I need your help...
Someone can make a simple script for me ?

In the linkgrabber tab, i have a package containing 55000+ videos files, each with a structure filename like "PREFIX_SUFFIXp.mp4" where, by chance, the suffixe is the resolution of the videos.

For exemple :

35478_720p.mp4
35478_1080p.mp4
68_460p.mp4
423_240p.mp4
423_360p.mp4
423_1080p.mp4
etc...

The problem is that most files have the same prefix and I would like to keep only the duplicates that have the highest resolution in their name suffixes so i don't need to download all video variants...
In my exemple, I would like to keep "35478_1080p.mp4", "68_460p.mp4", "423_1080p.mp4".

I hope i'm clear ^^
Thank you in advance.
Merry Christmas all !

P.S. I'm asking that because there is no plugin available for the website that I want to crawl.
Hello !
Obviously no one has the time to help or maybe my request is ridiculous so I won't bother anymore.
Thanks anyway.
Bye bye.
Reply With Quote
  #2764  
Old 27.02.2024, 07:33
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default

Quote:
Originally Posted by JazzooRock View Post
Hello !
Obviously no one has the time to help or maybe my request is ridiculous so I won't bother anymore.
Thanks anyway.
Bye bye.
This is slightly out of scope for the Event Scripter; it may be possible to accomplish, but the Event Scripter is used more for independent events (e.g., perform a task on any finished package/link).

I would instead suggest adding the links with the LinkGrabber and then extracting the JSON structure for the LinkGrabber table. Then, using a scripting language (Python, R, etc.), do a regex extraction for the PREFIX (video title?) and SUFFIX (resolution), and, grouping by PREFIX, determine what is the maximal SUFFIX, and pick the correspond URL. Then, remove the links from the LinkGrabber, and only add those picked URLs.
Reply With Quote
  #2765  
Old 28.02.2024, 01:48
JazzooRock JazzooRock is offline
Baby Loader
 
Join Date: Dec 2023
Posts: 8
Default

Quote:
Originally Posted by blank View Post
This is slightly out of scope for the Event Scripter; it may be possible to accomplish, but the Event Scripter is used more for independent events (e.g., perform a task on any finished package/link).

I would instead suggest adding the links with the LinkGrabber and then extracting the JSON structure for the LinkGrabber table. Then, using a scripting language (Python, R, etc.), do a regex extraction for the PREFIX (video title?) and SUFFIX (resolution), and, grouping by PREFIX, determine what is the maximal SUFFIX, and pick the correspond URL. Then, remove the links from the LinkGrabber, and only add those picked URLs.
Hello and thank you for the answer.

I asked for help because, despite the apparent simplicity of being able to use the EventScripter language to execute this operation directly in the LinkGrabber, I felt incapable of doing it alone.
So, even if I managed to extract the linkgrabber result to try to create the same kind of script outside of Jdownloader, I won't be sure I'll succeed either.

But by extracting the result from the linkgrabber, it would allow me to obtain the real links hidden behind a video with several different qualities so it would be a good start. (Hoping the Json file includes this kind of information of course).

So..., all I have to do is figure out how to extract the linkgrabber result to a Json file or even a simple text file.
Do you have an idea ? I can't find any information on the internet.

Thanks in advance.
Reply With Quote
  #2766  
Old 28.02.2024, 08:53
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default

Quote:
Originally Posted by JazzooRock View Post
Hello and thank you for the answer.

I asked for help because, despite the apparent simplicity of being able to use the EventScripter language to execute this operation directly in the LinkGrabber, I felt incapable of doing it alone.
So, even if I managed to extract the linkgrabber result to try to create the same kind of script outside of Jdownloader, I won't be sure I'll succeed either.

But by extracting the result from the linkgrabber, it would allow me to obtain the real links hidden behind a video with several different qualities so it would be a good start. (Hoping the Json file includes this kind of information of course).

So..., all I have to do is figure out how to extract the linkgrabber result to a Json file or even a simple text file.
Do you have an idea ? I can't find any information on the internet.

Thanks in advance.
No problem. This is actually not as simple as one might think, so it is understandable to have some difficulty. Someone else had a similar request here, and Jiaz, the JD manager, said it would not be possible using Filter/Packagizer and recommended filtering the links by oneself (though they did not bring up the Event Scripter). The "true" solution would be to write your own plugin, but that would not be straightforward without Java experience.

The LinkGrabber json can be found inside a zip at "cfg/linkcollector###.zip" below the JDownloader directory, where ### is a number. It might depend on your system/environment.

Are you comfortable in any scripting languages? It may be easiest to work in whatever you are already comfortable with as long as it has JSON support.

1. Retrieve the linkcollector zip file and extract.
2. Take the extracted JSON file(s) and read into a data structure where you can do group-by and select operations (will depend on language).
3. For each extracted title, determine the PREFIX and SUFFIX by regex (e.g., "([^_]+)_([^_]+)p").
4. Grouping by PREFIX, determine the maximal SUFFIX. Select the corresponding URL.
5. Take all of those selected URLs and put back into an empty LinkGrabber table.

(If you need more help, it might be best to move this discussion to another thread to avoid polluting the thread with non-Event Scripter scripts.)
Reply With Quote
  #2767  
Old 28.02.2024, 10:55
mostafatefa2009 mostafatefa2009 is offline
JD Alpha
 
Join Date: Feb 2024
Posts: 20
Default

Quote:
Originally Posted by mostafatefa2009 View Post
Hello Team,

Can you make a script that will check all files in the LinkGrabber, then compare (Name+Size) and delete the duplicate files from LinkGrabber?

Thank you in advance.
Any help here would be appreciated. I don't know much about Eventscripter and there is no thorough documentation available


HTML Code:
// Define function to delete duplicate files
function deleteDuplicateFiles() {
    var links = linkcollector.getDownloadLinks();

    // Create an object to store file names and their occurrences
    var fileOccurrences = {};

    // Iterate through the links and count occurrences of each file name
    for (var i = 0; i < links.length; i++) {
        var fileName = links[i].getName();

        if (fileOccurrences[fileName]) {
            fileOccurrences[fileName]++;
        } else {
            fileOccurrences[fileName] = 1;
        }
    }

    // Iterate through the links again and delete duplicates
    for (var i = 0; i < links.length; i++) {
        var fileName = links[i].getName();

        // Delete duplicate files (keep only one copy)
        if (fileOccurrences[fileName] > 1) {
            fileOccurrences[fileName]--;
            linkcollector.removePackage(links[i].getPackage());
            i--; // Adjust index to account for removed link
        }
    }
}

// Register the function to be called on linkgrabber refresh
linkgrabber.onRefresh(function() {
    // Delay the execution to ensure that the linkgrabber is fully refreshed
    setTimeout(deleteDuplicateFiles, 1000);
});
Reply With Quote
  #2768  
Old 28.02.2024, 12:02
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by JazzooRock View Post
... I would like to keep only the duplicates that have the highest resolution in their name suffixes ...
Code:
/*
    remove lower resolution
    trigger : linkgrabber context menu button pressed
    support : https://board.jdownloader.org/sendmessage.php?do=mailmember&u=73437
*/

if (name == "cleanup") {

    var package = lgSelection.contextPackage;
    var add = function(name, res, str) {
        remove.push(name.replace(res, str));
    }
    var remove = [];

    package.downloadLinks.forEach(function(link) {
        var name = link.name;
        var res = "1080p";

        if (name.indexOf(res) > -1) {
            add(name, res, "720p");
            add(name, res, "480p");
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "720p";

        if (name.indexOf(res) > -1) {
            add(name, res, "480p");
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "480p"

        if (name.indexOf(res) > -1) {
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "360p"

        if (name.indexOf(res) > -1) {
            add(name, res, "240p");
        }
    })

    package.downloadLinks.forEach(function(link) {
        if (remove.indexOf(link.name) > -1) {
            link.enabled = false;
            //link.remove();
        }
    })
}

Last edited by mgpai; 28.02.2024 at 13:35. Reason: Removed reduntant code
Reply With Quote
  #2769  
Old 28.02.2024, 13:28
mostafatefa2009 mostafatefa2009 is offline
JD Alpha
 
Join Date: Feb 2024
Posts: 20
Default

Quote:
Originally Posted by mgpai View Post
...
mgpai Kindly help with my request

Quote:
Originally Posted by mostafatefa2009 View Post
Hello Team,

Can you make a script that will check all files in the LinkGrabber, then compare (Name+Size) and delete the duplicate files from LinkGrabber?
Thank you in advance.
Reply With Quote
  #2770  
Old 28.02.2024, 13:54
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by mostafatefa2009 View Post
... script that will check all files in the LinkGrabber, then compare (Name+Size) and delete the duplicate files from LinkGrabber... .
Code:
/*
    remove files with matching name and size
    trigger : click 'test run' button in the top panel
    suopport: https://board.jdownloader.org/sendmessage.php?do=mailmember&u=73437
*/

var keys = [];

getAllCrawledLinks().forEach(function(link) {
    var size = link.bytesTotal;

    if (size > 0) {
        var key = link.name + size;

        if (keys.indexOf(key) == -1) {
            keys.push(key);
        } else {
            link.enabled = false;
            //link.remove;
        }
    }
})
Reply With Quote
  #2771  
Old 28.02.2024, 15:16
mostafatefa2009 mostafatefa2009 is offline
JD Alpha
 
Join Date: Feb 2024
Posts: 20
Default

Quote:
Originally Posted by mgpai View Post
Code:
var keys = [];

getAllCrawledLinks().forEach(function(link) {
    var size = link.bytesTotal;

    if (size > 0) {
        var key = link.name + size;

        if (keys.indexOf(key) == -1) {
            keys.push(key);
        } else {
            link.enabled = false;
            //link.remove;
        }
    }
})
Awesome! That really worked! Can you make it remove the duplicates instead?

Last edited by mostafatefa2009; 28.02.2024 at 15:28.
Reply With Quote
  #2772  
Old 28.02.2024, 16:44
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by mostafatefa2009 View Post
Awesome! That really worked! Can you make it remove the duplicates instead?
Already in the script, but disabled by default. Google how to comment/uncomment code block in javascript.
Reply With Quote
  #2773  
Old 28.02.2024, 16:46
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 71,260
Default

@mostafatefa2009
The EventScripter feature is made to be used by users.
It is super nice that mgpai is helping out here but ultimately you need to put time into this topic to use/understand existing scripts and create your own scripts.
__________________
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?

-----------------------------------

On Vacation / Im Urlaub
Start: 2024-02-08
End: TBA

Reply With Quote
  #2774  
Old 28.02.2024, 20:05
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default Update automatisch installieren mit Neustart, dann den Reconnect?

Gibt es eine Möglichkeit / ein Skript, das JD veranlasst bei einem erhältlichen Update das automatisch zu installieren, bevor er ein Reconnect ausführt, das er auch ohne Update ausführen würde, weil es die Downloads gerade sinnvoll machen?


Also:
Reconnect steht bevor wegen der Downlaods / Einstellungen, voher installieren mit Neustart, dann den Reconnect, danach weiterladen.
__________________
Aktuelles Windows

Last edited by Dockel; 28.02.2024 at 20:12.
Reply With Quote
  #2775  
Old 28.02.2024, 20:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,006
Default

@Dockel: Mittels dem "Vor einem Reconnect" Trigger und dort dann auf Update prüfen und diese initiieren und neustarten. Bitte dazu im entsprechenden Thread um Rat/Hilfe fragen, siehe https://board.jdownloader.org/showthread.php?t=70525
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2776  
Old 28.02.2024, 20:49
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default Install update automatically with restart, then reconnect?

Is there a way / a script that causes JD to automatically install an available update before executing a reconnect, which it would also do without an update because of the downloads progression?

So:
Reconnect is imminent because of the downloads / settings, first install with restart, then reconnect, then continue downloading.

https://board.jdownloader.org/showth...153#post531153
__________________
Aktuelles Windows
Reply With Quote
  #2777  
Old 29.02.2024, 04:13
JazzooRock JazzooRock is offline
Baby Loader
 
Join Date: Dec 2023
Posts: 8
Default

Quote:
Originally Posted by blank View Post
No problem. This is actually not as simple as one might think, so it is understandable to have some difficulty. Someone else had a similar request **External links are only visible to Support Staff**..., and Jiaz, the JD manager, said it would not be possible using Filter/Packagizer and recommended filtering the links by oneself (though they did not bring up the Event Scripter). The "true" solution would be to write your own plugin, but that would not be straightforward without Java experience.

The LinkGrabber json can be found inside a zip at "cfg/linkcollector###.zip" below the JDownloader directory, where ### is a number. It might depend on your system/environment.

Are you comfortable in any scripting languages? It may be easiest to work in whatever you are already comfortable with as long as it has JSON support.

1. Retrieve the linkcollector zip file and extract.
2. Take the extracted JSON file(s) and read into a data structure where you can do group-by and select operations (will depend on language).
3. For each extracted title, determine the PREFIX and SUFFIX by regex (e.g., "([^_]+)_([^_]+)p").
4. Grouping by PREFIX, determine the maximal SUFFIX. Select the corresponding URL.
5. Take all of those selected URLs and put back into an empty LinkGrabber table.

(If you need more help, it might be best to move this discussion to another thread to avoid polluting the thread with non-Event Scripter scripts.)
I see that mgpai created the script I needed but nevertheless a big thank you to you for taking the time to answer me and for giving me an interesting solution which could be useful to me in the future for something else ^^
Reply With Quote
  #2778  
Old 29.02.2024, 04:36
JazzooRock JazzooRock is offline
Baby Loader
 
Join Date: Dec 2023
Posts: 8
Default

Quote:
Originally Posted by mgpai View Post
Code:
/*
    remove lower resolution
    trigger : linkgrabber context menu button pressed
    support : https://board.jdownloader.org/sendmessage.php?do=mailmember&u=73437
*/

if (name == "cleanup") {

    var package = lgSelection.contextPackage;
    var add = function(name, res, str) {
        remove.push(name.replace(res, str));
    }
    var remove = [];

    package.downloadLinks.forEach(function(link) {
        var name = link.name;
        var res = "1080p";

        if (name.indexOf(res) > -1) {
            add(name, res, "720p");
            add(name, res, "480p");
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "720p";

        if (name.indexOf(res) > -1) {
            add(name, res, "480p");
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "480p"

        if (name.indexOf(res) > -1) {
            add(name, res, "360p");
            add(name, res, "240p");
        }

        res = "360p"

        if (name.indexOf(res) > -1) {
            add(name, res, "240p");
        }
    })

    package.downloadLinks.forEach(function(link) {
        if (remove.indexOf(link.name) > -1) {
            link.enabled = false;
            //link.remove();
        }
    })
}
Awesome ! Thank you very much mgpai for creating this script and it works perfectly!

I had a little trouble understanding that I had to give the package the name "cleanup" for it to work with this script specifically and the script is so simple that I ended up completely understanding it to the point that I feel ridiculous for not having made a little more effort to create it myself.

It's so simple that I was able to create a version that also works in the download tab! (...because for some reason if I run the download with only the qualities I want, the downloads fail with "file not found" and resetting then checking the online status doesn't change anything. So I have to include all versions retrieved by the linkgrabber and download everything and once the downloads are complete, I use your script to sort, select and delete from the hard drive all unwanted versions.)

Sooo.... Many many thanks for all the help you generously provide to all of us !
And also many thanks to all of the devs & CM behind JD. ^^

Have a nice day !
Reply With Quote
  #2779  
Old 29.02.2024, 11:03
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by JazzooRock View Post
... I had a little trouble understanding that I had to give the package the name "cleanup" for it to work with this script specifically...
Package name can be anything. In the eventscripter panel you have to set the event trigger to "linkgrabber contextmenu button pressed" and then create a 'eventscripter trigger" button in the linkgrabber context menu and replace the default button name with "cleanup". You can then select any package and click the custom button to run the script.
Reply With Quote
  #2780  
Old 29.02.2024, 12:59
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by Dockel View Post
... automatically install an available update before executing a reconnect...
Code:
/*
    update before reconnect
    trigger : before a reconnect
*/

if (callAPI("update", "isUpdateAvailable")) {
    callAPI("update", "restartAndUpdate");
}
Reply With Quote
  #2781  
Old 29.02.2024, 14:38
JazzooRock JazzooRock is offline
Baby Loader
 
Join Date: Dec 2023
Posts: 8
Default

Quote:
Originally Posted by mgpai View Post
Package name can be anything. In the eventscripter panel you have to set the event trigger to "linkgrabber contextmenu button pressed" and then create a 'eventscripter trigger" button in the linkgrabber context menu and replace the default button name with "cleanup". You can then select any package and click the custom button to run the script.
Oops... Yes, it work !
Thank you again mgpai
Reply With Quote
  #2782  
Old 29.02.2024, 15:34
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

Super! Thank you very much for the script!
__________________
Aktuelles Windows
Reply With Quote
  #2783  
Old 29.02.2024, 15:55
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

Something went wrong on the first reconnect:




Can't see the mistake I made.
__________________
Aktuelles Windows
Reply With Quote
  #2784  
Old 29.02.2024, 16:03
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

It seemed as if the script woked on the second reconnect (a message asking permission about the script appeared) And a little later this appears:
__________________
Aktuelles Windows

Last edited by Dockel; 29.02.2024 at 16:05.
Reply With Quote
  #2785  
Old 29.02.2024, 17:25
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by Dockel View Post
... And a little later this appears ...
My guess is internet connection get disconnected (by other script/setting/unknown reason) before the upddate can be downloaded. You can also use the "After a reconnect" trigger.
Reply With Quote
  #2786  
Old 29.02.2024, 19:27
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

I believe, there is no other script doing this, only JD does it. Did I have to deactivate the reconnect option (but then there was no reconnection without an update anymore, I guess).
__________________
Aktuelles Windows
Reply With Quote
  #2787  
Old 01.03.2024, 07:06
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default

Quote:
Originally Posted by JazzooRock View Post
I see that mgpai created the script I needed but nevertheless a big thank you to you for taking the time to answer me and for giving me an interesting solution which could be useful to me in the future for something else ^^
Sounds great, glad you found a solution! Sorry I did not come up with an Event Scripter solution; I hadn't considered that videos normally only come in a few different vertical resolutions. The strategy I suggested mostly is to take into account any positive integer-valued vertical resolution.
Reply With Quote
  #2788  
Old 01.03.2024, 16:16
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by Dockel View Post
I believe, there is no other script doing this, only JD does it. Did I have to deactivate the reconnect option (but then there was no reconnection without an update anymore, I guess).
Reconnect option should not be disabled. If you are repeatedly "No internet connection" message, it would only mean the internet connection was lost. I cannot say for sure why. Maybe, Jiaz can shed some light on it.

In the meanwhile, instead of 'before a rreconect' you can use 'after a reconnect. That should also solve the problem.
Reply With Quote
  #2789  
Old 01.03.2024, 20:56
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

Quote:
it would only mean the internet connection was lost.
So then it is not JD that cuts the connection anyway because of the activated Reconnect option?

Quote:
In the meanwhile, instead of 'before a rreconect' you can use 'after a reconnect. That should also solve the problem.
Yes, I do since yesterday or so, that works. Before the new start / installation a captcha is shown (because the next download is started / resumed) and resumed downloads (without a captcha) might go on. Don't know if there is any drawback by this (besides of being alarmed for the captcha).
__________________
Aktuelles Windows
Reply With Quote
  #2790  
Old 02.03.2024, 01:08
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default

Before downloading or extracting a file whose path matches an existing file, JDownloader will generate a dialog prompt that gives the name of the file and the sizes of the existing and potential new file and then asks the user if they would like to overwrite, skip, or rename. Is it possible for a user-generated Event Scripter script to trigger this same dialog prompt at runtime?
Reply With Quote
  #2791  
Old 02.03.2024, 04:57
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default Using comments for transfer status

I wanted to share some minor alterations of mgpai's script (https://board.jdownloader.org/showpo...8&postcount=20) for moving files as I thought it might be useful for others and addresses problems with data transfers that may otherwise go unnoticed.

One potential issue with moving files is that IO issues, reboots, crashes, etc. can interrupt a transfer. When the system recovers, the transfer will be incomplete, and one can be left with an incomplete copy in primary destination storage. For non-archives, it is more difficult to glean which files have not finished transferring when moving by a script (without looking at logs, examining files, etc.). Thus, it would be useful to "flag" when a file is moving and has successfuly transferred.

Ideally, we would be able to set the status symbols (e.g., to a differently colored checkmark); however, since this does not seem possible, I instead take advantage of the comment column.

This script checks if the file is intended for a "/mnt/scratch" temporary directory, sets a "Moving..." comment after the download is complete and before transfer, initiates a copy to a different final destination "/mnt/final", and then finally sets a "Successfully moved." comment, indicating the download was transferred successfully. If a transfer is later found to be incomplete ("Moving..."), the user can manually transfer externally or use a button-triggered script to complete the transfer. There is also some cleanup of the original file and package directory.


Code:
// Move from scratch temp dir to final dir

// Trigger: Package Finished

if (link.finished && !link.getArchive()) {
    // regex to check if folder in scratch directory
    const scratchRegex = new RegExp('^/mnt/scratch/');
    var downloadFolder = package.getDownloadFolder();
    if (scratchRegex.test(downloadFolder)) {
        var destinationFolder = getPath("/mnt/final/" + link.package.name);
        link.setComment("Moving...");
        var copied = getPath(link.downloadPath).copyTo(destinationFolder);
        if (copied) {
            getPath(link.downloadPath).delete();
            // try to delete package dir if empty
            getPath(package.getDownloadFolder()).delete();
            link.setComment("Successfully moved.");
        }
    }
}

For archives, this is already addressed by the extraction status symbols. However, for sake of completeness, I do the same for archive packages; again based on an mgpai script (https://board.jdownloader.org/showpo...84&postcount=7).

Code:
// Set successful comment and delete empty dir for extracted archive

// 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) {
    // try to delete package dir if empty
    getPath(package.getDownloadFolder()).delete();
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        link.setComment("Successfully extracted.");
    }
}

Last edited by blank; 02.03.2024 at 05:03.
Reply With Quote
  #2792  
Old 02.03.2024, 19:47
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Default

Quote:
Originally Posted by blank View Post
Before downloading or extracting a file whose path matches an existing file, JDownloader will generate a dialog prompt that gives the name of the file and the sizes of the existing and potential new file and then asks the user if they would like to overwrite, skip, or rename. Is it possible for a user-generated Event Scripter script to trigger this same dialog prompt at runtime?
It was a few years ago, but it seems I have an answer to my question: no, it is not possible to use the "Skip file if exists" GUI in an Event Scripter script. The alternative option appears to be to disable the link instead.

Quote:
Originally Posted by mgpai View Post
While it is possible to detect if the exists on disk, it is not possible to extend the GUI functionality of 'skip file if exists' to the event scripter. The links can only be disabled/removed or temporarily skipped to prevent it from being downloaded.

The current method limits the number (depth) of sub-folders which can be checked. Please wait for Jiaz to respond regarding request for new API method.

@Jiaz: Would it be possible to provide recursive list of the files and folders on the disk, something like:

Code:
var myFilePath[] = myFilePath.getChildrenRecursive();

Also can a method similar to "Mark as Finished" menu command be added?
Reply With Quote
  #2793  
Old 03.03.2024, 05:34
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by blank View Post
It was a few years ago, but it seems I have an answer to my question: no, it is not possible to use the "Skip file if exists" GUI in an Event Scripter script. The alternative option appears to be to disable the link instead.
While it is not possible to display JD GUI, you can use external utils to display interactive dialog/prompt. For e.g. in windows, you can use vbs MsgBox/InputBox or nircmd qbox.
Reply With Quote
  #2794  
Old 03.03.2024, 08:37
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

But even with "after a reconnect" something seems wrong there:


__________________
Aktuelles Windows

Last edited by Dockel; 03.03.2024 at 08:51.
Reply With Quote
  #2795  
Old 03.03.2024, 10:33
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by Dockel View Post
But even with "after a reconnect" something seems wrong there ...
The script does not disconnect the internet connection. It merely executes the 'restartAndUpdate" command when an update is available. Naturally it requires an internet connection to do that, which for some reason does not seem to be available.

You will need to figure out yourself as to why internet is getting disconnected or, wait for @Jiaz to respond.

In the meanwhile you can use the following script with either of the 'reconnect' triggers. It will restart and update only if connection is available, else it will play a sound.

Code:
/*
    update before reconnect
    trigger : before a reconnect
*/

var connected = false;

try {
    getPage("https://ipcheck0.jdownloader.org");
    connected = true;
} catch (e) {}

if (connected) {
    if (callAPI("update", "isUpdateAvailable")) {
        callAPI("update", "restartAndUpdate");
    }
} else {
    playWavAudio(JD_HOME + "/themes/standard/org/jdownloader/sounds/captcha.wav");
}
Reply With Quote
  #2796  
Old 03.03.2024, 10:54
Dockel Dockel is offline
JD Legend
 
Join Date: Feb 2020
Posts: 681
Default

Thank you very much for the script!

When Reconnect is not activated the connection is kept like usual. Only when Reconnect is activated the connection will be interrupted.

Yes, of course, let's wait for Jiaz.

Thank you very much again!
__________________
Aktuelles Windows
Reply With Quote
  #2797  
Old 03.03.2024, 20:59
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,006
Default

@Dockel: Typical issue caused by firewall/av blocking access to this url. Please check firewall/av and in doubt try to add it to exclude list or white/exclude list JDownloader.
This URL is part of the update cycle
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2798  
Old 03.03.2024, 22:15
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by Jiaz View Post
This URL is part of the update cycle
Hello Jiaz,

Which URL?
Reply With Quote
  #2799  
Old 03.03.2024, 23:19
blank blank is offline
Baby Loader
 
Join Date: Oct 2023
Posts: 9
Talking

Quote:
Originally Posted by mgpai View Post
While it is not possible to display JD GUI, you can use external utils to display interactive dialog/prompt. For e.g. in windows, you can use vbs MsgBox/InputBox or nircmd qbox.
Thank you! I appreciate the confirmation. I was considering an external utility as well.
Reply With Quote
  #2800  
Old 03.03.2024, 23:57
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,560
Default

Quote:
Originally Posted by blank View Post
Thank you! I appreciate the confirmation. I was considering an external utility as well.
Maybe you got what I wrote in my reply, but just in case, I meant you can call external utils from the script and pass the input as parameter to eventscripter methods.
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 10:55.
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.