From db5e7f08376f302725a0b9f8dcf29b3c6ecbdab9 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 1 Aug 2017 20:45:58 -0400 Subject: [PATCH] Added basic support for aerisdies.com --- .../ripme/ripper/rippers/AerisdiesRipper.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/AerisdiesRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/AerisdiesRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/AerisdiesRipper.java new file mode 100644 index 00000000..11349716 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/AerisdiesRipper.java @@ -0,0 +1,98 @@ +package com.rarchives.ripme.ripper.rippers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jsoup.Connection.Response; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.ui.RipStatusMessage.STATUS; +import com.rarchives.ripme.utils.Http; +import java.util.HashMap; + +public class AerisdiesRipper extends AbstractHTMLRipper { + + private Document albumDoc = null; + private Map cookies = new HashMap(); + + + public AerisdiesRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return "aerisdies"; + } + @Override + public String getDomain() { + return "aerisdies.com"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("^https?://www.aerisdies.com/html/lb/([a-z]*_[0-9]*_\\d)\\.html"); + Matcher m = p.matcher(url.toExternalForm()); + if (!m.matches()) { + throw new MalformedURLException("Expected URL format: http://www.aerisdies.com/html/lb/albumDIG, got: " + url); + } + return m.group(m.groupCount()); + } + + @Override + public String getAlbumTitle(URL url) throws MalformedURLException { + try { + // Attempt to use album title as GID + String title = getFirstPage().select("title").first().text(); + return getHost() + "_" + title.trim(); + } catch (IOException e) { + // Fall back to default album naming convention + logger.info("Unable to find title at " + url); + } + return super.getAlbumTitle(url); + } + + @Override + public Document getFirstPage() throws IOException { + if (albumDoc == null) { + Response resp = Http.url(url).response(); + cookies.putAll(resp.cookies()); + albumDoc = resp.parse(); + } + return albumDoc; + } + + @Override + public List getURLsFromPage(Document page) { + List imageURLs = new ArrayList(); + Elements albumElements = page.select("div.imgbox > a > img"); + for (Element imageBox : albumElements) { + String imageUrl = imageBox.attr("src"); + imageUrl = imageUrl.replaceAll("thumbnails", "images"); + imageUrl = imageUrl.replaceAll("../../", ""); + imageUrl = imageUrl.replaceAll("gif", "jpg"); + imageURLs.add("http://www.aerisdies.com/" + imageUrl); + } + return imageURLs; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index), "", this.url.toExternalForm(), cookies); + } + + @Override + public String getPrefix(int index) { + return String.format("%03d_", index); + } +}