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,80 +17,79 @@ 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;
/** public class XbooruRipper extends AbstractHTMLRipper {
* private static Pattern gidPattern = null;
* @author
*/
public class XbooruRipper extends AbstractHTMLRipper{
private static Pattern gidPattern=null;
public XbooruRipper(URL url) throws IOException { public XbooruRipper(URL url) throws IOException {
super(url); super(url);
} }
@Override @Override
public String getDomain() { public String getDomain() {
return "xbooru.com"; return "xbooru.com";
} }
@Override @Override
public String getHost() { public String getHost() {
return "xbooru"; return "xbooru";
} }
private String getPage(int num) throws MalformedURLException{
return "http://xbooru.com/index.php?page=dapi&s=post&q=index&pid="+num+"&tags="+getTerm(url);
}
@Override private String getPage(int num) throws MalformedURLException {
public Document getFirstPage() throws IOException { return "http://xbooru.com/index.php?page=dapi&s=post&q=index&pid=" + num + "&tags=" + getTerm(url);
return Http.url(getPage(0)).get(); }
}
@Override @Override
public Document getNextPage(Document doc) throws IOException { public Document getFirstPage() throws IOException {
int offset=Integer.parseInt(doc.getElementsByTag("posts").first().attr("offset")); return Http.url(getPage(0)).get();
int num=Integer.parseInt(doc.getElementsByTag("posts").first().attr("count")); }
if(offset+100>num)
return null;
return Http.url(getPage(offset/100+1)).get();
}
@Override @Override
public List<String> getURLsFromPage(Document page) { public Document getNextPage(Document doc) throws IOException {
List<String> res=new ArrayList<String>(100); int offset = Integer.parseInt(doc.getElementsByTag("posts").first().attr("offset"));
for(Element e:page.getElementsByTag("post")) int num = Integer.parseInt(doc.getElementsByTag("posts").first().attr("count"));
res.add(e.absUrl("file_url")+"#"+e.attr("id"));
return res;
}
@Override if (offset + 100 > num) {
public void downloadURL(URL url, int index) { return null;
addURLToDownload(url,Utils.getConfigBoolean("download.save_order",true)?url.getRef()+"-":""); }
}
private String getTerm(URL url) throws MalformedURLException{
if(gidPattern==null)
gidPattern=Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(\\&|(#.*)?$)");
Matcher m = gidPattern.matcher(url.toExternalForm()); return Http.url(getPage(offset / 100 + 1)).get();
if(m.matches()) }
return m.group(4);
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got "+url+" instead");
}
@Override @Override
public String getGID(URL url) throws MalformedURLException { public List<String> getURLsFromPage(Document page) {
try { List<String> res = new ArrayList<String>(100);
return Utils.filesystemSafe(new URI(getTerm(url)).getPath()); for (Element e : page.getElementsByTag("post")) {
} catch (URISyntaxException ex) { res.add(e.absUrl("file_url") + "#" + e.attr("id"));
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex); }
} return res;
}
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got "+url+" instead");
} @Override
public void downloadURL(URL url, int index) {
addURLToDownload(url, Utils.getConfigBoolean("download.save_order", true) ? url.getRef() + "-" : "");
}
private String getTerm(URL url) throws MalformedURLException {
if (gidPattern == null) {
gidPattern = Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(\\&|(#.*)?$)");
}
Matcher m = gidPattern.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(4);
}
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead");
}
@Override
public String getGID(URL url) throws MalformedURLException {
try {
return Utils.filesystemSafe(new URI(getTerm(url)).getPath());
} catch (URISyntaxException ex) {
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
}
throw new MalformedURLException("Expected xbooru.com URL format: xbooru.com/index.php?tags=searchterm - got " + url + " instead");
}
} }