JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #721  
Old 14.05.2019, 11:51
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by sherbee View Post
Thank you for idea. But I like complicated.
Here is a new script, but if you need help to troubleshoot/fix yours, contact me in JD Chat.

Code:
// Move archive files after extraction
// Trigger: Archive Extraction Finished

var links = archive.getDownloadLinks() || [];
var destinationFolder = "C:/sherbee/check";

links.forEach(function(link) {
    var filePath = getPath(link.getDownloadPath());
    var i = 0;

    while (getPath(destinationFolder + "/" + filePath.getName()).exists()) {
        i++;
        newPath = getPath(link.getDownloadPath().toString().replace(/(.+)(\..+)/, "$1" + i + "$2"));
        getPath(filePath).renameTo(newPath);
        filePath = newPath;
    }

    filePath.moveTo(destinationFolder);
});
Reply With Quote
  #722  
Old 14.05.2019, 11:56
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by Jiaz View Post
... we can't forbid/prevent such a script..here or anywhere else
True, but I am not comfortable helping anyone scam the hosters. If (I feel) the requirement is legitimate (as in this case), I will try to help in any way I can.
Reply With Quote
  #723  
Old 14.05.2019, 12:03
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by Tarantino View Post
... if I download part by part and repeat, I will be able to download all the content before they got deleted.
Can you contact me in JD Chat? Use the chat extension available in JD or use the webchat:

Code:
webchat.freenode.net/?channels=jdownloader
Reply With Quote
  #724  
Old 15.05.2019, 08:05
sherbee sherbee is offline
JD Fan
 
Join Date: Mar 2019
Posts: 76
Default

Quote:
Originally Posted by mgpai View Post
Here is a new script, but if you need help to troubleshoot/fix yours, contact me in JD Chat.

Code:
// Move archive files after extraction
// Trigger: Archive Extraction Finished

var links = archive.getDownloadLinks() || [];
var destinationFolder = "C:/sherbee/check";

links.forEach(function(link) {
    var filePath = getPath(link.getDownloadPath());
    var i = 0;

    while (getPath(destinationFolder + "/" + filePath.getName()).exists()) {
        i++;
        newPath = getPath(link.getDownloadPath().toString().replace(/(.+)(\..+)/, "$1" + i + "$2"));
        getPath(filePath).renameTo(newPath);
        filePath = newPath;
    }

    filePath.moveTo(destinationFolder);
});
I think this is very good. Thank you. I understand better now. Replace with regex is very clever.

2 Questions I have:
  1. Is there more docu to understand better return of methods? For example if I put
    Code:
    var myString = myFilePath.getPath();
    Is output with "\" or with "/" or has it slash at end. Or when I put
    Code:
    var myString = myFilePath.getExtension();
    is output with "." or without? That is make it more easy to know better what exactly is return not only return type. Then more easy to use and put back together.
  2. Code:
    newPath = getPath(link.getDownloadPath().toString().replace(/(.+)(\..+)/, "$1" + i + "$2"));
    Is link.getDownloadPath() not string type already? Why you put ".toString()"? I think that is the only thing I cannot understand now.
All other is so very good that I want to my head for better thinking.

Only thing I must change is
Code:
replace(/(.+)(\..+)/, "$1" + i + "$2"));
to
Code:
replace(/(.+)(\..+)/, "$1 (" + i + ")$2"));
then it is like Windows Explorer original rename.
Reply With Quote
  #725  
Old 15.05.2019, 09:26
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by sherbee View Post
Questions I have ...
  1. Code:
    var myString = "c:/sherbee/check/file.txt"; // string
    var myFilePath = getPath(myString); // Converts myString to myFilePath object
    var myString = myFilePath.toString(); // Output :  "c:\sherbee\check\file.txt"
    var myString = myFilePath.getParent(); // Output: "c:\sherbee\check"
    var myString = myFilePath.getName(); // Output: file.txt
    var myString = myFilePath.getExtension(); // Output: "txt"

  2. I had intitally used a path object while testing a different version of the script, which required converting it to string. I forgot to remove it in the final script.
