2014-10-15 07:27:51 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
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 com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
|
|
import com.rarchives.ripme.utils.Http;
|
|
|
|
|
|
|
|
public class SankakuComplexRipper extends AbstractHTMLRipper {
|
|
|
|
private Document albumDoc = null;
|
|
|
|
private Map<String,String> cookies = new HashMap<String,String>();
|
|
|
|
|
|
|
|
public SankakuComplexRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return "sankakucomplex";
|
|
|
|
}
|
2017-06-19 19:32:57 +02:00
|
|
|
|
2014-10-15 07:27:51 +02:00
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
2015-02-10 08:29:29 +01:00
|
|
|
return "sankakucomplex.com";
|
2014-10-15 07:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
2015-02-10 08:29:29 +01:00
|
|
|
Pattern p = Pattern.compile("^https?://([a-zA-Z0-9]+\\.)?sankakucomplex\\.com/.*tags=([^&]+).*$");
|
2014-10-15 07:27:51 +02:00
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
try {
|
|
|
|
return URLDecoder.decode(m.group(1), "UTF-8");
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
throw new MalformedURLException("Cannot decode tag name '" + m.group(1) + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new MalformedURLException("Expected sankakucomplex.com URL format: " +
|
|
|
|
"idol.sankakucomplex.com?...&tags=something... - got " +
|
|
|
|
url + "instead");
|
|
|
|
}
|
2017-06-19 19:32:57 +02:00
|
|
|
|
2014-10-15 07:27:51 +02:00
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
if (albumDoc == null) {
|
|
|
|
Response resp = Http.url(url).response();
|
|
|
|
cookies.putAll(resp.cookies());
|
|
|
|
albumDoc = resp.parse();
|
|
|
|
}
|
|
|
|
return albumDoc;
|
|
|
|
}
|
2017-06-19 19:32:57 +02:00
|
|
|
|
2014-10-15 07:27:51 +02:00
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
|
|
|
List<String> imageURLs = new ArrayList<String>();
|
|
|
|
// Image URLs are basically thumbnail URLs with a different domain, a simple
|
|
|
|
// path replacement, and a ?xxxxxx post ID at the end (obtainable from the href)
|
|
|
|
for (Element thumbSpan : doc.select("div.content > div > span.thumb")) {
|
|
|
|
String postId = thumbSpan.attr("id").replaceAll("p", "");
|
|
|
|
Element thumb = thumbSpan.getElementsByTag("img").first();
|
|
|
|
String image = thumb.attr("abs:src")
|
2015-02-10 08:29:29 +01:00
|
|
|
.replace(".sankakucomplex.com/data/preview",
|
|
|
|
"s.sankakucomplex.com/data") + "?" + postId;
|
2014-10-15 07:27:51 +02:00
|
|
|
imageURLs.add(image);
|
|
|
|
}
|
|
|
|
return imageURLs;
|
|
|
|
}
|
2017-06-19 19:32:57 +02:00
|
|
|
|
2014-10-15 07:27:51 +02:00
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
// Mock up the URL of the post page based on the post ID at the end of the URL.
|
|
|
|
String postId = url.toExternalForm().replaceAll(".*\\?", "");
|
2015-03-31 06:54:04 +02:00
|
|
|
addURLToDownload(url, postId + "_", "", "", null);
|
2014-10-15 07:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
|
|
|
Element pagination = doc.select("div.pagination").first();
|
|
|
|
if (pagination.hasAttr("next-page-url")) {
|
|
|
|
return Http.url(pagination.attr("abs:next-page-url")).cookies(cookies).get();
|
2017-06-19 19:32:57 +02:00
|
|
|
} else {
|
2014-10-15 07:27:51 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|