1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-15 18:34:09 +02:00

NsfwAlbumRipper: Add index prefix to downloads to keep albums in order; format, cleanup imports, cleanup log line

This commit is contained in:
MetaPrime
2025-01-04 02:17:36 -08:00
parent ae82bef13d
commit acd336ed4b

View File

@@ -1,95 +1,70 @@
package com.rarchives.ripme.ripper.rippers; package com.rarchives.ripme.ripper.rippers;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.*;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http;
//https://github.com/ripmeapp/ripme/wiki/How-To-Create-A-Ripper-for-HTML-websites public class NsfwAlbumRipper extends AbstractHTMLRipper {
public class NsfwAlbumRipper extends AbstractHTMLRipper
{
private static final String HOST = "nsfwalbum"; private static final String HOST = "nsfwalbum";
private static final String DOMAIN = "nsfwalbum.com"; private static final String DOMAIN = "nsfwalbum.com";
public NsfwAlbumRipper(URL url) throws IOException public NsfwAlbumRipper(URL url) throws IOException {
{
super(url); super(url);
} }
@Override @Override
public String getHost() public String getHost() {
{
return HOST; return HOST;
} }
@Override @Override
public String getDomain() public String getDomain() {
{
return DOMAIN; return DOMAIN;
} }
@Override @Override
public String getGID(URL url) throws MalformedURLException public String getGID(URL url) throws MalformedURLException {
{
Pattern pattern = Pattern.compile("(?!https:\\/\\/nsfwalbum.com\\/album\\/)\\d+"); Pattern pattern = Pattern.compile("(?!https:\\/\\/nsfwalbum.com\\/album\\/)\\d+");
Matcher matcher = pattern.matcher(url.toExternalForm()); Matcher matcher = pattern.matcher(url.toExternalForm());
if (matcher.find()) if (matcher.find()) {
{
return matcher.group(); return matcher.group();
} }
throw new MalformedURLException("Expected https://nsfwalbum.com/album/albumid URL format nsfwalbum.com/album/albumid - got " + url + " instead."); throw new MalformedURLException(
"Expected nsfwalbum.com URL format nsfwalbum.com/album/albumid - got " + url + " instead.");
} }
@Override @Override
public Document getFirstPage() throws IOException public List<String> getURLsFromPage(Document doc) {
{
return Http.url(url).get();
}
@Override
public List<String> getURLsFromPage(Document doc)
{
List<String> results = new ArrayList<String>(); List<String> results = new ArrayList<String>();
Elements imgs = doc.select(".album img"); Elements imgs = doc.select(".album img");
System.out.println(imgs.size() + " elements (thumbnails) found."); System.out.println(imgs.size() + " elements (thumbnails) found.");
for (Element img : imgs) for (Element img : imgs) {
{
String thumbURL = img.attr("data-src"); String thumbURL = img.attr("data-src");
String fullResURL = null; String fullResURL = null;
if (thumbURL.contains("imgspice.com")) if (thumbURL.contains("imgspice.com")) {
{
fullResURL = thumbURL.replace("_t.jpg", ".jpg"); fullResURL = thumbURL.replace("_t.jpg", ".jpg");
} } else if (thumbURL.contains("imagetwist.com")) {
else if (thumbURL.contains("imagetwist.com"))
{
fullResURL = thumbURL.replace("/th/", "/i/"); fullResURL = thumbURL.replace("/th/", "/i/");
} } else if (thumbURL.contains("pixhost.com")) {
else if (thumbURL.contains("pixhost.com"))
{
fullResURL = thumbURL.replace("https://t", "https://img"); fullResURL = thumbURL.replace("https://t", "https://img");
fullResURL = fullResURL.replace("/thumbs/", "/images/"); fullResURL = fullResURL.replace("/thumbs/", "/images/");
} } else if (thumbURL.contains("imx.to")) {
else if (thumbURL.contains("imx.to"))
{
fullResURL = thumbURL.replace("/t/", "/i/"); fullResURL = thumbURL.replace("/t/", "/i/");
} }
@@ -101,8 +76,7 @@ public class NsfwAlbumRipper extends AbstractHTMLRipper
} }
@Override @Override
public void downloadURL(URL url, int index) public void downloadURL(URL url, int index) {
{ addURLToDownload(url, getPrefix(index));
addURLToDownload(url);
} }
} }