From a6b3f50b7387b8c44ab19fedb1c73ff28440168b Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 16 Nov 2017 16:18:17 -0500 Subject: [PATCH] Added ripper for Theyiffgallery --- .../ripper/rippers/TheyiffgalleryRipper.java | 75 +++++++++++++++++++ .../tst/ripper/rippers/BasicRippersTest.java | 6 ++ 2 files changed, 81 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/TheyiffgalleryRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/TheyiffgalleryRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/TheyiffgalleryRipper.java new file mode 100644 index 00000000..9bdbfec6 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/TheyiffgalleryRipper.java @@ -0,0 +1,75 @@ +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; + +public class TheyiffgalleryRipper extends AbstractHTMLRipper { + + public TheyiffgalleryRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return "theyiffgallery"; + } + + @Override + public String getDomain() { + return "theyiffgallery.com"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("https?://theyiffgallery.com/index\\?/category/(\\d+)"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1); + } + throw new MalformedURLException("Expected theyiffgallery URL format: " + + "theyiffgallery.com/index?/category/#### - got " + url + " instead"); + } + + @Override + public Document getFirstPage() throws IOException { + // "url" is an instance field of the superclass + return Http.url(url).get(); + } + + @Override + public Document getNextPage(Document doc) throws IOException { + String nextPage = doc.select("span.navPrevNext > a").attr("href"); + if (nextPage != null && !nextPage.isEmpty() && nextPage.contains("start-")) { + return Http.url("https://theyiffgallery.com/" + nextPage).get(); + } + throw new IOException("No more pages"); + } + + @Override + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + for (Element el : doc.select("ul.thumbnails > li.gdthumb")) { + String imageSource = el.select("a > img").attr("src"); + imageSource = imageSource.replaceAll("_data/i", ""); + imageSource = imageSource.replaceAll("-\\w\\w_\\w\\d+x\\d+", ""); + result.add("https://theyiffgallery.com" + imageSource); + } + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } +} \ No newline at end of file diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/BasicRippersTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/BasicRippersTest.java index 1ba98059..8c7ca257 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/BasicRippersTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/BasicRippersTest.java @@ -28,6 +28,7 @@ import com.rarchives.ripme.ripper.rippers.VidbleRipper; import com.rarchives.ripme.ripper.rippers.VineRipper; import com.rarchives.ripme.ripper.rippers.VkRipper; import com.rarchives.ripme.ripper.rippers.XhamsterRipper; +import com.rarchives.ripme.ripper.rippers.TheyiffgalleryRipper; /** * Simple test cases for various rippers. @@ -214,6 +215,11 @@ public class BasicRippersTest extends RippersTest { testRipper(ripper); } + public void testTheyiffgallery() throws IOException { + AbstractRipper ripper = new TheyiffgalleryRipper(new URL("https://theyiffgallery.com/index?/category/4303")); + testRipper(ripper); + } + /* public void testSankakuChanRip() throws IOException { AbstractRipper ripper = new SankakuComplexRipper(new URL("https://chan.sankakucomplex.com/?tags=cleavage"));