#1
|
|||
|
|||
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 14:55. |
#2
|
||||
|
||||
Can you share your script? just remove your logins/api keys
What trigger are you using?
__________________
JD-Dev & Server-Admin |
#3
|
|||
|
|||
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") Thank you in advance |
#4
|
||||
|
||||
@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:
__________________
JD-Dev & Server-Admin |
#5
|
|||
|
|||
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 17:05. |
#6
|
||||
|
||||
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 |
#7
|
|||
|
|||
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 17:36. |
#8
|
|||
|
|||
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") } It might be obvious for medium skilled users but I'm really a beginner on that |
#9
|
||||
|
||||
Quote:
you have to use the actual values instead Quote:
__________________
JD-Dev & Server-Admin |
#10
|
|||
|
|||
ahhhhhhhhhhhhhhh now I understand my error! thank you very much for your time and patience!
|
#11
|
||||
|
||||
You're welcome And please just ask if you've got more questions or need help!
__________________
JD-Dev & Server-Admin |
#12
|
|||
|
|||
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); } 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 |
#13
|
|||
|
|||
Quote:
Quote:
|
#14
|
||||
|
||||
@Sk8er000: you could also combine multiple information into one value
Quote:
__________________
JD-Dev & Server-Admin |
#15
|
||||
|
||||
You have to concat variables like
Quote:
Quote:
__________________
JD-Dev & Server-Admin |
#16
|
||||
|
||||
@Sk8er000: just for your information, the syntax is Javascript
__________________
JD-Dev & Server-Admin |
#17
|
|||
|
|||
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); } [...] is https EVENT1 and EVENT2 are the triggers for IFTTT Thank you very much PERSONALKEY is the webhook key linked to your IFTTT account |
Thread Tools | |
Display Modes | |
|
|