Skip to content

Commit

Permalink
Support multi-page motherless albums
Browse files Browse the repository at this point in the history
  • Loading branch information
4pr0n committed Mar 12, 2014
1 parent e975ae6 commit 1cdec76
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,36 @@ public URL sanitizeURL(URL url) throws MalformedURLException {

@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?motherless\\.com/G([A-Z0-9]{6,8}).*$");
Pattern p = Pattern.compile("^https?://(www\\.)?motherless\\.com/G([VI][A-F0-9]{6,8}).*$");
Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) {
throw new MalformedURLException("Expected URL format: http://motherless.com/GXXXXXXXX");
throw new MalformedURLException("Expected URL format: http://motherless.com/GIXXXXXXX, got: " + url);
}
return m.group(m.groupCount());
}

@Override
public void rip() throws IOException {
int index = 0;
logger.info(" Retrieving " + this.url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm())
.userAgent(USER_AGENT)
.get();
for (Element thumb : doc.select("div.thumb a.img-container")) {
URL url = new URL("http://" + DOMAIN + thumb.attr("href"));
index += 1;
// Create thread for finding image at "url" page
MotherlessImageThread mit = new MotherlessImageThread(url, index);
motherlessThreadPool.addThread(mit);
int index = 0, page = 1;
String nextURL = this.url.toExternalForm();
while (nextURL != null) {
logger.info(" Retrieving " + nextURL);
Document doc = Jsoup.connect(nextURL)
.userAgent(USER_AGENT)
.get();
for (Element thumb : doc.select("div.thumb a.img-container")) {
URL url = new URL("http://" + DOMAIN + thumb.attr("href"));
index += 1;
// Create thread for finding image at "url" page
MotherlessImageThread mit = new MotherlessImageThread(url, index);
motherlessThreadPool.addThread(mit);
}
// Next page
nextURL = null;
page++;
if (doc.html().contains("?page=" + page)) {
nextURL = this.url.toExternalForm() + "?page=" + page;
}
}
motherlessThreadPool.waitForThreads();
waitForThreads();
Expand Down

0 comments on commit 1cdec76

Please sign in to comment.