Reply With Quote
  #726  
Old 15.05.2019, 09:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

1.) depends on your OS, Unix(/) vs Windows (\)
2.1) without dot
2.2) I guess in the past it was different instance or just wanted to make sure that string return type
__________________
JD-Dev & Server-Admin
Reply With Quote
  #727  
Old 18.05.2019, 22:14
JDFan
Guest
 
Posts: n/a
Default

Hello,

the code example
Save youtube links and basic information to a html page
contains the following invalid line:
Code:
if (youtubeMedia) {
    var output = [];
    var variant = JSON.parse("YT_VARIANT".prop());
    var variantData = JSON.parse(variant.data);
    var youtube = "<a href=\"External links are only visible to Support Staff;
Can someone be so kind and correct that?


Many thanks and greetings
JDFan
Reply With Quote
  #728  
Old 19.05.2019, 07:07
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by JDFan View Post
... the code example Save youtube links and basic information to a html page contains the following invalid line: ...
Code:
 var youtube = "<a href=\"External links are only visible to Support Staff;

Script:
Code:
gist.github.com/mgpai/defe23044e32d7cec7756053997295e1/download
Reply With Quote
  #729  
Old 20.05.2019, 16:04
JDFan
Guest
 
Posts: n/a
Default Corresponds EventScripter YT_CHANNEL_TITLE to Plugins Filename & Packagename CHANNEL?

Hello,

the result of the following script is always null:
Code:
if (name == "YT Test") {
  sYT_Channel_Title = downloadLinks[0].getProperty("YT_CHANNEL_TITLE") ;
  alert("YT_Channel_Title: " + sYT_Channel_Title) ;
}
YT_CHANNEL_ID works.

My filename contains an CHANNEL, so the package should contain one.


Many thanks and greetings
JDFan
Reply With Quote
  #730  
Old 20.05.2019, 16:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by JDFan View Post
... YT_CHANNEL_ID works. ...
Code:
var channelName = myDownloadLink.getProperty("YT_CHANNEL");
Reply With Quote
  #731  
Old 27.05.2019, 06:01
thecoder2012's Avatar
thecoder2012 thecoder2012 is offline
Official 9kw.eu Support
 
Join Date: Feb 2013
Location: Internet
Posts: 1,324
Default

Quote:
Originally Posted by Bach View Post
The script shows errors in the 23 line.
Syntax Error: Unterminated objekt literal
Error Report
net.sourceforge.htmlunit.corejs.javascript.EcmaError: SyntaxError: Unterminated object literal (#23)
I have updated my example with better errorhandling and retries. See my post #93 in this topic.
__________________
Join 9kw.eu Captcha Service now and let your JD continue downloads while you sleep.
Reply With Quote
  #732  
Old 30.05.2019, 15:38
bobolecoco bobolecoco is offline
Super Loader
 
Join Date: Aug 2015
Location: France
Posts: 27
Default Wait / Sleep

Hi.
The trigger is "A download started".
With the following code, downloads are "freezed" :
Code:
function Stream() {
    if (isDownloadControllerRunning()) {
        alert("OK !");
        sleep(30000);
        Stream();
    }
}
Stream();
Why ? Is the "sleep" function is "sleeping" the whole JDownloader process or just the script ?

(This is for testing purpose, my idea is to replace "alert("OK !");" with a function I want to check every 30 seconds while the "Download Controller" is running).

Is there a way to achieve that (pausing only the script) ?

Thanks !

Last edited by bobolecoco; 30.05.2019 at 15:56.
Reply With Quote
  #733  
Old 30.05.2019, 19:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by bobolecoco View Post
With the following code, downloads are "freezed"
Disable the "Synchronous execution of script" checkbox.

Quote:
Originally Posted by bobolecoco View Post
Is there a way to achieve that (pausing only the script) ?
If you can provide information on what you want to achieve with the function/script, we can look into it.
Reply With Quote
  #734  
Old 30.05.2019, 20:16
bobolecoco bobolecoco is offline
Super Loader
 
Join Date: Aug 2015
Location: France
Posts: 27
Default Thanks

Thanks, it worked. So if 2 downloads start, the script will run twice ? Should I use "Download controller started" trigger instead if I want only one instance to run ?

I already have a working script, it runs every 30 seconds (interval 30000). But it's relevant only when a download is running. It allows me to put a speed limit when a twitch channel is streaming, so bandwidth stay available to watch the stream. Here it is :
Code:
var myBrowser = getBrowser();
myBrowser.setHeader("Accept", "application/vnd.twitchtv.v3+json");
myBrowser.setHeader("Client-ID", "HereIsMyPrivateClientId");
myBrowser.getPage("**External links are only visible to Support Staff**);

if (!/"stream":null/.test(myBrowser.getHTML())) {
    setSpeedlimit(1.5 * 1024 * 1024);
} else {
    setSpeedlimit(0);
}
It's not relevant to run it when no file is being downloaded, but it need to be run periodically (every 30sec) when it is the case. That's why I was looking for triggers like "A download started" or "Download controller started" and use a while loop or a function that calls itself while "isDownloadControllerRunning()" is true.

Am I clear enough (English is not my natural language) ?

A problem I have is when twitch's server is not reachable for a brief moment : it triggers an error, and the script disables itself. So running it only when downloading reduce the probability to trigger that error. An other solution would be to extent time before a timeout error is fired, but I didn't find any option like this with getBrowser().

A reliable way to do it would be to create an external script that check if there is a streaming, that JD runs from event scripter. But my idea was to NOT use an external script.
Reply With Quote
  #735  
Old 30.05.2019, 21:31
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,549
Default

Quote:
Originally Posted by bobolecoco View Post
So if 2 downloads start, the script will run twice ?
Yes

Quote:
Originally Posted by bobolecoco View Post
Should I use "Download controller started" trigger instead if I want only one instance to run ?
Yes

Quote:
Originally Posted by bobolecoco View Post
A problem I have is when twitch's server is not reachable for a brief moment : it triggers an error, and the script disables itself.
Use try/catch.

Sample Code (Totally untested) :
Code:
// Toggle Speed Limit
// Trigger: Download Controller Started
// IMPORTANT: Disable 'Synchronous Execution'

while (isDownloadControllerRunning()) {
    if (streaming()) {
        setSpeedlimit(1.5 * 1024 * 1024);
    } else {
        setSpeedlimit(0);
    }
    sleep(30000);
}

//Functions
function streaming() {
    try {
        var myBrowser = getBrowser();
        myBrowser.setHeader("Accept", "application/vnd.twitchtv.v3+json");
        myBrowser.setHeader("Client-ID", "HereIsMyPrivateClientId");
        myBrowser.getPage("hxxps://api.twitch.tv/kraken/streams/TheNameOfTheTwitchChannel");
        return /"stream":null/.test(myBrowser.getHTML());
    } catch (e) {
        //On error assume it is atreaming?
        return true;
    }
}
Reply With Quote
  #736  
Old 30.05.2019, 22:07
bobolecoco bobolecoco is offline
Super Loader
 
Join Date: Aug 2015
Location: France
Posts: 27
Default Thanks again

It seems to work. I'll see if errors appear in the future.

Thanks ! I'll keep you posted if anything new happens !
Reply With Quote
  #737  
Old 02.06.2019, 18:11
JDFan
Guest
 
Posts: n/a
Default Avoid disabling erroneous scripts

Hello,

erroneous scripts are automatically disabled in the Settings -> Event Scripter after the first run. That makes sense, but not during testing. Any way to switch that behaviour off?


Many thanks and greetings
JDFan
Reply With Quote
  #738  
Old 03.06.2019, 09:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

@JDFan: Script won't get disabed when testing script. you want a way to disable *auto disable* in script?
__________________
JD-Dev & Server-Admin

Last edited by Jiaz; 03.06.2019 at 09:22.
Reply With Quote
  #739  
Old 03.06.2019, 14:48
Spyro70
Guest
 
Posts: n/a
Default

Mgpai,
I would like create a script to download some steaming with a scheduler that consider days, hours and minutes. I am not a programmer...can tell me how I can work out it?
Reply With Quote
  #740  
Old 03.06.2019, 16:07
JDFan
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by Jiaz View Post
@JDFan: Script won't get disabed when testing script. you want a way to disable *auto disable* in script?
I would prefer a global switch in Advanced Settings. I assume that's easier to implement compared to a change in the script engine.
Reply With Quote
  #741  
Old 03.06.2019, 16:25
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
I would prefer a global switch in Advanced Settings. I assume that's easier to implement compared to a change in the script engine.
script command is much easier than global switch also script command has the advantage that yuo can enable/disable it within the same script and not have impact on all other scripts as well
__________________
JD-Dev & Server-Admin
Reply With Quote
  #742  
Old 03.06.2019, 16:30
JDFan
Guest
 
Posts: n/a
Default YouTube plugin: What does YT_DESCRIPTION contain?

I'm wondering because I get always null!
Reply With Quote
  #743  
Old 03.06.2019, 16:40
JDFan
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by Jiaz View Post
script command is much easier than global switch also script command has the advantage that yuo can enable/disable it within the same script and not have impact on all other scripts as well
Then a script command please! Many thanks in advance.
Reply With Quote
  #744  
Old 03.06.2019, 16:42
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

@JDFan: it contains the description/text but only temporarily and currently not available via normal getProperty because those details are fetched and cached during session, not stored.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #745  
Old 03.06.2019, 16:47
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
Then a script command please! Many thanks in advance.
after next core update there are
setNotifyOnException(true/false), show(yes,no) dialog to inform about exception
setDisableOnException(true/false), disable(yes,no) script on exceptions
__________________
JD-Dev & Server-Admin
Reply With Quote
  #746  
Old 03.06.2019, 18:20
JDFan
Guest
 
Posts: n/a
Default alert box is flickering, complex problem

Complex problem, really. Script triggered by Script Downloadlist Contextmenu Button Pressed (name Test). YouTube video is downloaded. Flickers only with that link (others too). BUT when you change only some letters of 0Mp2kwE8xY0 no flickering (e. g. M -> 1)! Can someone reproduce that crazy behaviour?

Code:
if ( name == "Test" )
{
  //      123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
  alert( "Line1: **External links are only visible to Support Staff**) ;
}
And when no flickering occurs, the height is too small.
Reply With Quote
  #747  
Old 03.06.2019, 18:55
JDFan
Guest
 
Posts: n/a
Default alert box wishes

1. Optional (checkbox) non-proportional font like Courier New. Better readable debug outputs.
2. Properties for x, y, w(idth) and h(eight).
3. Copy to Clipboard button. Maybe Paste too.
Reply With Quote
  #748  
Old 03.06.2019, 18:58
JDFan
Guest
 
Posts: n/a
Default Clipboard access via script

Reading from and writing to the clipboard should be possible. Maybe with special security flag via Advanced Settings.
Reply With Quote
  #749  
Old 03.06.2019, 19:00
JDFan
Guest
 
Posts: n/a
Default Input dialog

Would simplify automation (passing parameters from other apps, e. g. AutoHotkey and speech recognition). Maybe with special security flag via Advanced Settings.
Reply With Quote
  #750  
Old 03.06.2019, 19:53
JDFan
Guest
 
Posts: n/a
Default Get hostname

Maybe via the Environment Object? getHostname()?? Different PCs/notebooks, different folder structures. Want to set pathes depending on the PC/notebook in use.

Edit: There seems to be an environment variable COMPUTERNAME.
Code:
sComputerName = getEnv( "COMPUTERNAME" ) ;
alert( sComputerName ) ;

Last edited by JDFan; 03.06.2019 at 21:20.
Reply With Quote
  #751  
Old 03.06.2019, 19:58
JDFan
Guest
 
Posts: n/a
Default Global variables

Should be accessible by all scripts. For a limited number of global script variables environment variables could be used of course, like JD_VarName.
Reply With Quote
  #752  
Old 03.06.2019, 21:16
JDFan
Guest
 
Posts: n/a
Default Event Scripter export/import

The possibility to export all marked scripts would be great. Should be an xml file so it could be created/modified with other tools. And of course the corresponding import functionallity.
Maybe with support by the event scripter itself? Methods like listScripts(), exportScripts(), importScripts(), enableScripts(), disableScripts(). Parameter an arrray of scripts. Propeties enabled, name, trigger plus all the GUI settings.
Reply With Quote
  #753  
Old 04.06.2019, 15:26
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
The possibility to export all marked scripts would be great. Should be an xml file so it could be created/modified with other tools. And of course the corresponding import functionallity.
Maybe with support by the event scripter itself? Methods like listScripts(), exportScripts(), importScripts(), enableScripts(), disableScripts(). Parameter an arrray of scripts. Propeties enabled, name, trigger plus all the GUI settings.
I don't think we have to create new commands for this. you can already access the advanced settings storage from the scripts via callapi and accessing the advanced settings and then read/write/modify or export/import. I'm sure mgpai can help you with that
__________________
JD-Dev & Server-Admin
Reply With Quote
  #754  
Old 04.06.2019, 15:27
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
Should be accessible by all scripts. For a limited number of global script variables environment variables could be used of course, like JD_VarName.
What *global variables* do you mean? You already can use set/getProperty(key,boolean) method with local(script,false)) or global(shared,true) and share information accross different scripts with help of global properties
__________________
JD-Dev & Server-Admin
Reply With Quote
  #755  
Old 04.06.2019, 15:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
Maybe via the Environment Object? getHostname()?? Different PCs/notebooks, different folder structures. Want to set pathes depending on the PC/notebook in use.

Edit: There seems to be an environment variable COMPUTERNAME.
Code:
sComputerName = getEnv( "COMPUTERNAME" ) ;
alert( sComputerName ) ;
You can either use getEnv to access the environment variables and/or use getEnvironment to access the EnvironmentSandbox object
__________________
JD-Dev & Server-Admin
Reply With Quote
  #756  
Old 04.06.2019, 15:30
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by jdfan View Post
reading from and writing to the clipboard should be possible. Maybe with special security flag via advanced settings.
Quote:
Originally Posted by jdfan View Post
3. Copy to clipboard button. Maybe paste too.

__________________
JD-Dev & Server-Admin
Reply With Quote
  #757  
Old 04.06.2019, 16:44
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

Quote:
Originally Posted by JDFan View Post
Complex problem, really. Script triggered by Script Downloadlist Contextmenu Button Pressed (name Test). YouTube video is downloaded. Flickers only with that link (others too). BUT when you change only some letters of 0Mp2kwE8xY0 no flickering (e. g. M -> 1)! Can someone reproduce that crazy behaviour?

Code:
if ( name == "Test" )
{
  //      123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
  alert( "Line1: **External links are only visible to Support Staff**) ;
}
And when no flickering occurs, the height is too small.
The flickering happens because of resize loop of auto break on text caused by the space. This is more complex to handle better and sorry to say but at the moment not that important.
__________________
JD-Dev & Server-Admin
Reply With Quote
  #758  
Old 05.06.2019, 15:50
JDFan
Guest
 
Posts: n/a
Default Event Scripter export/import

@mgpai:

Can you be so kind and support me with some basic hints, e. g. concerning callapi and where I can find the corresponding methods:
Quote:
Originally Posted by Jiaz View Post
I don't think we have to create new commands for this. you can already access the advanced settings storage from the scripts via callapi and accessing the advanced settings and then read/write/modify or export/import. I'm sure mgpai can help you with that
Reply With Quote
  #759  
Old 05.06.2019, 15:54
JDFan
Guest
 
Posts: n/a
Default INI file support and JSON

I really like INI files. And JSON, too. Scripter support?
Reply With Quote
  #760  
Old 05.06.2019, 15:58
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,537
Default

@JDFan: see https://my.jdownloader.org/developers/ for list of api methods and their parameters
__________________
JD-Dev & Server-Admin
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:04.
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.