ImgScroll/src/main/java/com/rarchives/ripme/ripper/rippers/HentaifoundryRipper.java

113 lines
3.7 KiB
Java
Raw Normal View History

2014-06-17 10:39:49 +02:00
package com.rarchives.ripme.ripper.rippers;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
2014-06-17 10:39:49 +02:00
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http;
2014-06-17 10:39:49 +02:00
public class HentaifoundryRipper extends AbstractHTMLRipper {
2014-06-17 10:39:49 +02:00
private Map<String,String> cookies = new HashMap<String,String>();
2014-06-17 10:39:49 +02:00
public HentaifoundryRipper(URL url) throws IOException {
super(url);
}
@Override
public String getHost() {
return "hentai-foundry";
}
@Override
public String getDomain() {
return "hentai-foundry.com";
2014-06-17 10:39:49 +02:00
}
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^.*hentai-foundry\\.com/pictures/user/([a-zA-Z0-9\\-_]+).*$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
throw new MalformedURLException(
"Expected hentai-foundry.com gallery format: "
+ "hentai-foundry.com/pictures/user/USERNAME"
+ " Got: " + url);
2014-06-17 10:39:49 +02:00
}
@Override
public Document getFirstPage() throws IOException {
Response resp = Http.url("http://www.hentai-foundry.com/").response();
cookies = resp.cookies();
resp = Http.url("http://www.hentai-foundry.com/?enterAgree=1&size=1500")
.referrer("http://www.hentai-foundry.com/")
.cookies(cookies)
.response();
cookies.putAll(resp.cookies());
sleep(500);
resp = Http.url(url)
.referrer("http://www.hentai-foundry.com/")
.cookies(cookies)
.response();
cookies.putAll(resp.cookies());
return resp.parse();
}
@Override
public Document getNextPage(Document doc) throws IOException {
if (doc.select("li.next.hidden").size() > 0) {
// Last page
throw new IOException("No more pages");
}
Elements els = doc.select("li.next > a");
Element first = els.first();
String nextURL = first.attr("href");
nextURL = "http://www.hentai-foundry.com" + nextURL;
return Http.url(nextURL)
.referrer(url)
.cookies(cookies)
.get();
}
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>();
Pattern imgRegex = Pattern.compile(".*/user/([a-zA-Z0-9\\-_]+)/(\\d+)/.*");
for (Element thumb : doc.select("td > a:first-child")) {
2014-06-17 10:39:49 +02:00
if (isStopped()) {
break;
}
Matcher imgMatcher = imgRegex.matcher(thumb.attr("href"));
if (!imgMatcher.matches()) {
logger.info("Couldn't find user & image ID in " + thumb.attr("href"));
continue;
2014-06-17 10:39:49 +02:00
}
String user = imgMatcher.group(1),
imageId = imgMatcher.group(2);
String image = "http://pictures.hentai-foundry.com//";
image += user.toLowerCase().charAt(0);
image += "/" + user + "/" + imageId + ".jpg";
imageURLs.add(image);
2014-06-17 10:39:49 +02:00
}
return imageURLs;
2014-06-17 10:39:49 +02:00
}
2014-06-17 10:39:49 +02:00
@Override
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
2014-06-17 10:39:49 +02:00
}
}