|
1 | 1 | # JDHttpAPI |
2 | 2 | JDownloader2 plugin with a local HTTP API to add new files for download |
| 3 | + |
| 4 | +This plugin is loaded by JDownloader2, which then starts up an embedded Jetty |
| 5 | +HTTP server to receive |
| 6 | + |
| 7 | +From there, just about anything can send requests to queue up a new link. I |
| 8 | +like to use [Tampermonkey userscripts](https://tampermonkey.net/) to scrape |
| 9 | +links directly from web pages as I browse. |
| 10 | + |
| 11 | +Note: it binds to your IP address, therefore other PCs on the network can add |
| 12 | +links. Configure a password or update the code to bind to something else - |
| 13 | +there is not currently a way configure local-only access. This plugin also |
| 14 | +accepts all Origins over ajax. |
| 15 | + |
| 16 | +## Install |
| 17 | + |
| 18 | +1. Close JDownloader. |
| 19 | +2. Build or download the `JDHttpApi.jar` file. |
| 20 | +3. Place that file in `./extensions/` inside the JDownloader2 program folder. |
| 21 | +3. Open the file `./tmp/extensioncache/extensionInfos.json` in your JD program |
| 22 | + folder and insert the following JSON as a new element in the array: |
| 23 | + |
| 24 | +``` |
| 25 | +{ |
| 26 | + "settings" : true, |
| 27 | + "configInterface" : "org.jdownloader.extensions.httpAPI.HttpAPIConfig", |
| 28 | + "quickToggle" : false, |
| 29 | + "headlessRunnable" : true, |
| 30 | + "description" : "Http API.", |
| 31 | + "lng" : "en_US", |
| 32 | + "iconPath" : "folder_add", |
| 33 | + "linuxRunnable" : true, |
| 34 | + "macRunnable" : true, |
| 35 | + "name" : "HTTP API", |
| 36 | + "version" : -1, |
| 37 | + "windowsRunnable" : true, |
| 38 | + "classname" : "org.jdownloader.extensions.httpAPI.HttpAPIExtension", |
| 39 | + "jarPath" : "/absolute/path/to/jd2/extensions/JDHttpApi.jar" |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +4. Open the file `./update/versioninfo/JD/extensions.installed.json` inside the |
| 44 | + JD program folder and insert the string `"jdhttpapi"` as the last element |
| 45 | + in the JSON array. |
| 46 | +5. Start JDownloader2 and go to the settings page to enable the extension. |
| 47 | + |
| 48 | +Note: there is no official extension install process, so most of this is |
| 49 | +tricking JD into thinking the JAR is already installed. It's possible that |
| 50 | +an update will trigger a cache invalidation that boots out this extension. Just |
| 51 | +reapply the steps above and you should get it back. |
| 52 | + |
| 53 | +## Configure |
| 54 | + |
| 55 | +This plugin has four settings to configure through the JDownloader GUI. In order |
| 56 | +to make changes take effect, disable and then re-enable the extension. |
| 57 | + |
| 58 | +1. Use a password: require password authentication. |
| 59 | +2. Port: the port that the HTTP server listens on. Defaults to 8297. |
| 60 | +3. Password: If you've enabled the password feature, set it here. |
| 61 | +4. Allow Get: This disables HTTP GET access to the API. When enabled, you |
| 62 | + must POST new links as JSON. This can help you reduce exposure to CSRF |
| 63 | + vulnerabilities, especially when combined with a password. |
| 64 | + |
| 65 | +## Use |
| 66 | + |
| 67 | +There is currently only one URL: `/addLink`. You may submit via POST or GET. |
| 68 | + |
| 69 | +### GET Service |
| 70 | + |
| 71 | +There are three parameters, only `url` is required: |
| 72 | + |
| 73 | +* `url`: The URL to add. |
| 74 | +* `packageName`: If you want to configure a custom package name, send it here. |
| 75 | +* `forcePackageName`: Set this to `true` to set the package name. For whatever |
| 76 | + reason, this is a separate field in JD's internals but if you don't force |
| 77 | + it, the package name will not be changed. It's possible I am hooking in too |
| 78 | + late in the process. |
| 79 | + |
| 80 | +The response has three possible values: |
| 81 | + |
| 82 | +On success: `{"success":true}` |
| 83 | +On malformed input: `{"errorMessage":"some error message"}` |
| 84 | +On authentication failure: `Login to access API` (this is not JSON) |
| 85 | + |
| 86 | +CURL Examples: |
| 87 | + |
| 88 | +``` |
| 89 | +curl 'http://localhost:8297/addLink?url=https://i.imgur.com/muChjiN.jpg' |
| 90 | +curl 'http://localhost:8297/addLink?url=https://i.imgur.com/muChjiN.jpg&packageName=cutebunny&forcePackageName=true' |
| 91 | +``` |
| 92 | + |
| 93 | +### POST Service |
| 94 | + |
| 95 | +Send a JSON object via POST with the same values as in the GET request: |
| 96 | + |
| 97 | +``` |
| 98 | +curl -X POST 'http://localhost:8297/addLink' \ |
| 99 | + -d '{"url":"https://i.imgur.com/muChjiN.jpg"}' |
| 100 | +curl -X POST 'http://localhost:8297/addLink' \ |
| 101 | + -d '{"url":"https://i.imgur.com/muChjiN.jpg","packageName":"cutebunny","forcePackageName":true}' |
| 102 | +``` |
| 103 | + |
| 104 | +### Authentication |
| 105 | + |
| 106 | +If you choose to use a password, send it as the password portion of HTTP Basic |
| 107 | +Authentication - leave the username blank. |
| 108 | + |
| 109 | +CURL Example: |
| 110 | + |
| 111 | +``` |
| 112 | +curl -u ':mypassword' 'http://192.168.1.7:8297/addLink?url=https://i.imgur.com/muChjiN.jpg' |
| 113 | +curl -u ':mypassword' -X POST 'http://localhost:8297/addLink' \ |
| 114 | + -d '{"url":"https://i.imgur.com/muChjiN.jpg"}' |
| 115 | +``` |
| 116 | + |
| 117 | +## Errata |
| 118 | + |
| 119 | +JDownloader2's extension system is surprisingly |
| 120 | +modular and easy to understand (aside from the install process). Feel free to |
| 121 | +use this project as an example for building other JD extensions as even the |
| 122 | +built-in ones are a bit more complex than this. Just make sure to have |
| 123 | +[the source code](https://svn.jdownloader.org/projects/jd) open up in |
| 124 | +another window for reference - there is virtually no documentation available |
| 125 | +and this project only uses the bare minimum of features. |
| 126 | + |
| 127 | + |
0 commit comments