2014-02-25 10:28:22 +01:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
import java.io.File;
|
2014-02-25 10:28:22 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
2014-02-26 08:44:22 +01:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-02-25 10:28:22 +01:00
|
|
|
|
|
|
|
public class ImagefapRipper extends AbstractRipper {
|
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
private static final String HOST = "imagefap.com";
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
private String gid;
|
|
|
|
|
|
|
|
public ImagefapRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
this.gid = getGID(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reformat given URL into the desired format (all images on single page)
|
|
|
|
*/
|
|
|
|
public void sanitizeURL() throws MalformedURLException {
|
|
|
|
this.url = new URL("http://www.imagefap.com/gallery.php?gid="
|
|
|
|
+ this.gid + "&view=2");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getGID(URL url) throws MalformedURLException {
|
|
|
|
String gid = null;
|
|
|
|
Pattern p = Pattern.compile("^.*imagefap.com/gallery.php?gid=([0-9]{1,}).*$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
gid = m.group(1);
|
|
|
|
} else {
|
|
|
|
p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
2014-02-25 10:28:22 +01:00
|
|
|
if (m.matches()) {
|
|
|
|
gid = m.group(1);
|
|
|
|
}
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
|
|
|
if (gid == null) {
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected imagefap.com gallery formats:"
|
|
|
|
+ "imagefap.com/gallery.php?gid=####... or"
|
|
|
|
+ "imagefap.com/pictures/####...");
|
|
|
|
}
|
|
|
|
return gid;
|
|
|
|
}
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-02-26 08:44:22 +01:00
|
|
|
@Override
|
|
|
|
public void setWorkingDir() throws IOException {
|
|
|
|
String path = Utils.getWorkingDirectory().getCanonicalPath();
|
|
|
|
path += this.gid + File.separator;
|
|
|
|
this.workingDir = new File(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void rip() throws IOException {
|
2014-02-25 10:28:22 +01:00
|
|
|
System.err.println("Connecting to " + this.url.toExternalForm());
|
|
|
|
Document doc = Jsoup.connect(this.url.toExternalForm()).get();
|
|
|
|
for (Element thumb : doc.select("#gallery img")) {
|
|
|
|
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String image = thumb.attr("src");
|
2014-02-26 08:44:22 +01:00
|
|
|
image = image.replaceAll("http://x.*.fap.to/images/thumb/",
|
|
|
|
"http://fap.to/images/full/");
|
|
|
|
processURL(image);
|
2014-02-25 10:28:22 +01:00
|
|
|
System.err.println(image);
|
|
|
|
}
|
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 void processURL(String url) {
|
2014-02-25 10:28:22 +01:00
|
|
|
|
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) {
|
|
|
|
if (!url.getHost().endsWith(HOST)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|