JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #2961  
Old 18.06.2024, 09:53
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,180
Default

@hulleyrob: sometimes solution is easier than thought Thanks for sharing your solution!
I will still work on better/easier browser usage. In case you need further help/got questions, just ask
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2962  
Old 18.06.2024, 10:46
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

@mpgai
New Script Request:

A script which converts ssssss.ms (sec. and msec.) to hh:mm:ss.xxx

Great thanks to Jiaz and especially pspzockerscene for implementing below properties in the PlugIns for keep2share and fileboom:
  • video_duration
  • video_width
  • video_height
  • video_format
Now, you can have these properties being shown in 'comments' by creating a Packagizer Rule.

Important note: In order to get this working, in the PlugIn settings - e.g. for k2s (keep2share) - you need to set single linkcheck as File linkcheck mode.

In Packagizer Rules, for Download-URLs which contain e.g k2s.cc
set Comment as e.g. as <jd:prop:video_width>,<jd:prop:video_duration>

For each new link added to LingGrabber, those properties will be shown in comments.

The duration, however, is shown as raw value.
For example:
4259.042 which is 4259 sec. and 42 msec.
What I would like to see is format hh:mm:ss.xxx
In this example 01:10:59.042

And for this conversion I would like to ask for a script.

Thank you very much for any efforts taken!
Reply With Quote
  #2963  
Old 20.06.2024, 10:42
hulleyrob hulleyrob is offline
JD Alpha
 
Join Date: Dec 2022
Posts: 24
Default

Quote:
Originally Posted by Jiaz View Post
@hulleyrob: sometimes solution is easier than thought Thanks for sharing your solution!
I will still work on better/easier browser usage. In case you need further help/got questions, just ask
funny you should say that, I have intermittent problem when running the event script a massive popup box appears occasionally with an IOException 424 failed dependency as the most obvious part of the error.

Is it worth uploading the logs for you to take a look?
20.06.24 06.16.53 <--> 20.06.24 08.43.39 jdlog://3653411370661/

Also once it has failed it disables the script. just enabling it again makes it work fine for another x times.
Reply With Quote
  #2964  
Old 20.06.2024, 12:48
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,180
Default

@hulleyrob: looks like some timeout issues with apprise, see
github.com/caronc/apprise-api/issues/29
github.com/caronc/apprise-api/issues/16
you should be able to try/catch the error to avoid the dialog/auto disable of the script
alternative you can make use of the following commands
Quote:
setAdvancedAlert(myBoolean);/*enable/disable alert with textbox and copy&paste*/
setDisableOnException(myBoolean);/*enable/disable script on exceptions*/
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2965  
Old 20.06.2024, 15:42
hulleyrob hulleyrob is offline
JD Alpha
 
Join Date: Dec 2022
Posts: 24
Default

Thank you will give it a go later when I get home.
Reply With Quote
  #2966  
Old 20.06.2024, 17:19
hulleyrob hulleyrob is offline
JD Alpha
 
Join Date: Dec 2022
Posts: 24
Default

try {
postPage('**External links are only visible to Support Staff**,
"urls=synology://192.168.0.4:5000/TOKEN&body=" + package.getName() +
" finished.");
}
catch (e) {
if (!(e instanceof Error)) {
e = new Error(e);
}
console.error(e.message);
}

A quick google of a JavaScript try catch and this appears to be working.

Can you suggest any improvements?
Reply With Quote
  #2967  
Old 21.06.2024, 00:44
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 80,180
Default

@hulleyrob: maybe URL encode package name to avoid issues if special/forbidden chars are part of it&final URL.
also maybe enqueue stuff that failed and retry sending them a few seconds later?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #2968  
Old 21.06.2024, 17:31
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
What I would like to see is format hh:mm:ss.xxx
If you find a suitable JS snippet on github[gist] or stackoverflow which can do it, I can help you add it to eventscripter.
Reply With Quote
  #2969  
Old 21.06.2024, 17:47
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

Quote:
Originally Posted by mgpai View Post
If you find a suitable JS snippet on github[gist] or stackoverflow which can do it, I can help you add it to eventscripter.
Thanks for taking a look at my request!

What I have is an Excel formula which can do the job. But I guess that cannot be used here.

But in the meantime:
Would it at least be possible to replace the "." (point) with a "," (comma).

Example:
12345.678 should be replaced with 12345,678
Could you create a script, which can do this "replacement" job?

That would also help me.
Thanks in advance for any efforts taken!
Reply With Quote
  #2970  
Old 21.06.2024, 18:06
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
... replace the "." (point) with a "," (comma).
Code:
/*
    generate "video_duration_comma" property
    trigger : packagizer hook
    Enable "synchronous execution of script" checkbox in top panel
*/    

if (linkcheckDone && state == "BEFORE") {
    var duration = link.getProperty("video_duration");

    if (duration != null) {
        link.setProperty("video_duration_comma", duration.toString().replace(".",","));
    }
}
Reply With Quote
  #2971  
Old 21.06.2024, 18:54
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

