2014-06-01 10:26:35 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2018-05-06 12:27:41 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-06-01 10:26:35 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
2018-05-06 12:27:41 +02:00
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-06-01 10:26:35 +02:00
|
|
|
|
2018-05-06 12:27:41 +02:00
|
|
|
|
|
|
|
public class SmuttyRipper extends AbstractHTMLRipper {
|
2014-06-01 10:26:35 +02:00
|
|
|
|
|
|
|
private static final String DOMAIN = "smutty.com",
|
|
|
|
HOST = "smutty";
|
|
|
|
|
|
|
|
public SmuttyRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
2018-05-06 12:27:41 +02:00
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return "smutty";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return "smutty.com";
|
|
|
|
}
|
|
|
|
|
2014-06-01 10:26:35 +02:00
|
|
|
@Override
|
|
|
|
public boolean canRip(URL url) {
|
|
|
|
return (url.getHost().endsWith(DOMAIN));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-06 12:27:41 +02:00
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
|
|
|
List<String> results = new ArrayList<>();
|
|
|
|
for (Element image : doc.select("a.l > img")) {
|
2014-06-20 13:09:36 +02:00
|
|
|
if (isStopped()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-05-06 12:27:41 +02:00
|
|
|
String imageUrl = image.attr("src");
|
|
|
|
|
|
|
|
// Construct direct link to image based on thumbnail
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
String[] fields = imageUrl.split("/");
|
|
|
|
for (int i = 0; i < fields.length; i++) {
|
|
|
|
if (i == fields.length - 2 && fields[i].equals("m")) {
|
|
|
|
fields[i] = "b";
|
2014-06-20 13:09:36 +02:00
|
|
|
}
|
2018-05-06 12:27:41 +02:00
|
|
|
sb.append(fields[i]);
|
|
|
|
if (i < fields.length - 1) {
|
|
|
|
sb.append("/");
|
2014-06-01 10:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-06 12:27:41 +02:00
|
|
|
imageUrl = sb.toString();
|
|
|
|
results.add("http:" + imageUrl);
|
2014-06-01 10:26:35 +02:00
|
|
|
}
|
2018-05-06 12:27:41 +02:00
|
|
|
return results;
|
2014-06-01 10:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-06 12:27:41 +02:00
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
|
|
|
Element elem = doc.select("a.next").first();
|
|
|
|
if (elem == null) {
|
|
|
|
throw new IOException("No more pages");
|
|
|
|
}
|
|
|
|
String nextPage = elem.attr("href");
|
|
|
|
// Some times this returns a empty string
|
|
|
|
// This for stops that
|
|
|
|
if (nextPage.equals("")) {
|
|
|
|
throw new IOException("No more pages");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Http.url("https://smutty.com" + nextPage).get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
// "url" is an instance field of the superclass
|
|
|
|
return Http.url(url).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
2014-06-01 10:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^https?://smutty\\.com/h/([a-zA-Z0-9\\-_]+).*$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
p = Pattern.compile("^https?://[wm.]*smutty\\.com/search/\\?q=([a-zA-Z0-9\\-_%]+).*$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1).replace("%23", "");
|
|
|
|
}
|
2018-05-06 12:27:41 +02:00
|
|
|
|
|
|
|
p = Pattern.compile("^https?://smutty.com/user/([a-zA-Z0-9\\-_]+)/?$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
2014-06-01 10:26:35 +02:00
|
|
|
throw new MalformedURLException("Expected tag in URL (smutty.com/h/tag and not " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|