From acc7f87ad5d02f1754f1c14ccf9c531936e53327 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Mon, 21 Apr 2014 00:02:56 -0700 Subject: [PATCH] 1.0.23 - Added teenplanet album ripper #8 --- pom.xml | 2 +- .../ripper/rippers/TeenplanetRipper.java | 94 +++++++++++++++++++ .../com/rarchives/ripme/ui/UpdateUtils.java | 2 +- 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/TeenplanetRipper.java diff --git a/pom.xml b/pom.xml index 8217c3df4..0e278ef64 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.22 + 1.0.23 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/TeenplanetRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/TeenplanetRipper.java new file mode 100644 index 000000000..da3d90771 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/TeenplanetRipper.java @@ -0,0 +1,94 @@ +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; + +public class TeenplanetRipper extends AlbumRipper { + + private static final String DOMAIN = "teenplanet.org", + HOST = "teenplanet"; + private static final Logger logger = Logger.getLogger(TeenplanetRipper.class); + + private Document albumDoc = null; + + public TeenplanetRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return HOST; + } + + public URL sanitizeURL(URL url) throws MalformedURLException { + return url; + } + + public String getAlbumTitle(URL url) throws MalformedURLException { + try { + // Attempt to use album title as GID + if (albumDoc == null) { + albumDoc = Jsoup.connect(url.toExternalForm()).get(); + } + Elements elems = albumDoc.select("div.header > h2"); + return elems.get(0).text(); + } catch (Exception e) { + // Fall back to default album naming convention + e.printStackTrace(); + } + return super.getAlbumTitle(url); + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p; Matcher m; + + p = Pattern.compile("^.*teenplanet.org/galleries/([a-zA-Z0-9\\-]+).html$"); + m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1); + } + + throw new MalformedURLException( + "Expected teenplanet.org gallery format: " + + "teenplanet.org/galleries/....html" + + " Got: " + url); + } + + @Override + public void rip() throws IOException { + int index = 0; + logger.info(" Retrieving " + this.url.toExternalForm()); + if (albumDoc == null) { + albumDoc = Jsoup.connect(this.url.toExternalForm()).get(); + } + for (Element thumb : albumDoc.select("#galleryImages > a > img")) { + if (!thumb.hasAttr("src")) { + continue; + } + String image = thumb.attr("src"); + image = image.replace( + "/thumbs/", + "/"); + index += 1; + addURLToDownload(new URL(image), String.format("%03d_", index)); + } + waitForThreads(); + } + + public boolean canRip(URL url) { + return url.getHost().endsWith(DOMAIN); + } + +} \ No newline at end of file diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 3e790ceee..8d935ae42 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -19,7 +19,7 @@ public class UpdateUtils { private static final Logger logger = Logger.getLogger(UpdateUtils.class); - private static final String DEFAULT_VERSION = "1.0.22"; + private static final String DEFAULT_VERSION = "1.0.23"; private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String mainFileName = "ripme.jar";