Quote:
Originally Posted by mgpai View Post
Code:
/*
    generate "video_duration_comma" property
    trigger : packagizer hook
    Enable "synchronous execution of script" checkbox in top panel
*/    

if (linkcheckDone && state == "BEFORE") {
    var duration = link.getProperty("video_duration");

    if (duration != null) {
        link.setProperty("video_duration_comma", duration.toString().replace(".",","));
    }
}
Not working for me.
Probably my mistake?

I selected "packagizer hook"
I set the checkbox "synchronous execution of script"

But still output in comment is something like this for duration:
4149.412 as it is without the script.
Any ideas what I could have done wrong?
Reply With Quote
  #2972  
Old 21.06.2024, 19:08
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
Not working for me.
Which placeholder have you used in packagier rule?
Reply With Quote
  #2973  
Old 21.06.2024, 19:47
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

Quote:
Originally Posted by mgpai View Post
Which placeholder have you used in packagier rule?
Code:
<jd:prop:video_duration>		<jd:prop:video_width>	<jd:prop:video_height>	<jd:prop:video_format>
all separated by tabs.

But now I see my mistake:
should haved used <jd:prop:video_duration_comma>

Now it's working!
Thank you very much!

Last edited by StefanM; 21.06.2024 at 19:50.
Reply With Quote
  #2974  
Old 21.06.2024, 19:52
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
...all separated by tabs.
Quote:
generate "video_duration_comma" property
Will leave the original unchanged and add a new property.
Reply With Quote
  #2975  
Old 21.06.2024, 19:54
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
Thank you very much!
You're welcome.
Reply With Quote
  #2976  
Old 22.06.2024, 10:18
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

Quote:
Originally Posted by mgpai View Post
If you find a suitable JS snippet on github[gist] or stackoverflow which can do it, I can help you add it to eventscripter.
Hello again!
Here's a JS snippet which hopefully does the job. It should even take care of the replacement of "." with ","

Code:
function convertToTimeFormat(input) {
    // Split the input string into seconds and milliseconds
    let [seconds, milliseconds] = input.split('.').map(Number);
    
    // Calculate hours, minutes, and remaining seconds
    let hours = Math.floor(seconds / 3600);
    seconds = seconds % 3600;
    let minutes = Math.floor(seconds / 60);
    seconds = seconds % 60;

    // Format hours, minutes, and seconds to always be two digits
    hours = hours.toString().padStart(2, '0');
    minutes = minutes.toString().padStart(2, '0');
    seconds = seconds.toString().padStart(2, '0');

    // Format milliseconds to always be three digits
    milliseconds = milliseconds.toString().padStart(3, '0');

    // Combine and return the formatted string
    return `${hours}:${minutes}:${seconds},${milliseconds}`;
}

// Example usage
let input = "4259.042";
let formattedTime = convertToTimeFormat(input);
console.log(formattedTime); // Output: "01:10:59,042"
Explanation:

1. Split the Input String: The input string is split into seconds and milliseconds using split('.').

2. Convert to Numbers: Both parts of the split string are converted to numbers using map(Number).

3. Calculate Hours, Minutes, and Seconds:
  • Hours are calculated by dividing the total seconds by 3600 (the number of seconds in an hour).
  • Remaining seconds are calculated using the modulo operator % and then converted to minutes and seconds similarly.

4. Format with Padding: padStart(2, '0') ensures that hours, minutes, and seconds are always two digits. padStart(3, '0') ensures that milliseconds are always three digits.

5. Combine and Return: The formatted time parts are combined into the final string in the desired format.

Copyright: ChatGPT
Reply With Quote
  #2977  
Old 22.06.2024, 10:50
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by StefanM View Post
Here's a JS snippet which hopefully does the job. It should even take care of the replacement of "." with ","
...
Copyright: ChatGPT
Contains methods not supported in eventscripter.

ChatGPT is not a reliable source for scripts/snippets. It often mixes up languages and also picks methods/functions out of thin air. That is the reason I suggested specific sources in my reply.

While newer JS methods are not supported in JD, if you find a snippet which does, it should be possible to figure out to make it work in JD.
Reply With Quote
  #2978  
Old 22.06.2024, 11:11
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default

Quote:
Originally Posted by mgpai View Post
Contains methods not supported in eventscripter.
Then it's going to be very complicated for me to find something, because I'm not familiar with Java Script at all.
Quote:
Originally Posted by mgpai View Post
ChatGPT is not a reliable source for scripts/snippets. It often mixes up languages and also picks methods/functions out of thin air.
You are right. In my experience some 20 to 50 percent of answers I get, are incorrect. But as - on the other hand - some 50 to 80 percent are correct, I use ChatGPT quite often. E.g. even very complicated Excel formulas are nearly always working as specified.
Quote:
Originally Posted by mgpai View Post
While newer JS methods are not supported in JD, if you find a snippet which does, it should be possible to figure out to make it work in JD.
Do the JS methods supported in JD depend on the Java version I use with JD?
As you probably know, JD is available with different Java versions.

