mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-09-01 09:53:53 +02:00
Make TeenplanetRipper inherit from AbstractHTMLRipper, not AlbumRipper directly
This commit is contained in:
@@ -3,51 +3,66 @@ package com.rarchives.ripme.ripper.rippers;
|
|||||||
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.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
||||||
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 com.rarchives.ripme.ripper.AlbumRipper;
|
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
|
||||||
import com.rarchives.ripme.utils.Http;
|
import com.rarchives.ripme.utils.Http;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
public class TeenplanetRipper extends AlbumRipper {
|
public class TeenplanetRipper extends AbstractHTMLRipper {
|
||||||
|
|
||||||
private static final String DOMAIN = "teenplanet.org",
|
private static final String DOMAIN = "teenplanet.org",
|
||||||
HOST = "teenplanet";
|
HOST = "teenplanet";
|
||||||
|
|
||||||
private Document albumDoc = null;
|
|
||||||
|
|
||||||
public TeenplanetRipper(URL url) throws IOException {
|
public TeenplanetRipper(URL url) throws IOException {
|
||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getDomain() {
|
||||||
|
return DOMAIN;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return HOST;
|
return HOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL sanitizeURL(URL url) throws MalformedURLException {
|
@Override
|
||||||
return url;
|
protected Document getFirstPage() throws IOException {
|
||||||
|
return Http.url(url).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlbumTitle(URL url) throws MalformedURLException {
|
@Override
|
||||||
try {
|
protected List<String> getURLsFromPage(Document page) {
|
||||||
// Attempt to use album title as GID
|
List<String> imageURLs = new ArrayList<>();
|
||||||
if (albumDoc == null) {
|
for (Element thumb : page.select("#galleryImages > a > img")) {
|
||||||
albumDoc = Http.url(url).get();
|
if (!thumb.hasAttr("src")) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
Elements elems = albumDoc.select("div.header > h2");
|
String imageURL = thumb.attr("src");
|
||||||
return HOST + "_" + elems.get(0).text();
|
imageURL = imageURL.replace(
|
||||||
} catch (Exception e) {
|
"/thumbs/",
|
||||||
// Fall back to default album naming convention
|
"/");
|
||||||
e.printStackTrace();
|
imageURLs.add(imageURL);
|
||||||
}
|
}
|
||||||
return super.getAlbumTitle(url);
|
System.out.println("Found" + imageURLs.size() + " image urls");
|
||||||
|
return imageURLs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void downloadURL(URL url, int index) {
|
||||||
|
String prefix = "";
|
||||||
|
if (Utils.getConfigBoolean("download.save_order", true)) {
|
||||||
|
prefix = String.format("%03d_", index);
|
||||||
|
}
|
||||||
|
addURLToDownload(url, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,38 +80,4 @@ public class TeenplanetRipper extends AlbumRipper {
|
|||||||
+ "teenplanet.org/galleries/....html"
|
+ "teenplanet.org/galleries/....html"
|
||||||
+ " Got: " + url);
|
+ " Got: " + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void rip() throws IOException {
|
|
||||||
int index = 0;
|
|
||||||
LOGGER.info("Retrieving " + this.url);
|
|
||||||
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
|
|
||||||
if (albumDoc == null) {
|
|
||||||
albumDoc = Http.url(url).get();
|
|
||||||
}
|
|
||||||
for (Element thumb : albumDoc.select("#galleryImages > a > img")) {
|
|
||||||
if (!thumb.hasAttr("src")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String image = thumb.attr("src");
|
|
||||||
image = image.replace(
|
|
||||||
"/thumbs/",
|
|
||||||
"/");
|
|
||||||
index += 1;
|
|
||||||
String prefix = "";
|
|
||||||
if (Utils.getConfigBoolean("download.save_order", true)) {
|
|
||||||
prefix = String.format("%03d_", index);
|
|
||||||
}
|
|
||||||
addURLToDownload(new URL(image), prefix);
|
|
||||||
if (isThisATest()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
waitForThreads();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canRip(URL url) {
|
|
||||||
return url.getHost().endsWith(DOMAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user