2014-05-16 08:29:50 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2014-06-22 02:08:42 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-05-16 08:29:50 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
2014-06-23 04:12:29 +02:00
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-05-16 08:29:50 +02:00
|
|
|
|
2014-06-23 04:12:29 +02:00
|
|
|
public class DrawcrowdRipper extends AbstractHTMLRipper {
|
2014-05-16 08:29:50 +02:00
|
|
|
|
|
|
|
public DrawcrowdRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
2014-06-22 02:08:42 +02:00
|
|
|
return "drawcrowd";
|
2014-05-16 08:29:50 +02:00
|
|
|
}
|
2014-06-22 02:08:42 +02:00
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return "drawcrowd.com";
|
2014-05-16 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p; Matcher m;
|
|
|
|
|
|
|
|
p = Pattern.compile("^.*drawcrowd.com/projects/.*$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
throw new MalformedURLException("Cannot rip drawcrowd.com/projects/ pages");
|
|
|
|
}
|
|
|
|
|
|
|
|
p = Pattern.compile("^.*drawcrowd.com/([a-zA-Z0-9\\-_]+).*$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected drawcrowd.com gallery format: "
|
|
|
|
+ "drawcrowd.com/username"
|
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-22 02:08:42 +02:00
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
return Http.url(this.url).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
|
|
|
Elements loadMore = doc.select("a#load-more");
|
|
|
|
if (loadMore.size() == 0) {
|
|
|
|
throw new IOException("No next page found");
|
2014-05-16 08:29:50 +02:00
|
|
|
}
|
2014-06-22 02:08:42 +02:00
|
|
|
if (!sleep(1000)) {
|
|
|
|
throw new IOException("Interrupted while waiting for next page");
|
|
|
|
}
|
|
|
|
String nextPage = "http://drawcrowd.com" + loadMore.get(0).attr("href");
|
|
|
|
return Http.url(nextPage).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document page) {
|
|
|
|
List<String> imageURLs = new ArrayList<String>();
|
|
|
|
for (Element thumb : page.select("div.item.asset img")) {
|
|
|
|
String image = thumb.attr("src");
|
|
|
|
image = image
|
|
|
|
.replaceAll("/medium/", "/large/")
|
|
|
|
.replaceAll("/small/", "/large/");
|
|
|
|
imageURLs.add(image);
|
|
|
|
}
|
|
|
|
return imageURLs;
|
2014-05-16 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 02:08:42 +02:00
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
2014-05-16 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|