JDownloader Community - Appwork GmbH
 

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 28.10.2021, 15:36
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default Package name variable on a script

Hello,
I'm using a very very basic script to be notified on a telegram channel when a download is finished:

**External links are only visible to Support Staff****External links are only visible to Support Staff**

I'd like to add to the 3 values some variables like the name of the file that was finished, I've made a couple of tries but with no luck.

Can someone please help me?
Thank you very much:)

Last edited by Sk8er000; 28.10.2021 at 15:55.
Reply With Quote
  #2  
Old 28.10.2021, 17:17
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

Can you share your script? just remove your logins/api keys
What trigger are you using?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 28.10.2021, 17:43
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

I'm sorry I wrote only the http get and forgot to add the whole script

Code:
var iftttBrowser = getBrowser(); 

iftttBrowser.getPage("[...]maker.ifttt.com/trigger/EVENTNAME/with/key/PERSONALKEY?&value1=value1&value2=value2&value3=value3")
I omitted the https part [...] since it seems to be automatically blocked.

Thank you in advance
Reply With Quote
  #4  
Old 28.10.2021, 17:56
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

@Sk8er000: you have seen the help window above the editor?
it shows all available variables/objects/methods, use the event trigger "Download has stopped"

Quote:
var myFilePackage = package;
var myDownloadLink = link;

/* === FilePackage === */
/* The context download list package*/
/* ========= Methods =========*/
var myLong = myFilePackage.getAddedDate();
var myArchive[] = myFilePackage.getArchives();
var myLong = myFilePackage.getBytesLoaded();
var myLong = myFilePackage.getBytesTotal();
var myString = myFilePackage.getComment();
var myString = myFilePackage.getDownloadFolder();
var myDownloadLink[] = myFilePackage.getDownloadLinks();
var myLong = myFilePackage.getFinishedDate();
var myLong = myFilePackage.getModified();
var myString = myFilePackage.getName();
var myString = myFilePackage.getPriority();
var myMap = myFilePackage.getProperties();
var myObject = myFilePackage.getProperty(myString);
var myString = myFilePackage.getUUID();
var myBoolean = myFilePackage.isFinished();
var myBoolean = myFilePackage.remove();

/* === FilePackage === */
/* The context download list package*/
/* ========= Methods =========*/
var myLong = myFilePackage.getAddedDate();
var myArchive[] = myFilePackage.getArchives();
var myLong = myFilePackage.getBytesLoaded();
var myLong = myFilePackage.getBytesTotal();
var myString = myFilePackage.getComment();
var myString = myFilePackage.getDownloadFolder();
var myDownloadLink[] = myFilePackage.getDownloadLinks();
var myLong = myFilePackage.getFinishedDate();
var myLong = myFilePackage.getModified();
var myString = myFilePackage.getName();
var myString = myFilePackage.getPriority();
var myMap = myFilePackage.getProperties();
var myObject = myFilePackage.getProperty(myString);
var myString = myFilePackage.getUUID();
var myBoolean = myFilePackage.isFinished();
var myBoolean = myFilePackage.remove();
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 28.10.2021, 18:00
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

I'm using the download is finished trigger, and tried the above variables but I can't get the package name correctly on "value1". I'll try to dig more and report here

Last edited by Sk8er000; 28.10.2021 at 18:05.
Reply With Quote
  #6  
Old 28.10.2021, 18:26
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

What do you mean by *name correctly*? You have to correct escape the values in case it has spaces or special chars

Also there is no "download is finshed" trigger, only "download has stopped"
__________________
JD-Dev & Server-Admin
Reply With Quote
  #7  
Old 28.10.2021, 18:34
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Code:
/*
    Send notification
    Trigger : A download stopped
*/

if (link.isFinished()) {
    var value1 = package.getName();
    var value2 = link.getName();
    var value3 = link.getBytesTotal();

    // http request goes here
}

Last edited by mgpai; 28.10.2021 at 18:36.
Reply With Quote
  #8  
Old 29.10.2021, 11:45
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

I'm sorry for the late reply, I've tried to integrate your suggested code with the prevuous one:

Code:
/*
    Send notification
    Trigger : A download stopped
*/

if (link.isFinished()) {
    var value1 = package.getName();
    var value2 = link.getName();
    var value3 = link.getBytesTotal();
    var iftttBrowser = getBrowser(); 
    
iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT/with/key/PERSONALKEY?&value1=value1&value2=value2&value3=value3")
}
but like my previous tries when the script is triggered the 3 values re reported as "value1" "value2" "value3"

It might be obvious for medium skilled users but I'm really a beginner on that
Reply With Quote
  #9  
Old 29.10.2021, 11:54
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

Quote:
iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT/with/key/PERSONALKEY?&value1=value1&value2=value2&value3=value3")
you actual send the string "value1=value1&value2=value2&value3=value3"

you have to use the actual values instead
Quote:
iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT/with/key/PERSONALKEY?&value1="+value1+"&value2="+value2+"&value3="+value3)
__________________
JD-Dev & Server-Admin
Reply With Quote
  #10  
Old 29.10.2021, 12:16
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

