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;
|
2014-06-25 04:05:54 +02:00
|
|
|
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;
|
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-06-17 10:39:49 +02:00
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
public class HentaifoundryRipper extends AbstractHTMLRipper {
|
2014-06-17 10:39:49 +02:00
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
private Map<String,String> cookies = new HashMap<>();
|
2014-06-17 10:39:49 +02:00
|
|
|
public HentaifoundryRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return "hentai-foundry";
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return "hentai-foundry.com";
|
2014-06-17 10:39:49 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 04:05:54 +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
|
2014-06-25 04:05:54 +02:00
|
|
|
public Document getFirstPage() throws IOException {
|
2014-06-22 02:08:42 +02:00
|
|
|
Response resp = Http.url("http://www.hentai-foundry.com/").response();
|
2014-06-25 04:05:54 +02:00
|
|
|
cookies = resp.cookies();
|
2014-06-22 02:08:42 +02:00
|
|
|
resp = Http.url("http://www.hentai-foundry.com/?enterAgree=1&size=1500")
|
|
|
|
.referrer("http://www.hentai-foundry.com/")
|
|
|
|
.cookies(cookies)
|
|
|
|
.response();
|
2017-04-25 20:02:18 +02:00
|
|
|
// The only cookie that seems to matter in getting around the age wall is the phpsession cookie
|
2014-06-25 04:05:54 +02:00
|
|
|
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();
|
|
|
|
}
|
2017-03-17 23:09:52 +01:00
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
@Override
|
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
2018-03-18 00:52:47 +01:00
|
|
|
if (doc.select("li.next > a").size() == 0) {
|
2014-06-25 04:05:54 +02:00
|
|
|
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) {
|
2017-10-24 16:33:28 +02:00
|
|
|
List<String> imageURLs = new ArrayList<>();
|
2014-06-25 04:05:54 +02:00
|
|
|
Pattern imgRegex = Pattern.compile(".*/user/([a-zA-Z0-9\\-_]+)/(\\d+)/.*");
|
2017-04-25 20:02:18 +02:00
|
|
|
for (Element thumb : doc.select("div.thumb_square > a.thumbLink")) {
|
2014-06-17 10:39:49 +02:00
|
|
|
if (isStopped()) {
|
|
|
|
break;
|
|
|
|
}
|
2014-06-25 04:05:54 +02:00
|
|
|
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
|
|
|
}
|
2017-03-28 21:17:51 +02:00
|
|
|
Document imagePage;
|
|
|
|
try {
|
|
|
|
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());
|
|
|
|
|
|
|
|
logger.info("grabbing " + "http://www.hentai-foundry.com" + thumb.attr("href"));
|
|
|
|
imagePage = Http.url("http://www.hentai-foundry.com" + thumb.attr("href")).cookies(cookies).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException e) {
|
|
|
|
logger.debug(e.getMessage());
|
|
|
|
logger.debug("Warning: imagePage is null!");
|
|
|
|
imagePage = null;
|
|
|
|
}
|
2017-04-25 20:39:05 +02:00
|
|
|
// This is here for when the image is resized to a thumbnail because ripme doesn't report a screensize
|
2017-10-24 16:33:28 +02:00
|
|
|
if (imagePage.select("div.boxbody > img.center").attr("src").contains("thumbs.")) {
|
2017-04-25 20:39:05 +02:00
|
|
|
imageURLs.add("http:" + imagePage.select("div.boxbody > img.center").attr("onclick").replace("this.src=", "").replace("'", "").replace("; $(#resize_message).hide();", ""));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
imageURLs.add("http:" + imagePage.select("div.boxbody > img.center").attr("src"));
|
|
|
|
}
|
2014-06-17 10:39:49 +02:00
|
|
|
}
|
2014-06-25 04:05:54 +02:00
|
|
|
return imageURLs;
|
2014-06-17 10:39:49 +02:00
|
|
|
}
|
2017-03-17 23:09:52 +01:00
|
|
|
|
2014-06-17 10:39:49 +02:00
|
|
|
@Override
|
2014-06-25 04:05:54 +02:00
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
2014-06-17 10:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|