2014-03-14 04:26:23 +01:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2017-11-23 06:18:09 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-03-14 04:26:23 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
2017-11-23 06:18:09 +01:00
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-03-14 04:26:23 +01:00
|
|
|
|
2017-11-23 06:18:09 +01:00
|
|
|
public class XhamsterRipper extends AbstractHTMLRipper {
|
2014-03-14 04:26:23 +01:00
|
|
|
|
|
|
|
public XhamsterRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-23 06:18:09 +01:00
|
|
|
public String getHost() {
|
|
|
|
return "xhamster";
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-23 06:18:09 +01:00
|
|
|
public String getDomain() {
|
|
|
|
return "xhamster.com";
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-23 06:18:09 +01:00
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
String URLToReturn = url.toExternalForm();
|
|
|
|
URLToReturn = URLToReturn.replaceAll("m.xhamster.com", "xhamster.com");
|
|
|
|
URLToReturn = URLToReturn.replaceAll("\\w\\w.xhamster.com", "xhamster.com");
|
|
|
|
URL san_url = new URL(URLToReturn.replaceAll("xhamster.com", "m.xhamster.com"));
|
|
|
|
logger.info("sanitized URL is " + san_url.toExternalForm());
|
|
|
|
return san_url;
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
2017-11-23 06:18:09 +01:00
|
|
|
Pattern p = Pattern.compile("^https?://[\\w\\w.]*xhamster\\.com/photos/gallery/.*?(\\d+)$");
|
2014-03-14 04:26:23 +01:00
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
2017-07-02 04:41:55 +02:00
|
|
|
return m.group(1);
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected xhamster.com gallery formats: "
|
2017-07-02 04:41:55 +02:00
|
|
|
+ "xhamster.com/photos/gallery/xxxxx-#####"
|
2014-03-14 04:26:23 +01:00
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
|
|
|
|
2017-11-23 06:18:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
// "url" is an instance field of the superclass
|
|
|
|
return Http.url(url).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canRip(URL url) {
|
|
|
|
Pattern p = Pattern.compile("^https?://[wmde.]*xhamster\\.com/photos/gallery/.*?(\\d+)$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
2018-05-31 15:21:44 +02:00
|
|
|
return m.matches();
|
2017-11-23 06:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
2018-04-19 17:35:36 +02:00
|
|
|
if (!doc.select("a.next").first().attr("href").equals("")) {
|
2017-11-23 06:18:09 +01:00
|
|
|
return Http.url(doc.select("a.next").first().attr("href")).get();
|
|
|
|
} else {
|
|
|
|
throw new IOException("No more pages");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
for (Element thumb : doc.select("div.picture_view > div.pictures_block > div.items > div.item-container > a > div.thumb_container > div.img > img")) {
|
|
|
|
String image = thumb.attr("src");
|
|
|
|
// replace thumbnail urls with the urls to the full sized images
|
|
|
|
image = image.replaceAll(
|
|
|
|
"https://upt.xhcdn\\.",
|
|
|
|
"http://up.xhamster.");
|
|
|
|
image = image.replaceAll("ept\\.xhcdn", "ep.xhamster");
|
|
|
|
image = image.replaceAll(
|
|
|
|
"_160\\.",
|
|
|
|
"_1000.");
|
|
|
|
// Xhamster has bad cert management and uses invalid certs for some cdns, so we change all our requests to http
|
|
|
|
image = image.replaceAll("https", "http");
|
|
|
|
result.add(image);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
|
|
|
}
|
|
|
|
}
|