ahhhhhhhhhhhhhhh now I understand my error! thank you very much for your time and patience!
Reply With Quote
  #11  
Old 29.10.2021, 12:25
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

You're welcome And please just ask if you've got more questions or need help!
__________________
JD-Dev & Server-Admin
Reply With Quote
  #12  
Old 29.10.2021, 17:23
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

I've spent a couple of hour brainstormig how to accomplish that but since I'm trying to learn I'm stuck again.

Looking at the most interesting variables for this string, I've find the ones that I'd like to use (for now).

Tha main neckbottle is that I'm stuck with 3 values every message and I thing that sending more than 2 message at time will be very confusing.

I'd like to convert ms in a time format HH:MM:ss and bytes in GB,MB but without using more than a "iftttt value" for each:

Code:
/* 
    Send notification 
    Trigger : A download stopped 
*/ 
 
if (link.isFinished()) { 
    var value1 = package.getName(); 
    var value2 = link.getName(); 
    var bytes = link.getBytesTotal(); 
    var iftttBrowser = getBrowser();  
    var ms = link.getDownloadTime();
    var value5 = link.getContainerURL(); 
    var value6 = link.getDownloadPath(); 
    var seconds = Math.floor((ms / 1000) % 60);
    var minutes = Math.floor((ms / (1000 * 60)) % 60);
    var hours = Math.floor(ms / (1000 * 60 * 60));
    var MB = Math.floor((bytes / (1024)) % 1024);
    var GB = Math.floor(MB / (1024));
    
    
  iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT1/with/key/PERSONALKEY?&value1=" + value1 + "&value2=" + GB,MB + "&value3=" + value2); 
    
sleep(1000); 
    iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT2/with/key/PERSONALKEY?&value1=" + hours:minutes:seconds + "&value2=" + value5 + "&value3=" + value6); 
    }
as you already know if I use more than a variable between the + + (like + GB,MB +) is not working and if i use more than a variable separated with "+" (+ GB + + MB +) I'cant add nothing in between like a simple ":".

I know that is sound really stupid for the experts (and even for begginers XD) but I'm really a newbie.

Thank you in advance
Reply With Quote
  #13  
Old 29.10.2021, 17:39
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by Sk8er000 View Post
... if I use more than a variable between the + + (like + GB,MB +) is not working and if i use more than a variable separated with "+" (+ GB + + MB +) I'cant add nothing in between like a simple ":".
Find me in IRC:
Quote:
kiwiirc.com/nextclient/irc.libera.chat/#jdownloader
Reply With Quote
  #14  
Old 29.10.2021, 19:49
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

@Sk8er000: you could also combine multiple information into one value
Quote:
var value12=value1+"_and_"+value2;
var value12=value1+""+value2;
__________________
JD-Dev & Server-Admin
Reply With Quote
  #15  
Old 29.10.2021, 19:51
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

You have to concat variables like
Quote:
x+y+z
and not like
Quote:
x:y:z
__________________
JD-Dev & Server-Admin
Reply With Quote
  #16  
Old 29.10.2021, 19:51
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,338
Default

@Sk8er000: just for your information, the syntax is Javascript
__________________
JD-Dev & Server-Admin
Reply With Quote
  #17  
Old 29.10.2021, 20:03
Sk8er000 Sk8er000 is offline
Baby Loader
 
Join Date: Oct 2021
Posts: 7
Default

Finally after a lot of tries and a lot of help from you guys, I've accomplished what I need.
I'll receive 2 telegram messages (because IFTTT limits 3 value every http request) containing the information I needed:

Code:
/*  
    Send notification  
    Trigger : A download stopped  
*/  
  
if (link.isFinished()) {  
    var packname = package.getName();  
    var filename = link.getName();  
    var bytes = link.getBytesTotal();  
    var iftttBrowser = getBrowser();   
    var ms = link.getDownloadTime(); 
    var linkURL = link.getContainerURL();  
    var path = link.getDownloadPath()

function msToTime(ms) {
  var milliseconds = Math.floor((ms % 1000) / 100),
    seconds = Math.floor((ms / 1000) % 60),
    minutes = Math.floor((ms / (1000 * 60)) % 60),
    hours = Math.floor((ms / (1000 * 60 * 60)) % 24);

  hours = (hours < 10) ? "0" + hours : hours;
  minutes = (minutes < 10) ? "0" + minutes : minutes;
  seconds = (seconds < 10) ? "0" + seconds : seconds;

  return hours + ":" + minutes + ":" + seconds;
}
     var time = msToTime(ms);

function bytesToSize(bytes) {
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes == 0) return 'n/a';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
};

    var size = bytesToSize(bytes);

    iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT1/with/key/PERSONALKEY?&value1=" + packname + "&value2=" + filename + "&value3=" +  size);  
    sleep(10);  
    iftttBrowser.getPage("[...]//maker.ifttt.com/trigger/EVENT2/with/key/PERSONALKEY?&value1=" + time + "&value2=" + linkURL + "&value3=" + path);  
    }
Where:
[...] is https
EVENT1 and EVENT2 are the triggers for IFTTT

Thank you very much
PERSONALKEY is the webhook key linked to your IFTTT account
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 08:11.
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.