#2801
|
|||
|
|||
Problem with callAPI /accounts/updateAccount?accountId&username&password
I'm trying to update an existing account via the Event Scripter from an imported text/csv file but unfortunately I get an error. For that I used more or less a combination of two script from this forum:
1. to import the file: https://board.jdownloader.org/showpo...postcount=1862 HTML Code:
var myfile = "/config/import/accounts.txt"; var newFilePath = "/config/import/processed"; var myFilePath = getPath(myfile); if (myFilePath.exists()) { try { readFile(myfile).trim().split("\r\n").forEach(function(item) { var substrings = item.split("\t"); var account = substrings[0]; var email = substrings[1]; var cookie = substrings[2]; callAPI("accounts", "addAccount", account, email, cookie); }); getPath(myfile).moveTo(newFilePath) } catch (e) { alert(e.message); } }; 2. to get the account id: https://board.jdownloader.org/showpo...18&postcount=3 HTML Code:
var myfile = "/config/import/accounts.txt";
if (myFilePath.exists()) {
try {
readFile(myfile).trim().split("\r\n").forEach(function(item) {
var substrings = item.split("\t");
var account = substrings[0];
var premiumAccounts = callAPI("accountsV2", "listAccounts", {});
for (i = 0; i < premiumAccounts.length; ++i) {
if (premiumAccounts[i].hostname.indexOf(account) > -1) {
var ids = [];
ids.push(premiumAccounts[i].uuid);
}
}
alert(callAPI("accounts", "getAccountInfo", ids));
});
getPath(myfile).moveTo(newFilePath)
} catch (e) {
alert(e.message);
}
};
As a side note: this still doesnt work, as mentioned by neygen in the above mentioned link: HTML Code:
var ids = new long[] {premiumAccounts[0].uuid}; HTML Code:
var ids = []; ids.push(premiumAccounts[0].uuid); Both scripts work on their own. So my final script for reading the file, parsing the values, getting the account id based on the host name in the file and then updating the respective account looks like that: HTML Code:
var myfile = "/config/import/accounts.txt";
var newFilePath = "/config/import/processed";
var myFilePath = getPath(myfile);
if (myFilePath.exists()) {
try {
readFile(myfile).trim().split("\r\n").forEach(function(item) {
var substrings = item.split("\t");
var account = substrings[0];
var email = substrings[1];
var cookie = substrings[2];
var premiumAccounts = callAPI("accountsV2", "listAccounts", {});
for (i = 0; i < premiumAccounts.length; ++i) {
if (premiumAccounts[i].hostname.indexOf(account) > -1) {
var ids = [];
ids.push(premiumAccounts[i].uuid);
}
}
var values=[ids, email, cookie];
// callAPI("accounts", "updateAccount", item.split("\t"));
callAPI("accounts", "updateAccount", ids, email, cookie);
// callAPI("accounts", "updateAccount", values);
});
getPath(myfile).moveTo(newFilePath)
} catch (e) {
alert(e.message);
}
};
HTML Code:
callAPI("accounts", "updateAccount", ids, email, cookie); HTML Code:
org.jdownloader.extensions.eventscripter.EnvironmentException: Line 20 org.appwork.remoteapi.exceptions.BadParameterException: BAD_PARAMETERS(ERROR_BAD_REQUEST) at org.jdownloader.api.RemoteAPIController.call(RemoteAPIController.java:779) at org.jdownloader.extensions.eventscripter.sandboxobjects.ScriptEnvironment.callAPI(ScriptEnvironment.java:232) at sun.reflect.GeneratedMethodAccessor531.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153) at net.sourceforge.htmlunit.corejs.javascript.NativeJavaMethod.call(NativeJavaMethod.java:213) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1536) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105) at net.sourceforge.htmlunit.corejs.javascript.NativeArray.iterativeMethod(NativeArray.java:1687) at net.sourceforge.htmlunit.corejs.javascript.NativeArray.execIdCall(NativeArray.java:405) at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:93) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1536) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411) at org.jdownloader.scripting.JSHtmlUnitPermissionRestricter$SandboxContextFactory.doTopCall(JSHtmlUnitPermissionRestricter.java:134) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3286) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115) at net.sourceforge.htmlunit.corejs.javascript.Context.evaluateString(Context.java:1361) at org.jdownloader.extensions.eventscripter.ScriptThread.evalUNtrusted(ScriptThread.java:344) at org.jdownloader.extensions.eventscripter.ScriptThread.executeScipt(ScriptThread.java:192) at org.jdownloader.extensions.eventscripter.ScriptThread.run(ScriptThread.java:172) Caused by: java.lang.ClassCastException
I do not know why it wont work in combination. Any help is appreciated. |
#2802
|
|||
|
|||
Quote:
if you see: Code:
ids (long[]) Code:
var ids = [object ids]; Also for namespace "updateAccount" the parameter is 'accountId (Long)', not 'array'. Instead of this, you can just use: Code:
var ids = [ids.push(premiumAccounts[0].uuid]; But in the case of 'updateAccounts' the parmeter should be 'long' not 'array' Quote:
In conclusion, would be easier for me to re-write the code block rather than try to troubleshoot it. Code:
readFile(myfile).trim().split("\r\n").forEach(function(item) { var [host, user, pass] = item.split("\\n"); callAPI("accountsV2", "listAccounts", {}).forEach(function(account) { if (account.hostname == host) { callAPI("accounts", "updateAccount", item.uuid, user, pass); } }); }) Perhaps you can fix your code based on the logic used in the above code block. |
#2803
|
|||
|
|||
Thanks @mgpai! I think I fixed it. Mainly I mixed up the "ids (List)" vs. "ids (Long[])".
|
#2804
|
||||
|
||||
@mgpai
Thanks once more for helping out! I assume that the user Docoakere is trying to build something which in the end will auto re-import current login-cookies for services where Cloudflare tends to kick in. Reference: https://board.jdownloader.org/showth...119#post531119
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#2805
|
|||
|
|||
My pleasure.
Shoule be possible to autmaitcally update it directly from browser by using MYJD API in userscript, eliminating the need to export/import it from text file using eventscripter script. |
#2806
|
||||
|
||||
Quote:
I'm sure Docoakere will come back to us regarding this topic.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#2807
|
|||
|
|||
Thanks for the help and the idea with MYJD API/broswer userscript. That sounds more efficient indeed. However I'm not a developer and my JS skills are minimal. I'll see what I can figure out with the help of GPT, Google and Trial-and-Error.
By briefly thinking about it the following things must be (probably) done in one way or another: (3. Might be optional but is maybe a good idea to prevent updating the account too often (resulting in unnecessary requests at the hoster), depending also on the trigger of when the script fires.) 1. Accessing & reading the local cookies by some trigger which I dont know yet 2. Filtering by domain name & cookie name 3. Storing the current values/datetime or the hash of it in an "own" cookie for later comparison (I don't know about any other way of storing data within a browser for later use) 4. Building the cookie json if the current cookies are newer then last version based on the hash of our "own" cookie 5. Sending the latest cookie json as password together with the correct account id and the user name/email via /accounts/updateAccount?accountId&username&password to JD If you have another approach or suggestions feel free to colaborate. |
#2808
|
||||
|
||||
* do not forget about periodically reloading specific URLs of the websites you want the cookies for to always have a current set of Cloudflare cookies.
Just as a side-hint: Using FlareSolverr might still be the better attempt.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#2809
|
|||
|
|||
> (3. Might be optional but is maybe a good idea to prevent updating the account too often (resulting in unnecessary requests at the hoster), depending also on the trigger of when the script fires.)
You can use "// @run-at context-menu" in greasemonkey/tampermonkey to run the userscript. > 1. Accessing & reading the local cookies by some trigger which I dont know yet By local if you mean browser cookies, they can be accessed using 'document.cookie' method. > 2. Filtering by domain name & cookie name This will not be necessary if you use run the userscript using context menu. > 3. Storing the current values/datetime or the hash of it in an "own" cookie for later comparison (I don't know about any other way of storing data within a browser for later use) Not necessary to compare. Just run the script from context menu when you want to update the cookies in JD. > 4. Building the cookie json if the current cookies are newer then last version based on the hash of our "own" cookie Use the for/forEach loop on document.cookie to convert it to json format. > 5. Sending the latest cookie json as password together with the correct account id and the user name/email via /accounts/updateAccount?accountId&username&password to JD Pretty much similar to what is done in eventscripter. You have to enable deprecated API in JD and make the same request to localhost in userscript. Using a injection method other than '@run-at ' will not result in any additional request. While comparision is not required, you can limit the account update frequency by checking the account status (for error relating to cookies) at reqular intervals, and only then make a API request to update it. If fully automated you can use for e.g. '// @include *://www.mysite.com/*" to run on specific sites. |
#2810
|
||||
|
||||
Addendum:
I don't know if browser addons can provide internal APIs but as for getting the cookies and getting them in a supported json format, the easiest way would be if FlagCookies or EditThisCookie would provide a single line method to get all cookies of the currently open tab programmatically. I'am not into that topic at all but it might be worth looking into this and/or even asking the developer of such a browser addon e.g. public support thread of browser addon "FlagCookies": ngb.to/threads/addon-ff-gc-o-e-flagcookies.32496/ github: github.com/jrie/flagCookies/issues
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#2811
|
|||
|
|||
Thanks for the input to both of you. Yeah, I read about FlareSolverr multiple times in this forum. I don't expect a guide on how to setup and configure it but just to sort things out I have a question about how the interaction with JD could look like.
What I found out about FS: Other then a "normal" proxy FS does not just tunnel the requests but rather act as a client which calls the website using a browser, solves the CF challenge and returns a json-like object with different information including the cookies and userAgent: HTML Code:
{ "status": "ok", "message": "Challenge solved!", "solution": { "url": "**External links are only visible to Support Staff**, "status": 200, "cookies": [ { "domain": "www.petsathome.com", "httpOnly": false, "name": "WC_MOBILEDEVICEID", "path": "/", "secure": false, "value": "0" }, { "domain": ".petsathome.com", "expiry": 1673531559, "httpOnly": false, "name": "FPLC", "path": "/", "secure": true, "value": "k03jwEFLbwxG2InqkF8yDy5%2BxWFeypsVETpfQGAFNO9M33HudoClDsp%2FY9BH89yLrGpQRLYL2WCgOkBrWRwdcK%2BycvG8%2F3m3SjDu3ZDXXHodwcxEhm4fQo7x8G%2BMrw%3D%3D" }, ... ], "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", "headers": {}, "response": "<html><head>...</head><body>...</body></html>" }, "startTimestamp": 1673459546891, "endTimestamp": 1673459560345, "version": "3.0.2" } Do I miss something? Is JD capable of calling FS direclty and doing the response handling itself? If so I guess it needs to be within the Event Scripter. Last edited by Docoakere; 07.03.2024 at 19:23. |
#2812
|
||||
|
||||
Quote:
Then let's put it this way: If it was possible to integrate FlareSolverr as a"normal" proxy, all you'd need to do is to set it up and add it as a proxy in JD. Just by the first glance on their readme, it looks like it does provide said proxy functionality: github.com/FlareSolverr/FlareSolverr I won't take a deep-dive here since I'm providing JD support here, not support to setup 3rd party tools If I misunderstood the concept of FlareSolverr I'm sorry. I will leave it in the Cloudflare FAQ either way since it is a helpful tool which can be used to solve Cloudflare related problems.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download Last edited by pspzockerscene; 07.03.2024 at 18:46. Reason: Fixed typo |
#2813
|
|||
|
|||
Hi,
if very long tracks have chaptermarks, is it possible to cut the file at the same time? So that we get all the songs contained as individual tracks? |
#2814
|
|||
|
|||
The URL to the updates? Which one is it?
__________________
Aktuelles Windows |
#2815
|
|||
|
|||
Dear mgpai,
a few years back you helped me with a wonderful script,, which let me start videos straight out of JD with one click in the context menu. ... it worked like a charm for all these years. :-) But now, with a new OS, I need to start the player scaled down with: HTML Code:
export QT_SCALE_FACTOR=.6 ; smplayer I suppose the "var player" needs a little change, but my trials were not succesful. This is the original script: HTML Code:
if (name == "Play") { var player = "/usr/bin/smplayer"; dlSelection.getLinks().filter(function(link) { return link.getBytesLoaded(); }).forEach(function(link) { var file = link.getDownloadPath(); file = link.isFinished() ? file : file + ".part"; callSync(player, file); }) } |
#2816
|
|||
|
|||
Oh, I found a solution:
Just call JD itself with the scale factor. It does not respect it (unfortunately) but at least it passes it on to its child-processes: HTML Code:
export QT_SCALE_FACTOR=.6 ; java -jar JDownloader.jar |
#2817
|
|||
|
|||
Quote:
Code:
callSync("QT_SCALE_FACTOR=.6", player, file); |
#2818
|
|||
|
|||
Unfortunately this does not work. The error message is:
HTML Code:
Wrapped org.jdownloader.extensions.eventscripter.EnvironmentException: Line 9 java.io.IOException: Cannot run program "QT_SCALE_FACTOR=.6": error=2, Datei oder Verzeichnis nicht gefunden I tried several things in place of "callSync(player, file);" ... but without success, like: HTML Code:
Files.writeString(Path.of("filename.txt"), "file"); HTML Code:
PrintWriter out = new PrintWriter("filename.txt"); out.println(file); out.close(); |
#2819
|
|||
|
|||
Quote:
I guess the qt parameter should be preceded by interpreter or other parameters. In any case, it is not necessary to write the path to a text file. You can call the terminal command directly using callsync and pass the file path to it as a parameter. So also with a script. Code:
callSync(binary, parameter1, parameter2, file); or callSync(myscript.sh, file); Code:
var myFile = getPath("/preview.txt"); myFile.delete(); writeFile(myFile,file,false); |
#2820
|
|||
|
|||
Ah, thank you very much, mgpai!
I testet both, calling it directly and writing it to a text-file. Both works perfectly! I learned quite a bit here. Thanks, mate! :-) |
#2821
|
|||
|
|||
Script that marks ne / certain hosters in one or more packages in the download window
This would be great: a script that marks (e.g with the context menu after right clicking) one / certain hosters in one or more packages in the download window?
https://board.jdownloader.org/showth...952#post531952
__________________
Aktuelles Windows |
#2822
|
|||
|
|||
What action do you want to perform after selecting them? You can also just set the search filter at the bottom to "Hoster" and type the host(s) name in the search field.
|
#2823
|
|||
|
|||
Yes, for one hoster at a time (I believe).
For example set / change priorities, (de)activate (a) special hoster(s). (De)activate sound notification. So maybe the script would just allow to do a right click on a special hoster and in the context menu one could choose to mark that hoster or to mark other hosters of the same package as well. Or one marked two or more packages and could choose to select special hosters of these packages.
__________________
Aktuelles Windows |
#2824
|
|||
|
|||
Quote:
For your use case the best option is to use the search filter at the bottom of the donwload tab. Select' hoster' and type the hostname(s) you want to filter. |
#2825
|
||||
|
||||
I could provide api methods for this
__________________
JD-Dev & Server-Admin |
#2826
|
|||
|
|||
Give me the place to stand, and I shall move the earth. - Archimedes
|
#2827
|
|||
|
|||
Maybe moving JD a little bit would be enough (at the moment). - Dockel
But if it is too much work I absolutely could understand...so I would go on using the search filter...
__________________
Aktuelles Windows |
#2828
|
|||
|
|||
[Request]
I need a script to trigger a url when there's a new captcha to solve. I'm using a headless JD on a linux server if that matters. Thanks in advance. EDIT: nevermind, found it in the help file. Last edited by HughJazz; 20.03.2024 at 23:52. |
#2829
|
|||
|
|||
Switch the larger one between two versions of videos
I need a script to switch the larger one between two versions (mp4 and mkv) of videos from YouTube to put in linkgrabber, as lower compression tend to result in larger file sizes.
|
#2830
|
||||
|
||||
@Mesenzio: mkv with vp9 or av1 has much better quality as h264 in mp4 container.
__________________
JD-Dev & Server-Admin |
#2831
|
|||
|
|||
how do you use/what do you use "myBrowser.getDownload(myString, myString);" for?
is it for adding download links to the linkgrabber? what does it take as arguments? I am currently trying to use myBrowser.setHeader() to get through a cloudflare protected site, I am successful in getting the browser object to bypass it, but using callAPI linkgrabberv2 to add link to list gets blocked so I am stuck. |
#2832
|
|||
|
|||
Quote:
Code:
myBrowser.getDownload(savePath, url); If the final link is behind cf protection, adding it via api will not work since JD will use a different browser instance, with different cookies. While 'getDownload' can be used, it might not be practical to download many/large files. If you add the cookies to a linkcrawler rule, adding links via API might work, since JD will then use those cookies to crawl/download them. |
#2833
|
|||
|
|||
Quote:
This is a website for which a JD plugin already exist, so as I understand I cannot use linkcrawler rules in that case, Is this correct? or am I misunderstanding what you meant? In any case, can I ask how to write the cookies? or, where I can learn the syntax of writing cookies the only line I needed to add for using scripter was myBrowser.setHeader("Origin", "/*the site host link*/"); Last edited by hideas; 23.03.2024 at 08:23. |
#2834
|
|||
|
|||
Quote:
Thanks for the response. In some cases .mkv files are not present, so I would need a script that normally filters mp4 but lets them in when .mkv are not found. |
#2835
|
|||
|
|||
In case anyone else is interested or need to pass headers, I snooped around for solutions for a bit and just ended up using a script to call an external app ytdlp that can add headers to handle what I wanted. you can make it more seamless than I thought (can trigger at the same time as the JD grabber list, save to the same folder you want etc.) only drawback is you cannot track download status because it runs in the background so i just made it do alert(package + " done"); when it is done
|
#2836
|
|||
|
|||
Getting an odd error in a couple of my scripts.
The jscore runtime is throwing "Cannot call method `indexOf` on null (#10)" I have several scripts all following the same pattern, but the full script for this case is at: pastebin com ivTZxkm9 Code:
if (isDownloadControllerRunning() && !isDownloadControllerStopping()) { var candidates = getAllDownloadLinks().filter(function(dl) { return dl.getStatus() != null && dl.isEnabled() && (dl.getStatus().indexOf('found') === -1) && ( // <-- line 10 Code:
dl.getStatus() != null && dl.isEnabled() && (dl.getStatus().indexOf('found') === -1) |
#2837
|
||||
|
||||
@hideas: Can you provide example links and headers you used to bypass cloudflare/to make it work in JDownloader. Then we can check/update JDownloader. Also it might be possible to customize headers for links you want to download but for that we need example links. Either post here ot send to support@jdownloader.org
__________________
JD-Dev & Server-Admin |
#2838
|
||||
|
||||
@mwl: you should store dl.getStatus in variable and then process on it. because of timing, the dl.getStatus still might be != null but just the next moment it returns null and dl.getStatus.indexOf will fail because now it's null. many of those get methods are live
__________________
JD-Dev & Server-Admin |
#2839
|
||||
|
||||
@Jiaz
The best solution would be to add the ability to add headers via LinkCrawler rules because this is what is definitely missing.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#2840
|
|||
|
|||
Quote:
and header used was "Origin: **External links are only visible to Support Staff** |
Thread Tools | |
Display Modes | |
|
|