JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1021  
Old 06.12.2019, 13:47
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by SMS View Post
How can I rename files? I want to download domain.com/foo/bar.zip as bar_foo.zip rather than as bar.zip. The renaming should happen early. For example as a Packagizer Hook, or within the following call in a script I have:

Code:
myObject = callAPI("linkgrabberv2", "addLinks", {
    "links": theLink
});
Code:
// Rename files by matching download url pattern
// Trigger: Packagizer Hook

if (state == "BEFORE") {
    var patt = /.+\/domain\.com\/(foo)\/(bar)(\.zip)/i;
    var name = link.getURL().match(patt);
    if (name) link.setName(name[2] + "_" + name[1] + name[3]);
}

Packagizer rules not suitable for this?
Reply With Quote
  #1022  
Old 08.12.2019, 11:00
SirJohnny SirJohnny is offline
Baby Loader
 
Join Date: Oct 2019
Posts: 8
Default

Hello, how can I see the output of my script ? In python, you would call print.
Is alert the only way ?

For example, I want to display the items that pass the if statement for debug purposes:

Code:
var allDownloadLinks = getAllDownloadLinks(); // Get all download links

allDownloadLinks.forEach(function(allDownloadLink) {
    var allDownloadLinkHost = allDownloadLink.getDownloadHost();
    var allDownloadLinkFinished = allDownloadLink.isFinished();
    var allDownloadLinkPackage = allDownloadLink.getPackage();
    if (allDownloadLinkHost == "youtube.com" && !allDownloadLinkFinished) {
        alert(allDownloadLinkPackage.getName() + " : " + allDownloadLink.getName() + " : " + allDownloadLinkHost + " --> " + allDownloadLink.isFinished());
    }
})
Reply With Quote
  #1023  
Old 08.12.2019, 12:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by SirJohnny View Post
how can I see the output of my script ? In python, you would call print.
Is alert the only way ?
You can also log the output to JD session logs using:
Code:
log(myObject[]);/*Log to stderr and to JDownloader Log Files*/

or, write to a file using:
Code:
writeFile(myString/*filepath*/, myString/*myText*/, myBoolean/*append*/);/*Write a text file*/
/* Example: */writeFile(JD_HOME+"/log.txt",JSON.stringify(this)+"\r\n",true);

You can append the debug string to a variable and view them in a single alert box after all the items in the array are processed.
Reply With Quote
  #1024  
Old 08.12.2019, 19:10
noone1's Avatar
noone1 noone1 is offline
JD Beta
 
Join Date: Oct 2013
Posts: 50
Default

Quote:
Originally Posted by SirJohnny View Post
Hello,
hello,

maybe this one could be more 'visual' while a bit time consuming if you try to display huge object!

