JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #721  
Old 14.05.2019, 12:51
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 12:56
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 13:03
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 09: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, 10:26
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 10:29
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,084
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, 23: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, 08:07
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 17: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, 17:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 07:01
thecoder2012's Avatar
thecoder2012 thecoder2012 is offline
Official 9kw.eu Support
 
Join Date: Feb 2013
Location: Internet
Posts: 1,325
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, 16: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 16:56.
Reply With Quote
  #733  
Old 30.05.2019, 20:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 21: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, 22:31
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,495
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, 23: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, 19: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, 10:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,084
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 10:22.
Reply With Quote
  #739  
Old 03.06.2019, 15: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, 17: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
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 17:33.
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 - 2023, Jelsoft Enterprises Ltd.