diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/NudeGalsRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/NudeGalsRipper.java index ae9faaed..49e767b5 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/NudeGalsRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/NudeGalsRipper.java @@ -8,15 +8,21 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; 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.utils.Http; public class NudeGalsRipper extends AbstractHTMLRipper { + private static final Logger logger = LogManager.getLogger(NudeGalsRipper.class); + + private static final Pattern ALBUM_PATTERN = Pattern.compile("^.*nude-gals\\.com/photoshoot\\.php\\?photoshoot_id=(\\d+)$"); + private static final Pattern VIDEO_PATTERN = Pattern.compile("^.*nude-gals\\.com/video\\.php\\?video_id=(\\d+)$"); + public NudeGalsRipper(URL url) throws IOException { super(url); } @@ -36,10 +42,18 @@ public class NudeGalsRipper extends AbstractHTMLRipper { Pattern p; Matcher m; - p = Pattern.compile("^.*nude-gals\\.com/photoshoot\\.php\\?photoshoot_id=(\\d+)$"); + p = ALBUM_PATTERN; m = p.matcher(url.toExternalForm()); if (m.matches()) { - return m.group(1); + logger.info("Found nude-gals photo album page"); + return "album_" + m.group(1); + } + + p = VIDEO_PATTERN; + m = p.matcher(url.toExternalForm()); + if (m.matches()) { + logger.info("Found nude-gals video page"); + return "video_" + m.group(1); } throw new MalformedURLException( @@ -50,17 +64,38 @@ public class NudeGalsRipper extends AbstractHTMLRipper { @Override public List getURLsFromPage(Document doc) { - List imageURLs = new ArrayList<>(); + List urlsToDownload = new ArrayList<>(); - Elements thumbs = doc.select("img.thumbnail"); - for (Element thumb : thumbs) { - String link = thumb.attr("src").replaceAll("thumbs/th_", ""); - String imgSrc = "http://nude-gals.com/" + link; - imgSrc = imgSrc.replaceAll(" ", "%20"); - imageURLs.add(imgSrc); + Pattern p; + Matcher m; + + p = ALBUM_PATTERN; + m = p.matcher(url.toExternalForm()); + if (m.matches()) { + logger.info("Ripping nude-gals photo album"); + Elements thumbs = doc.select("img.thumbnail"); + for (Element thumb : thumbs) { + String link = thumb.attr("src").strip().replaceAll("thumbs/th_", ""); + String imgSrc = "http://nude-gals.com/" + link; + imgSrc = imgSrc.replaceAll(" ", "%20"); + urlsToDownload.add(imgSrc); + } } - return imageURLs; + p = VIDEO_PATTERN; + m = p.matcher(url.toExternalForm()); + if (m.matches()) { + logger.info("Ripping nude-gals video"); + Elements thumbs = doc.select("video source"); + for (Element thumb : thumbs) { + String link = thumb.attr("src").strip(); + String videoSrc = "http://nude-gals.com/" + link; + videoSrc = videoSrc.replaceAll(" ", "%20"); + urlsToDownload.add(videoSrc); + } + } + + return urlsToDownload; } @Override diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/NudeGalsRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/NudeGalsRipperTest.java index fb348d94..3223762c 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/NudeGalsRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/NudeGalsRipperTest.java @@ -9,15 +9,30 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class NudeGalsRipperTest extends RippersTest { + private static String ALBUM_TEST_URL = "https://nude-gals.com/photoshoot.php?photoshoot_id=5541"; + private static String VIDEO_TEST_URL = "https://nude-gals.com/video.php?video_id=1277"; + @Test - public void testRip() throws IOException, URISyntaxException { - NudeGalsRipper ripper = new NudeGalsRipper(new URI("https://nude-gals.com/photoshoot.php?photoshoot_id=5541").toURL()); + public void testAlbumRip() throws IOException, URISyntaxException { + NudeGalsRipper ripper = new NudeGalsRipper(new URI(ALBUM_TEST_URL).toURL()); testRipper(ripper); } @Test - public void testGetGID() throws IOException, URISyntaxException { - NudeGalsRipper ripper = new NudeGalsRipper(new URI("https://nude-gals.com/photoshoot.php?photoshoot_id=5541").toURL()); - Assertions.assertEquals("5541", ripper.getGID( new URI("https://nude-gals.com/photoshoot.php?photoshoot_id=5541").toURL())); + public void testVideoRip() throws IOException, URISyntaxException { + NudeGalsRipper ripper = new NudeGalsRipper(new URI(VIDEO_TEST_URL).toURL()); + testRipper(ripper); + } + + @Test + public void testGetAlbumGID() throws IOException, URISyntaxException { + NudeGalsRipper ripper = new NudeGalsRipper(new URI(ALBUM_TEST_URL).toURL()); + Assertions.assertEquals("album_5541", ripper.getGID( new URI(ALBUM_TEST_URL).toURL())); + } + + @Test + public void testGetVideoGID() throws IOException, URISyntaxException { + NudeGalsRipper ripper = new NudeGalsRipper(new URI(VIDEO_TEST_URL).toURL()); + Assertions.assertEquals("video_1277", ripper.getGID(new URI(VIDEO_TEST_URL).toURL())); } }