Skip to content

Commit

Permalink
Added Drawcrowd ripper #8
Browse files Browse the repository at this point in the history
  • Loading branch information
4pr0n committed May 16, 2014
1 parent 8aa8eaa commit 339aa89
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions src/main/java/com/rarchives/ripme/ripper/rippers/DrawcrowdRipper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;

public class DrawcrowdRipper extends AlbumRipper {

private static final String DOMAIN = "drawcrowd.com",
HOST = "drawcrowd";
private static final Logger logger = Logger.getLogger(DrawcrowdRipper.class);

public DrawcrowdRipper(URL url) throws IOException {
super(url);
}

@Override
public String getHost() {
return HOST;
}

/**
* Reformat given URL into the desired format (all images on single page)
*/
public URL sanitizeURL(URL url) throws MalformedURLException {
return url;
}

@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
public void rip() throws IOException {
int index = 0;
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
logger.info(" Retrieving " + this.url.toExternalForm());
Document albumDoc = Jsoup.connect(this.url.toExternalForm()).get();
while (true) {
if (isStopped()) {
break;
}
for (Element thumb : albumDoc.select("div.item.asset img")) {
String image = thumb.attr("src");
image = image
.replaceAll("/medium/", "/large/")
.replaceAll("/small/", "/large/");
index++;
addURLToDownload(new URL(image), String.format("%03d_", index));
}
Elements loadMore = albumDoc.select("a#load-more");
if (loadMore.size() == 0) {
break;
}
String nextURL = "http://drawcrowd.com" + loadMore.get(0).attr("href");
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, nextURL);
albumDoc = Jsoup.connect(nextURL).get();
}
waitForThreads();
}

public boolean canRip(URL url) {
return url.getHost().endsWith(DOMAIN);
}

}

0 comments on commit 339aa89

Please sign in to comment.