I downloaded jdownloader to try and figure this out, what I found out, is that the undefined error with XMLHttpRequest
is most likely caused by htmlunit being outdated, I don’t know enough about htrmlunit to help you resolve it, my best guess would be that jdownloader has it built into their software and it would be up to the developer to fix this.
I also tried to use postPage to access sonarr via the api, without the apikey, as you would expect, it throws the “unauthorized error”, so I knew I was able to connect, I then tried to include the apikey.
postPage("sonarr_url","apikey=key");
But I still received the same unauthorized error, at first I assumed I did something wrong, and tested the url in my browser, I was able to gain access, so I did the following.
postPage("sonarr_url?apikey=key");
this wont work.
postPage("sonarr_url?apikey=key","data=jsondata");
this throws error.
no matter what I try, I am unable to gain access to sonarr’s api, and when I come close to a solution I receive java errors.
So here are the only possible solutions to this issue, that I can think off.
-
Go to JDforums and post your xmlhttp errors there, hopefully someone will have a solution, which will most likely be to create a custom plugin.
-
Create or ask someone to create a custom plugin.
-
Execute an external script to do the job for you.
I found that rednoah from filebot created such a script, so I tried to Frankenstein my own out of his script, since it’s pretty much doing what you want, the downside to this, is that it requires two external scripts because we can only send commands to a .cmd file without it throwing errors and since we can’t use the command line to connect to sonarr’s API, this forces us to use another script, in this case, I used a snippet from my VBScript, but you can use python or any other alternative, this is purely an example, the code was tested within event scripter using Test Run.
In JDownloader, create an event scripter with the trigger “Package_finished”, and place the following code within.
var script = "sonarr.cmd"
var path = package.getDownloadFolder()
var links = package.getDownloadLinks() ? package.getDownloadLinks() : []
function isReallyFinished() {
for (var i = 0; i < links.length; i++) {
if (links[i].getArchive() != null && links[i].getExtractionStatus() != "SUCCESSFUL" || !package.isFinished()) {
return false
}
}
return true
}
if (isReallyFinished()) {
var command = [script, path, 'PACKAGE_FINISHED']
log(command)
log(callSync(command))
}
Next create another event script, with a trigger called “Archived extraction finnished”, and place in the following code.
var script = "sonarr.cmd"
var package = archive.getDownloadLinks() ? archive.getDownloadLinks()[0].getPackage() : null
var links = package ? package.getDownloadLinks() : []
function isReallyFinished() {
for (var i = 0; i < links.length; i++) {
if (links[i].getArchive() != null && links[i].getExtractionStatus() != "SUCCESSFUL" || !package.isFinished()) {
return false
}
}
return true
}
if (package && isReallyFinished()) {
var command = [script, package.getDownloadFolder()]
log(command)
log(callSync(command))
}
Now create a file called sonarr.cmd and place in the following code cscript sonarr.vbs "%~1"
Finally we create another script called sonarr.vbs and place the following within.
Dim Jstr: Jstr = "{""name"": ""DownloadedEpisodesScan"", ""path"": """ & WScript.Arguments(0) & """, ""importMode"": ""Move""}"
Dim URL: URL = "sonar_url_here"
Dim xmlhttp: Set xmlhttp = createobject("msxml2.xmlhttp.3.0")
xmlhttp.Open "POST", URL & "/api/command", false
xmlhttp.setRequestHeader "X-Api-Key", "API KEY HERE"
xmlhttp.send Replace(Jstr, "\", "\\")
Lastly, you will need to place both sonarr.cmd and sonarr.vbs into the jd home folder, for me this was in, C:\Users\Username\AppData\Local\JDownloader 2.0
, you don’t actually have to place the vbs in the same folder, since you can change the location in sonarr.cmd, but I always find it best to keep all the scripts together.
Also I found that the developers of JDownloader have no plans at this time to provide any sort of support for sonarr, so unfortunatly I believe this may be the only workable method.