Skip to content

Commit 844fd4e

Browse files
committed
First commit
1 parent dbf8197 commit 844fd4e

33 files changed

Lines changed: 864 additions & 0 deletions

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@
2020

2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
23+
24+
.idea/workspace.xml
25+
.idea/**/gradle.xml
26+
.idea/**/libraries
27+
.idea/**/dataSources/
28+
.idea/**/dataSources.ids
29+
.idea/**/dataSources.xml
30+
.idea/**/dataSources.local.xml
31+
.idea/**/sqlDataSources.xml
32+
.idea/**/dynamic.xml
33+
.idea/**/uiDesigner.xml
34+
.idea/**/workspace.xml
35+
.idea/**/tasks.xml
36+
.idea/dictionaries
37+
.idea_modules/

.idea/artifacts/JDHttpApi_jar.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Core.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JDHttpApi.iml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Core" level="project" />
15+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.7.v20170914" level="project" />
16+
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
17+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.7.v20170914" level="project" />
18+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.7.v20170914" level="project" />
19+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.7.v20170914" level="project" />
20+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" />
21+
</component>
22+
</module>

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,127 @@
11
# JDHttpAPI
22
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+

lib/Core.jar

7.57 MB
Binary file not shown.

0 commit comments

Comments
 (0)