Completely reformatted XbooruRipper; add missing braces.

This commit is contained in:
MetaPrime 2017-05-09 15:40:11 -07:00
parent 56093cc1ad
commit c75aad47d4

View File

@ -1,4 +1,3 @@
package com.rarchives.ripme.ripper.rippers; package com.rarchives.ripme.ripper.rippers;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
@ -18,10 +17,6 @@ import java.util.regex.Pattern;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
/**
*
* @author
*/
public class XbooruRipper extends AbstractHTMLRipper { public class XbooruRipper extends AbstractHTMLRipper {
private static Pattern gidPattern = null; private static Pattern gidPattern = null;
@ -53,8 +48,9 @@ public class XbooruRipper extends AbstractHTMLRipper{
int offset = Integer.parseInt(doc.getElementsByTag("posts").first().attr("offset")); int offset = Integer.parseInt(doc.getElementsByTag("posts").first().attr("offset"));
int num = Integer.parseInt(doc.getElementsByTag("posts").first().attr("count")); int num = Integer.parseInt(doc.getElementsByTag("posts").first().attr("count"));
if(offset+100>num) if (offset + 100 > num) {
return null; return null;
}
return Http.url(getPage(offset / 100 + 1)).get(); return Http.url(getPage(offset / 100 + 1)).get();
} }
@ -62,8 +58,9 @@ public class XbooruRipper extends AbstractHTMLRipper{
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> res = new ArrayList<String>(100); List<String> res = new ArrayList<String>(100);
for(Element e:page.getElementsByTag("post")) for (Element e : page.getElementsByTag("post")) {
res.add(e.absUrl("file_url") + "#" + e.attr("id")); res.add(e.absUrl("file_url") + "#" + e.attr("id"));
}
return res; return res;
} }
@ -73,12 +70,14 @@ public class XbooruRipper extends AbstractHTMLRipper{
} }
private String getTerm(URL url) throws MalformedURLException { private String getTerm(URL url) throws MalformedURLException {
if(gidPattern==null) if (gidPattern == null) {
gidPattern = Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(\\&|(#.*)?$)"); gidPattern = Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(\\&|(#.*)?$)");
}
Matcher m = gidPattern.matcher(url.toExternalForm()); Matcher m = gidPattern.matcher(url.toExternalForm());
if(m.matches()) if (m.matches()) {
return m.group(4); return m.group(4);
}
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead"); throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead");
} }
@ -93,5 +92,4 @@ public class XbooruRipper extends AbstractHTMLRipper{
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead"); throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead");
} }
} }