2014-02-25 10:28:22 +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.Jsoup;
|
|
|
|
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-05-11 19:07:58 +02:00
|
|
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
2014-05-26 09:31:58 +02:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-04-20 07:41:11 +02:00
|
|
|
public class ImagefapRipper extends AlbumRipper {
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-02-27 04:54:44 +01:00
|
|
|
private static final String DOMAIN = "imagefap.com",
|
|
|
|
HOST = "imagefap";
|
2014-02-26 08:44:22 +01:00
|
|
|
|
2014-04-11 08:42:14 +02:00
|
|
|
private Document albumDoc = null;
|
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
public ImagefapRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
2014-02-27 04:54:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return HOST;
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reformat given URL into the desired format (all images on single page)
|
|
|
|
*/
|
2014-02-27 04:54:44 +01:00
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
String gid = getGID(url);
|
|
|
|
URL newURL = new URL("http://www.imagefap.com/gallery.php?gid="
|
|
|
|
+ gid + "&view=2");
|
|
|
|
logger.debug("Sanitized URL from " + url + " to " + newURL);
|
|
|
|
return newURL;
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-04-11 08:42:14 +02:00
|
|
|
|
|
|
|
public String getAlbumTitle(URL url) throws MalformedURLException {
|
|
|
|
try {
|
|
|
|
// Attempt to use album title as GID
|
|
|
|
if (albumDoc == null) {
|
2014-06-20 13:09:36 +02:00
|
|
|
albumDoc = getDocument(url);
|
2014-04-11 08:42:14 +02:00
|
|
|
}
|
|
|
|
String title = albumDoc.title();
|
|
|
|
Pattern p = Pattern.compile("^Porn pics of (.*) \\(Page 1\\)$");
|
|
|
|
Matcher m = p.matcher(title);
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Fall back to default album naming convention
|
|
|
|
}
|
|
|
|
return super.getAlbumTitle(url);
|
|
|
|
}
|
2014-02-26 08:44:22 +01:00
|
|
|
|
2014-04-11 08:42:14 +02:00
|
|
|
@Override
|
2014-02-27 04:54:44 +01:00
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
2014-04-11 08:42:14 +02:00
|
|
|
Pattern p; Matcher m;
|
|
|
|
|
2014-05-26 05:12:18 +02:00
|
|
|
p = Pattern.compile("^.*imagefap.com/gallery.php\\?gid=([0-9]+).*$");
|
2014-04-11 08:42:14 +02:00
|
|
|
m = p.matcher(url.toExternalForm());
|
2014-02-26 08:44:22 +01:00
|
|
|
if (m.matches()) {
|
2014-02-27 04:54:44 +01:00
|
|
|
return m.group(1);
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-04-11 08:42:14 +02:00
|
|
|
|
2014-05-26 05:12:18 +02:00
|
|
|
p = Pattern.compile("^.*imagefap.com/pictures/([0-9]+).*$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = Pattern.compile("^.*imagefap.com/gallery/([0-9]+).*$");
|
2014-02-27 04:54:44 +01:00
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-04-11 08:42:14 +02:00
|
|
|
|
2014-02-27 04:54:44 +01:00
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected imagefap.com gallery formats: "
|
|
|
|
+ "imagefap.com/gallery.php?gid=####... or "
|
|
|
|
+ "imagefap.com/pictures/####..."
|
|
|
|
+ " Got: " + url);
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void rip() throws IOException {
|
2014-02-28 04:49:28 +01:00
|
|
|
int index = 0;
|
2014-05-11 19:07:58 +02:00
|
|
|
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
|
2014-06-20 13:09:36 +02:00
|
|
|
logger.info("Retrieving " + this.url);
|
2014-04-11 08:42:14 +02:00
|
|
|
if (albumDoc == null) {
|
2014-06-20 13:09:36 +02:00
|
|
|
albumDoc = getDocument(this.url);
|
2014-04-11 08:42:14 +02:00
|
|
|
}
|
2014-05-11 19:07:58 +02:00
|
|
|
while (true) {
|
|
|
|
if (isStopped()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (Element thumb : albumDoc.select("#gallery img")) {
|
|
|
|
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String image = thumb.attr("src");
|
|
|
|
image = image.replaceAll(
|
|
|
|
"http://x.*.fap.to/images/thumb/",
|
|
|
|
"http://fap.to/images/full/");
|
|
|
|
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);
|
2014-05-11 19:07:58 +02:00
|
|
|
}
|
|
|
|
String nextURL = null;
|
|
|
|
for (Element a : albumDoc.select("a.link3")) {
|
|
|
|
if (a.text().contains("next")) {
|
|
|
|
nextURL = a.attr("href");
|
|
|
|
nextURL = "http://imagefap.com/gallery.php" + nextURL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nextURL == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
logger.error("Interrupted while waiting to load next page", e);
|
|
|
|
throw new IOException(e);
|
|
|
|
}
|
|
|
|
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
|
|
|
|
albumDoc = Jsoup.connect(nextURL).get();
|
2014-02-25 10:28:22 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-02 03:08:16 +01:00
|
|
|
waitForThreads();
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
public boolean canRip(URL url) {
|
2014-04-25 18:42:54 +02:00
|
|
|
return url.getHost().endsWith(DOMAIN);
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 04:54:44 +01:00
|
|
|
}
|