blob: 3c785224202e53e5a917455a07333eabb05f8b97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package net.tylermurphy.ken.api;
import net.tylermurphy.ken.api.wrapper.HTTPMethod;
import net.tylermurphy.ken.api.wrapper.XmlRequest;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Rule34API {
public static String request(String query){
Document doc = (Document) new XmlRequest()
.setURL("https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags="+ query)
.setType(HTTPMethod.GET)
.request();
try {
NodeList nList = doc.getElementsByTagName("post");
int choice = (int) (Math.random()*nList.getLength()-1);
if(choice < 0) return null;
Node node = nList.item(choice);
Element element = (Element) node;
return element.getAttribute("file_url");
} catch (JSONException e) {
return null;
}
}
}
|