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;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
import com.rarchives.ripme.ripper.AlbumRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-05-26 09:31:58 +02:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-03-14 04:26:23 +01:00
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
public class XhamsterRipper extends AlbumRipper {
|
2014-03-14 04:26:23 +01:00
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
private static final String HOST = "xhamster";
|
2014-03-14 04:26:23 +01:00
|
|
|
|
|
|
|
public XhamsterRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canRip(URL url) {
|
2014-11-17 01:53:21 +01:00
|
|
|
Pattern p = Pattern.compile("^https?://[wmde.]*xhamster\\.com/photos/gallery/[0-9]+.*$");
|
2014-06-25 04:05:54 +02:00
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
return m.matches();
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void rip() throws IOException {
|
|
|
|
int index = 0;
|
|
|
|
String nextURL = this.url.toExternalForm();
|
|
|
|
while (nextURL != null) {
|
|
|
|
logger.info(" Retrieving " + nextURL);
|
2014-06-22 02:08:42 +02:00
|
|
|
Document doc = Http.url(nextURL).get();
|
2014-03-14 04:26:23 +01:00
|
|
|
for (Element thumb : doc.select("table.iListing div.img img")) {
|
|
|
|
if (!thumb.hasAttr("src")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String image = thumb.attr("src");
|
2017-05-09 21:36:27 +02:00
|
|
|
// replace thumbnail urls with the urls to the full sized images
|
2014-03-14 04:26:23 +01:00
|
|
|
image = image.replaceAll(
|
2016-11-21 23:07:43 +01:00
|
|
|
"https://upt.xhcdn\\.",
|
|
|
|
"http://up.xhamster.");
|
2017-03-24 22:58:17 +01:00
|
|
|
image = image.replaceAll("ept\\.xhcdn", "ep.xhamster");
|
2014-03-14 04:26:23 +01:00
|
|
|
image = image.replaceAll(
|
|
|
|
"_160\\.",
|
|
|
|
"_1000.");
|
2017-05-09 21:36:27 +02:00
|
|
|
// Xhamster has shitty cert management and uses the wrong cert for their ep.xhamster Domain
|
|
|
|
// so we change all https requests to http
|
|
|
|
image = image.replaceAll(
|
|
|
|
"https://",
|
|
|
|
"http://");
|
2014-03-14 04:26:23 +01:00
|
|
|
index += 1;
|
2014-05-26 09:31:58 +02:00
|
|
|
String prefix = "";
|
|
|
|
if (Utils.getConfigBoolean("download.save_order", true)) {
|
|
|
|
prefix = String.format("%03d_", index);
|
|
|
|
}
|
|
|
|
addURLToDownload(new URL(image), prefix);
|
2015-02-10 08:29:29 +01:00
|
|
|
if (isThisATest()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isThisATest()) {
|
|
|
|
break;
|
2014-03-14 04:26:23 +01:00
|
|
|
}
|
|
|
|
nextURL = null;
|
|
|
|
for (Element element : doc.select("a.last")) {
|
|
|
|
nextURL = element.attr("href");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
waitForThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return HOST;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^https?://([a-z0-9.]*?)xhamster\\.com/photos/gallery/([0-9]{1,})/.*\\.html");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(2);
|
|
|
|
}
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected xhamster.com gallery formats: "
|
|
|
|
+ "xhamster.com/photos/gallery/#####/xxxxx..html"
|
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|