From 7b1fbd3290010db410ef2c92afb75d1bc6e4797f Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 29 Apr 2018 12:22:27 -0400 Subject: [PATCH 1/3] Added ripper for hypnohub.net; removed misnamed file --- .../ripme/ripper/rippers/HypnohubRipper.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/HypnohubRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/HypnohubRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/HypnohubRipper.java new file mode 100644 index 00000000..1eabefb9 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/HypnohubRipper.java @@ -0,0 +1,91 @@ +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.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.utils.Http; + +import javax.print.Doc; + +public class HypnohubRipper extends AbstractHTMLRipper { + + public HypnohubRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return "hypnohub"; + } + + @Override + public String getDomain() { + return "hypnohub.net"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("https?://hypnohub.net/\\S+/show/([\\d]+)/?$"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1); + } + p = Pattern.compile("https?://hypnohub.net/\\S+/show/([\\d]+)/([\\S]+)/?$"); + m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1) + "_" + m.group(2); + } + throw new MalformedURLException("Expected cfake URL format: " + + "hypnohub.net/pool/show/ID - got " + url + " instead"); + } + + @Override + public Document getFirstPage() throws IOException { + // "url" is an instance field of the superclass + return Http.url(url).get(); + } + + private String ripPost(String url) throws IOException { + logger.info(url); + Document doc = Http.url(url).get(); + return "https:" + doc.select("img.image").attr("src"); + + } + + private String ripPost(Document doc) { + logger.info(url); + return "https:" + doc.select("img.image").attr("src"); + + } + + @Override + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + if (url.toExternalForm().contains("/pool")) { + for (Element el : doc.select("ul[id=post-list-posts] > li > div > a.thumb")) { + try { + result.add(ripPost("https://hypnohub.net" + el.attr("href"))); + } catch (IOException e) { + return result; + } + } + } else if (url.toExternalForm().contains("/post")) { + result.add(ripPost(doc)); + } + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } +} From 60d5f95f938a2da169727b13a4b5af055ca16b9e Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 29 Apr 2018 12:40:50 -0400 Subject: [PATCH 2/3] Added unit test for HypnohubRipper --- .../ripper/rippers/HypnohubRipperTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java new file mode 100644 index 00000000..4466eadc --- /dev/null +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java @@ -0,0 +1,25 @@ +package com.rarchives.ripme.tst.ripper.rippers; + +import java.io.IOException; +import java.net.URL; + +import com.rarchives.ripme.ripper.rippers.HypnohubRipper; + +public class HypnohubRipperTest extends RippersTest { + public void testRip() throws IOException { + URL poolURL = new URL("http://hypnohub.net/pool/show/2303"); + URL postURL = new URL("http://hypnohub.net/post/show/63464/black_hair-bracelet-collar-corruption-female_only-"); + HypnohubRipper ripper = new HypnohubRipper(poolURL); + testRipper(ripper); + ripper = new HypnohubRipper(postURL); + testRipper(ripper); + } + public void testGetGID() throws IOException { + URL poolURL = new URL("http://hypnohub.net/pool/show/2303"); + HypnohubRipper ripper = new HypnohubRipper(poolURL); + assertEquals("hypnohub_2303", ripper.getGID(poolURL)); + + URL postURL = new URL("http://hypnohub.net/post/show/63464/black_hair-bracelet-collar-corruption-female_only-"); + assertEquals("hypnohub_63464_black_hair-bracelet-collar-corruption-female_only-", ripper.getGID(postURL)); + } +} From 24f1b4fbdc6f26ab0a6a6dfe85d2edb1cf5ed9a7 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 29 Apr 2018 12:50:44 -0400 Subject: [PATCH 3/3] Fixed hypnohub unit test --- .../ripme/tst/ripper/rippers/HypnohubRipperTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java index 4466eadc..1d9ef4ad 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HypnohubRipperTest.java @@ -17,9 +17,9 @@ public class HypnohubRipperTest extends RippersTest { public void testGetGID() throws IOException { URL poolURL = new URL("http://hypnohub.net/pool/show/2303"); HypnohubRipper ripper = new HypnohubRipper(poolURL); - assertEquals("hypnohub_2303", ripper.getGID(poolURL)); + assertEquals("2303", ripper.getGID(poolURL)); URL postURL = new URL("http://hypnohub.net/post/show/63464/black_hair-bracelet-collar-corruption-female_only-"); - assertEquals("hypnohub_63464_black_hair-bracelet-collar-corruption-female_only-", ripper.getGID(postURL)); + assertEquals("63464_black_hair-bracelet-collar-corruption-female_only-", ripper.getGID(postURL)); } }