But...
...if I understand you correctly, even a snippet with newer JS methods would help, as long as it has not been created by ChatGPT?
So, it would make sense if I continue searching for a snippet, created by a source one can trust?
Reply With Quote
  #2979  
Old 22.06.2024, 14:06
hulleyrob hulleyrob is offline
JD Alpha
 
Join Date: Dec 2022
Posts: 24
Default

Quote:
Originally Posted by Jiaz View Post
@hulleyrob: maybe URL encode package name to avoid issues if special/forbidden chars are part of it&final URL.
also maybe enqueue stuff that failed and retry sending them a few seconds later?
Code:
//Add your script here. Feel free to use the available api properties and methods
// Retry code

var encoded = encodeURI(package.getName());

// appriseUrl in format:
// discord://avatar@webhook_id/webhook_token
// line://Token@User
// ntfys://topic/
// pover://user@token/DEVICE
// synology://hostname:port/token
// tgram://bottoken/ChatID
// mailtos://domain.com:465?user=userid&pass=password

var appriseUrl = "synology://192.168.0.4:5000/TOKEN_REMOVED"

// appriseAPI IP:Port/notify of the server running the apprise api

var appriseAPI = '**External links are only visible to Support Staff**

const fn =  postPage(
    appriseAPI,
    "urls="
    + appriseURL 
    +"&body=" 
    + encoded
    + " finished.");

var maxRetries = 3

function retry(maxRetries, fn) {
  sleep(2000);
  return fn().catch(function(err) { 
    if (maxRetries <= 0) {
      throw err;
    }
    return retry(maxRetries - 1, fn); 
  });
}

Well definitely took longer than I had hoped went through so many different code snippets from stack overflow but I couldnt get them working so ended up with this.

@Jiaz can you see anything obviously wrong? (it seems to work but its hard to test the it might fail part)
Reply With Quote
  #2980  
Old 22.06.2024, 15:26
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,574
Default

Quote:
Originally Posted by hulleyrob View Post
... went through so many different code snippets
another one ...
Code:
var notified = false;
var count = 0;
var notify = function() {
    postPage("url", "data");
}

while (!notified && count < 3) {
    try {
        notify();
        notified = true;
    } catch (e) {
        alert(e.message);
        count++;
        sleep(2000);
    };
}
Reply With Quote
  #2981  
Old 22.06.2024, 16:50
hulleyrob hulleyrob is offline
JD Alpha
 
Join Date: Dec 2022
Posts: 24
Default

Quote:
Originally Posted by mgpai View Post
another one ...
Code:
var notified = false;
var count = 0;
var notify = function() {
    postPage("url", "data");
}

while (!notified && count < 3) {
    try {
        notify();
        notified = true;
    } catch (e) {
        alert(e.message);
        count++;
        sleep(2000);
    };
}
would alert be the popover message with the error and ok button as im trying to avoid that?
Reply With Quote
  #2982  
Old 23.06.2024, 00:50
TGU TGU is offline
Ultra Loader
 
Join Date: Jun 2024
Posts: 48
Default

@StefanM this should support the JD javascript version.

Code:
function convertToTimeFormat(input) {
    // Split the input string into seconds and milliseconds
    var split = input.split('.');
    var seconds = split[0]
    var milliseconds = split[1]
    
    // Calculate hours, minutes, and remaining seconds
    var hours = Math.floor(seconds / 3600);
    seconds = seconds % 3600;
    var minutes = Math.floor(seconds / 60);
    seconds = seconds % 60;

    // Format hours, minutes, and seconds to always be two digits
    hours = String(hours).padStart(2, '0');
    minutes = String(minutes).padStart(2, '0');
    seconds = String(seconds).padStart(2, '0');

    // Format milliseconds to always be three digits
    milliseconds = String(milliseconds).padStart(3, '0');

    // Combine and return the formatted string
    return hours + ":" + minutes + ":" + seconds + "," + milliseconds;
}

Last edited by TGU; 23.06.2024 at 00:55.
Reply With Quote
  #2983  
Old 23.06.2024, 15:20
StefanM's Avatar
StefanM StefanM is online now
JD Legend
 
Join Date: Oct 2020
Posts: 600
Default Verwendete Java Version und EventScripter

Zu diesem Java-Snippet teilte mir mgpai mit:
Quote:
Contains methods not supported in eventscripter.
...
...newer JS methods are not supported in JD...
Fragen dazu:
  1. Konkret welche der im Snippet verwendeten Befehle werden vom EventScripter nicht unterstützt?
  2. Welchen "Ersatz" kann man für die nicht unterstützen Befehle verwenden, d.h .das Snippet entsprechend umschreiben?
  3. Oder sind die "supported methods" abhängig von der im JD verwendeten Java-Version?
Reply With Quote
  #2984  
Old 24.06.2024, 10:08
pspzockerscene's Avatar
pspzockerscene pspzockerscene is online now
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 71,704
Default

EventScripter Threads zusammengeführt.
__________________
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
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 11:22.
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.