Completely reformatted PahealRipper; add missing braces.
This commit is contained in:
parent
d2a4412a85
commit
56093cc1ad
@ -21,18 +21,14 @@ import org.jsoup.nodes.Document;
|
|||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
/**
|
public class PahealRipper extends AbstractHTMLRipper {
|
||||||
*
|
private static Map<String, String> cookies = null;
|
||||||
* @author
|
private static Pattern gidPattern = null;
|
||||||
*/
|
|
||||||
public class PahealRipper extends AbstractHTMLRipper{
|
|
||||||
private static Map<String,String> cookies=null;
|
|
||||||
private static Pattern gidPattern=null;
|
|
||||||
|
|
||||||
private static Map<String, String> getCookies() {
|
private static Map<String, String> getCookies() {
|
||||||
if(cookies==null){
|
if (cookies == null) {
|
||||||
cookies=new HashMap<String, String>(1);
|
cookies = new HashMap<String, String>(1);
|
||||||
cookies.put("ui-tnc-agreed","true");
|
cookies.put("ui-tnc-agreed", "true");
|
||||||
}
|
}
|
||||||
return cookies;
|
return cookies;
|
||||||
}
|
}
|
||||||
@ -53,26 +49,28 @@ public class PahealRipper extends AbstractHTMLRipper{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document getFirstPage() throws IOException {
|
public Document getFirstPage() throws IOException {
|
||||||
return Http.url("http://rule34.paheal.net/post/list/"+getTerm(url)+"/1").cookies(getCookies()).get();
|
return Http.url("http://rule34.paheal.net/post/list/" + getTerm(url) + "/1").cookies(getCookies()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document getNextPage(Document page) throws IOException {
|
public Document getNextPage(Document page) throws IOException {
|
||||||
for(Element e:page.select("#paginator a")){
|
for (Element e : page.select("#paginator a")) {
|
||||||
if(e.text().toLowerCase().equals("next"))
|
if (e.text().toLowerCase().equals("next")) {
|
||||||
return Http.url(e.absUrl("href")).cookies(getCookies()).get();
|
return Http.url(e.absUrl("href")).cookies(getCookies()).get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getURLsFromPage(Document page) {
|
public List<String> getURLsFromPage(Document page) {
|
||||||
Elements elements=page.select(".shm-thumb.thumb>a").not(".shm-thumb-link");
|
Elements elements = page.select(".shm-thumb.thumb>a").not(".shm-thumb-link");
|
||||||
List<String> res=new ArrayList<String>(elements.size());
|
List<String> res = new ArrayList<String>(elements.size());
|
||||||
|
|
||||||
for(Element e:elements)
|
for (Element e : elements) {
|
||||||
res.add(e.absUrl("href"));
|
res.add(e.absUrl("href"));
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -80,16 +78,20 @@ public class PahealRipper extends AbstractHTMLRipper{
|
|||||||
@Override
|
@Override
|
||||||
public void downloadURL(URL url, int index) {
|
public void downloadURL(URL url, int index) {
|
||||||
try {
|
try {
|
||||||
String name=url.getPath();
|
String name = url.getPath();
|
||||||
String ext=".png";
|
String ext = ".png";
|
||||||
|
|
||||||
name=name.substring(name.lastIndexOf('/')+1);
|
name = name.substring(name.lastIndexOf('/') + 1);
|
||||||
if(name.indexOf('.')>=0){
|
if (name.indexOf('.') >= 0) {
|
||||||
ext=name.substring(name.lastIndexOf('.'));
|
ext = name.substring(name.lastIndexOf('.'));
|
||||||
name=name.substring(0,name.length()-ext.length());
|
name = name.substring(0, name.length() - ext.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
addURLToDownload(url,new File(workingDir.getCanonicalPath()+File.separator+Utils.filesystemSafe(new URI(name).getPath())+ext));
|
File outFile = new File(workingDir.getCanonicalPath()
|
||||||
|
+ File.separator
|
||||||
|
+ Utils.filesystemSafe(new URI(name).getPath())
|
||||||
|
+ ext);
|
||||||
|
addURLToDownload(url, outFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
@ -97,15 +99,17 @@ public class PahealRipper 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\\.)?rule34\\.paheal\\.net/post/list/([a-zA-Z0-9$_.+!*'(),%-]+)(/.*)?(#.*)?$");
|
gidPattern = Pattern.compile("^https?://(www\\.)?rule34\\.paheal\\.net/post/list/([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(2);
|
return m.group(2);
|
||||||
|
}
|
||||||
|
|
||||||
throw new MalformedURLException("Expected paheal.net URL format: rule34.paheal.net/post/list/searchterm - got "+url+" instead");
|
throw new MalformedURLException("Expected paheal.net URL format: rule34.paheal.net/post/list/searchterm - got " + url + " instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,7 +120,6 @@ public class PahealRipper extends AbstractHTMLRipper{
|
|||||||
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MalformedURLException("Expected paheal.net URL format: rule34.paheal.net/post/list/searchterm - got "+url+" instead");
|
throw new MalformedURLException("Expected paheal.net URL format: rule34.paheal.net/post/list/searchterm - got " + url + " instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user