From b73e943b9cf39e89b5bcf1fe08723bc9e77081d5 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 19 Apr 2018 18:52:36 -0400 Subject: [PATCH 1/3] Added HitomiRipper --- .../ripme/ripper/rippers/HitomiRipper.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/HitomiRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/HitomiRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/HitomiRipper.java new file mode 100644 index 00000000..3e92cc61 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/HitomiRipper.java @@ -0,0 +1,73 @@ +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.json.JSONArray; +import org.json.JSONObject; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.utils.Http; + +public class HitomiRipper extends AbstractHTMLRipper { + + String galleryId = ""; + + public HitomiRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return "hitomi"; + } + + @Override + public String getDomain() { + return "hitomi.la"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("https://hitomi.la/galleries/([\\d]+).html"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + galleryId = m.group(1); + return m.group(1); + } + throw new MalformedURLException("Expected hitomi URL format: " + + "https://hitomi.la/galleries/ID.html - got " + url + " instead"); + } + + @Override + public Document getFirstPage() throws IOException { + // if we go to /GALLERYID.js we get a nice json array of all images in the gallery + return Http.url(new URL(url.toExternalForm().replaceAll(".html", ".js"))).ignoreContentType().get(); + } + + + @Override + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + String json = doc.text().replaceAll("var galleryinfo =", ""); + logger.info(json); + JSONArray json_data = new JSONArray(json); + for (int i = 0; i < json_data.length(); i++) { + result.add("https://0a.hitomi.la/galleries/" + galleryId + "/" + json_data.getJSONObject(i).getString("name")); + } + + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } +} From a7445ec4ac3d4ccab090fd829706f8ad2ff68fc0 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 19 Apr 2018 18:54:54 -0400 Subject: [PATCH 2/3] Added Hitomi Ripper unit test --- .../ripme/tst/ripper/rippers/HitomiRipperTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java new file mode 100644 index 00000000..78627a83 --- /dev/null +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java @@ -0,0 +1,13 @@ +package com.rarchives.ripme.tst.ripper.rippers; + +import java.io.IOException; +import java.net.URL; + +import com.rarchives.ripme.ripper.rippers.HitomiRipper; + +public class HitomiRipperTest extends RippersTest { + public void testRip() throws IOException { + HitomiRipper ripper = new HitomiRipper(new URL("https://hitomi.la/galleries/975973.html")); + testRipper(ripper); + } +} From f8a8fdb9dc74c54064bd021aa774166fff0a7f9e Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 19 Apr 2018 18:58:47 -0400 Subject: [PATCH 3/3] Extended HitomiRipper unit test --- .../com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java index 78627a83..13c2798d 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/HitomiRipperTest.java @@ -9,5 +9,6 @@ public class HitomiRipperTest extends RippersTest { public void testRip() throws IOException { HitomiRipper ripper = new HitomiRipper(new URL("https://hitomi.la/galleries/975973.html")); testRipper(ripper); + assertTrue(ripper.getGID(new URL("https://hitomi.la/galleries/975973.html")).equals("975973")); } }