From 0722667b4e1b9b0d5e1d7342c26a7f5e400d04d0 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Thu, 15 May 2014 22:44:57 -0700 Subject: [PATCH] Fix for multi-page deviantart albums #42 --- .../ripper/rippers/DeviantartRipper.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java index d0fc3f98..575204b7 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java @@ -19,6 +19,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import com.rarchives.ripme.ripper.AlbumRipper; +import com.rarchives.ripme.ui.RipStatusMessage.STATUS; import com.rarchives.ripme.utils.Utils; public class DeviantartRipper extends AlbumRipper { @@ -49,35 +50,46 @@ public class DeviantartRipper extends AlbumRipper { public void rip() throws IOException { int index = 0; String nextURL = this.url.toExternalForm(); + while (nextURL != null) { + logger.info(" Retrieving " + nextURL); + sendUpdate(STATUS.LOADING_RESOURCE, "Retrieving " + nextURL); Document doc = Jsoup.connect(nextURL) .userAgent(USER_AGENT) .get(); + + for (Element thumb : doc.select("div.zones-container a.thumb img")) { + if (thumb.attr("transparent").equals("false")) { + continue; // a.thumbs to other albums are invisible + } + + String fullSizePage = thumbToFull(thumb.attr("src")); + try { + URL fullsizePageURL = new URL(fullSizePage); + index++; + addURLToDownload(fullsizePageURL, String.format("%03d_", index)); + } catch (MalformedURLException e) { + logger.error("[!] Invalid thumbnail image: " + thumbToFull(fullSizePage)); + continue; + } + } + try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException e) { logger.error("[!] Interrupted while waiting for page to load", e); break; } - for (Element thumb : doc.select("a.thumb img")) { - String fullSize = thumbToFull(thumb.attr("src")); - URL pageURL; - try { - pageURL = new URL(fullSize); - } catch (MalformedURLException e) { - logger.error("[!] Invalid thumbnail image: " + thumbToFull(fullSize)); - continue; - } - index++; - addURLToDownload(pageURL, String.format("%03d_", index)); - } nextURL = null; for (Element nextButton : doc.select("a.away")) { if (nextButton.attr("href").contains("offset=" + index)) { nextURL = this.url.toExternalForm() + "?offset=" + index; } } + if (nextURL == null) { + logger.info("No next button found"); + } } waitForThreads(); }