Code:
function jdbox(){
/*call jdbox(arg1,arg2,...)

    alert(print_r([JSON.parse(JSON.stringify(arguments,null,"\t"))]));
}
edt:oops, forgot the 2nd
Spoiler:
Code:
function print_r(arr, level) {
//stackoverflow.com/a/9613740
//format recursive Array/Hashes/Objects,Strings/Chars/Numbers etc...

    var dumped_text = "";
    if (!level) level = 0;

    var level_padding = "";//The padding given at the beginning of the line.
    for (var j = 0; j < level + 1; j++) level_padding += "    ";

    if (typeof(arr) == 'object') { 
        for (var item in arr) {
            var value = arr[item];

            if (typeof(value) == 'object') { 
                dumped_text += level_padding + item + " ...\n";
                dumped_text += print_r(value, level + 1);
            } else {
                dumped_text += level_padding + item + " => " + value + "\n";
            }
        }
    } else { 
        dumped_text = "=> " + arr + " <=(" + typeof(arr) + ")";
    }
    return dumped_text;
}

edt2: logf will redirect to a file or simply combine it with alert. ex:alert("test1"+print_r(myobj)); not perfect but it run through any kind of type and display it...while we are hopping a debugger in JD

Otherwise I've just posted a question on the board with a script that contains 2 usefull functions I use (logf and print_r), may be it can help.
__________________
Spoiler:

>'msdos/js chimera' : we will rule the world!
>'py god' : calm down... you are era too early
>'vba Bellérophon': one day I will kill you both, I swear
>'wscript pegasus': me too, me too
>'php observer': haha, those kids are funny
epilogue
>'brainf*ck alien': +[>.+<] bzzzt
>'whitepace void':
...
>'java nut': I think, therefore I am, I know I'm not crazy! anybody in there??
:biggrin:

Last edited by noone1; 08.12.2019 at 19:34.
Reply With Quote
  #1025  
Old 10.12.2019, 21:02
askin2u askin2u is offline
Fibre Channel User
 
Join Date: Mar 2015
Posts: 128
Default

Hi, I have a question: I have differente debrid accounts.
I'd like to log the performance for comparison
I will try to explain in pseudocode
Code:
if isDownloadedUsingPremium(link)
    then Log (host/accountUsed/successOrError/TimeStarted/TimeFinished/SizeorAverageSpeed)
    else notLog
is it posssible to achieve?

thanks
Reply With Quote
  #1026  
Old 10.12.2019, 22:28
raztoki's Avatar
raztoki raztoki is offline
English Supporter
 
Join Date: Apr 2010
Location: Australia
Posts: 16,984
Default

@askin2u
as is the log function jd core? or some more eventscripter function ?
if its jd core then logging function currently is core function.

raztoki
__________________
raztoki @ jDownloader reporter/developer
http://svn.jdownloader.org/users/170

Don't fight the system, use it to your advantage. :]
Reply With Quote
  #1027  
Old 11.12.2019, 09:49
askin2u askin2u is offline
Fibre Channel User
 
Join Date: Mar 2015
Posts: 128
Default

Quote:
Originally Posted by raztoki View Post
@askin2u
as is the log function jd core? or some more eventscripter function ?
if its jd core then logging function currently is core function.

raztoki
honestly don't know, I'd like to log every try to use a premium account in a file so that I can grep and get some stats.
Reply With Quote
  #1028  
Old 11.12.2019, 10:17
raztoki's Avatar
raztoki raztoki is offline
English Supporter
 
Join Date: Apr 2010
Location: Australia
Posts: 16,984
Default

@askin2u
Not much useful stuff is within logs other than maybe start time and finish, probably easier just using event scripter and gather info and create/update db
or do it within the core create stats module/extension
__________________
raztoki @ jDownloader reporter/developer
http://svn.jdownloader.org/users/170

Don't fight the system, use it to your advantage. :]
Reply With Quote
  #1029  
Old 11.12.2019, 18:25
Rabelux Rabelux is offline
Baby Loader
 
Join Date: Oct 2018
Posts: 9
Question Exitcode of callsync()

Hi mgpai,
is there a way to retrieve the exit code of a callsync()-function?
Or to specify my question: how do I check whether the called function/script did not encounter any errors? If I got this correct a callsync() returns the first stdout that occours. In my case that doesn't leave a clue whether the call was succesfull.
To give you an idea what I'm trying to accomplish:
I have a headless setup of JDownloader on a remote server and after finishing a download I want that file to be copied to my local server via scp. If that was successfull the remote server should delete the file.
I got the copy-part working but cannot check whether it was successful.
My code:
Code:
//trigger: download stopped
disablePermissionChecks();
if (link.isFinished()) {
    var sourceFile = link.getDownloadPath();
    var result = callSync("scp", sourceFile, "user@hostname:/path");
    if (result == 0) {
        deleteFile(sourceFile, false);
        log(sourceFile + " should be deleted")
    } else {
        log("Err: scp-result = " + result);
    }
    if (package.isFinished()) package.remove();
}
Thanks in advance,
rabelux
Reply With Quote
  #1030  
Old 12.12.2019, 06:01
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by Rabelux View Post
is there a way to retrieve the exit code of a callsync()-function?
Exit code is captured by the "$?" operator. You should be able to get it by adding "echo $?" to your command. Cannot use callAsync() instead?
Reply With Quote
  #1031  
Old 13.12.2019, 11:44
Rabelux Rabelux is offline
Baby Loader
 
Join Date: Oct 2018
Posts: 9
Default

Quote:
You should be able to get it by adding "echo $?" to your command
You mean something like
Code:
callSync("scp", sourceFile, "user@hostname:/path", "; echo $?")
or rather get the echo in a new call like callsync("echo $?")?
The question is what does callSync() return? The first, the last, or the sum of all echos to stdout?

What would be the benefit of using callAsync()? I thought using sync is better as i want to make sure the whole file has been copied.
Reply With Quote
  #1032  
Old 13.12.2019, 12:30
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by Rabelux View Post
You mean something like
Code:
callSync("scp", sourceFile, "user@hostname:/path", "; echo $?")
or rather get the echo in a new call like callsync("echo $?")?
The question is what does callSync() return? The first, the last, or the sum of all echos to stdout?

What would be the benefit of using callAsync()? I thought using sync is better as i want to make sure the whole file has been copied.
callSync() will output stdOut or stdErr. You have to use the echo $? as the second command (using &), which will result in stdOut or stdErr + echo result. It is also possible to get just the exit code by redirecting redirect the stdOut & stdErr to null device.

callAsync() will be more suitable as the exitCode, stdOut or stdErr will be available to the callback function. This will be available after the external command has ended (in this case the file has been copied or failed). You then have to just query those properties before executing your code.

Feel free to find me in JD Chat if you need any help with this.
Reply With Quote
  #1033  
Old 15.12.2019, 18:56
HughJazz HughJazz is offline
Baby Loader
 
Join Date: Apr 2017
Posts: 5
Default

Quote:
Originally Posted by mgpai View Post
IG does not provide RSS feeds. You will have to use third-party services to generate custom RSS/XML feeds and add them at regular intervals to linkgrabber using a script.

Alternatively, you can also use a script to add native IG urls to the linkgrabber at regular intervals. By default this will fetch all the content from the given url. There is a plugin option where you can specify the 'x' latest items to be fetched. This however does not seem to be currently working as expected.

If you want to avoid adding duplicate urls to linkgrabber, you will have to leave the old urls in the download list or linkgrabber list. If the links are present in linkgrabber, JD will skip them. Links present in the download list will be added to the list and marked (BG color will be red) as duplicate. You can create a linkgrabber filter rule to also skip links which are present in the download list.

Code:
// Add urls to linkgrabber at user-defined intervals
// Trigger: Interval (Recommended 3600000 ms or more)

var urls = [];
urls[urls.length] = "**External links are only visible to Support Staff**;
urls[urls.length] = "**External links are only visible to Support Staff**;
urls[urls.length] = "**External links are only visible to Support Staff**;
urls[urls.length] = "**External links are only visible to Support Staff**;
urls[urls.length] = "**External links are only visible to Support Staff**;

callAPI("linkgrabberv2", "addLinks", {
    "links": urls.join(" ")
});
I managed to add the script and it is working, but it keeps adding duplicate links, so can you please tell me how to create the filter rule to skip duplicate instagram links?
Reply With Quote
  #1034  
Old 16.12.2019, 05:54
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by HughJazz View Post
... how to create the filter rule to skip duplicate instagram links?
Settings > Linkgrabber Filter > Filter :

Code:
Condition > is true > Link is already in downloadlist
Sourceurl(s) > contains > instagram.com
Reply With Quote
  #1035  
Old 16.12.2019, 06:58
raztoki's Avatar
raztoki raztoki is offline
English Supporter
 
Join Date: Apr 2010
Location: Australia
Posts: 16,984
Default

adding a filter wont mean the decryption task will finish though.
creating a crontab like event in theory is good. but realistically when dupes are found decryption task should end.
__________________
raztoki @ jDownloader reporter/developer
http://svn.jdownloader.org/users/170

Don't fight the system, use it to your advantage. :]
Reply With Quote
  #1036  
Old 16.12.2019, 19:27
anonymous anonymous is offline
Baby Loader
 
Join Date: Sep 2019
Posts: 8
Default

Quote:
Originally Posted by mgpai View Post
Code:
// Rename files by matching download url pattern
// Trigger: Packagizer Hook

if (state == "BEFORE") {
    var patt = /.+\/domain\.com\/(foo)\/(bar)(\.zip)/i;
    var name = link.getURL().match(patt);
    if (name) link.setName(name[2] + "_" + name[1] + name[3]);
}

Packagizer rules not suitable for this?

Is this what I would need to use in the case of creating a directory and subdirectory based on the pinterest url?

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

mine was more like this with my basic javascript knowledge so, i didn't know exactly how to apply it to this situation
Code:
testVar = document.URL
testVar = https://www.pinterest.com/stewipanzon/english-bull-terrier/

const [first, second] = testVar.split("/").filter(n=>n).slice(-2);
	if pinterestURL
		if the url is in this format, 
			main folder is first string 
			subfolder is second string
        ...

first = stewipanzon
second = english-bull-terrier
Hoping someone can understand my intent
Reply With Quote
  #1037  
Old 16.12.2019, 20:14
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by anonymous View Post
Is this what I would need to use in the case of creating a directory and subdirectory based on the pinterest url?
Use the packagizer extension (unless for some reason you need to use a script).

Settings > Packagizier > Add:

Code:
if > Sourceurl(s) > contains : https://www.pinterest.com/*/*/
then set > Download Directory : <jd:source:1>\<jd:source:2>
Reply With Quote
  #1038  
Old 16.12.2019, 20:49
anonymous anonymous is offline
Baby Loader
 
Join Date: Sep 2019
Posts: 8
Default

Quote:
Originally Posted by mgpai View Post
Use the packagizer extension (unless for some reason you need to use a script).

Settings > Packagizier > Add:

Code:
if > Sourceurl(s) > contains : https://www.pinterest.com/*/*/
then set > Download Directory : <jd:source:1>\<jd:source:2>
Thanks. I thought i needed some kind of regexpr trick at first. I've been searching for those "jd:" parameters but haven't had any luck. I appreciate this a lot. Would it be possible to have it this apply to already downloaded items as well?

Changingg what's already in the linkgrabber "queue just gives invalid download directory" after starting. Changing the already downloaded using that yields:
Code:
java.io.IOException: Could not create E:\Users\NewAdmin\pinterest\<jd:source:1>\<jd:source:2>
	at jd.plugins.PluginForHost.renameOrMove(PluginForHost.java:2409)
	at jd.plugins.PluginForHost.handle(PluginForHost.java:2400)
	at jd.plugins.PluginForHost.move(PluginForHost.java:2358)
	at jd.controlling.downloadcontroller.DownloadWatchDog.move(DownloadWatchDog.java:4520)
	at jd.controlling.downloadcontroller.DownloadWatchDog$44.execute(DownloadWatchDog.java:4483)
	at jd.controlling.downloadcontroller.DownloadWatchDog$30.run(DownloadWatchDog.java:3008)

Last edited by anonymous; 17.12.2019 at 00:19.
Reply With Quote
  #1039  
Old 17.12.2019, 06:24
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

Quote:
Originally Posted by anonymous View Post
Thanks. I thought i needed some kind of regexpr trick at first. I've been searching for those "jd:" parameters but haven't had any luck.
You can also match/capture strings using regex by enabling the button at the end of the respective 'if' fields.

List of packagizer variables

Quote:
Originally Posted by anonymous View Post
Would it be possible to have it this apply to already downloaded items as well?
Packagizer rules are processed before the links are added to the linkgrabber. You will have to remove and add them back again. Use the context menu to copy the links to clipboard before removing them from the list.
Reply With Quote
  #1040  
Old 20.12.2019, 01:18
DieKatzchen DieKatzchen is offline
I will play nice!
 
Join Date: Dec 2019
Posts: 1
Default

Is there a way, using some combination of scripts and/or packagizer rules to convert the URL to a full path, e.g. **External links are only visible to Support Staff**... becomes C:\myfolder\foo\bar\file.zip? I almost had it with packagizer rules but it turned all the / into _ which is not what I want.
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 09:12.
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 - 2020, Jelsoft Enterprises Ltd.