2014-04-21 09:02:56 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AlbumRipper;
|
2014-06-20 13:09:36 +02:00
|
|
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-05-26 09:31:58 +02:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-04-21 09:02:56 +02:00
|
|
|
|
|
|
|
public class TeenplanetRipper extends AlbumRipper {
|
|
|
|
|
|
|
|
private static final String DOMAIN = "teenplanet.org",
|
|
|
|
HOST = "teenplanet";
|
|
|
|
|
|
|
|
private Document albumDoc = null;
|
|
|
|
|
|
|
|
public TeenplanetRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return HOST;
|
|
|
|
}
|
|
|
|
|
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
return url;
|
|
|
|
}
|
2017-06-19 19:32:57 +02:00
|
|
|
|
2014-04-21 09:02:56 +02:00
|
|
|
public String getAlbumTitle(URL url) throws MalformedURLException {
|
|
|
|
try {
|
|
|
|
// Attempt to use album title as GID
|
|
|
|
if (albumDoc == null) {
|
2014-06-22 02:08:42 +02:00
|
|
|
albumDoc = Http.url(url).get();
|
2014-04-21 09:02:56 +02:00
|
|
|
}
|
|
|
|
Elements elems = albumDoc.select("div.header > h2");
|
2014-04-21 09:16:46 +02:00
|
|
|
return HOST + "_" + elems.get(0).text();
|
2014-04-21 09:02:56 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
// Fall back to default album naming convention
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return super.getAlbumTitle(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p; Matcher m;
|
|
|
|
|
|
|
|
p = Pattern.compile("^.*teenplanet.org/galleries/([a-zA-Z0-9\\-]+).html$");
|
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected teenplanet.org gallery format: "
|
|
|
|
+ "teenplanet.org/galleries/....html"
|
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void rip() throws IOException {
|
|
|
|
int index = 0;
|
2018-06-03 03:14:41 +02:00
|
|
|
LOGGER.info("Retrieving " + this.url);
|
2014-06-20 13:09:36 +02:00
|
|
|
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
|
2014-04-21 09:02:56 +02:00
|
|
|
if (albumDoc == null) {
|
2014-06-22 02:08:42 +02:00
|
|
|
albumDoc = Http.url(url).get();
|
2014-04-21 09:02:56 +02:00
|
|
|
}
|
|
|
|
for (Element thumb : albumDoc.select("#galleryImages > a > img")) {
|
|
|
|
if (!thumb.hasAttr("src")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String image = thumb.attr("src");
|
|
|
|
image = image.replace(
|
|
|
|
"/thumbs/",
|
|
|
|
"/");
|
|
|
|
index += 1;
|
2014-05-26 09:31:58 +02:00
|
|
|
String prefix = "";
|
|
|
|
if (Utils.getConfigBoolean("download.save_order", true)) {
|
|
|
|
prefix = String.format("%03d_", index);
|
|
|
|
}
|
|
|
|
addURLToDownload(new URL(image), prefix);
|
2015-02-10 08:29:29 +01:00
|
|
|
if (isThisATest()) {
|
|
|
|
break;
|
|
|
|
}
|
2014-04-21 09:02:56 +02:00
|
|
|
}
|
|
|
|
waitForThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canRip(URL url) {
|
|
|
|
return url.getHost().endsWith(DOMAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|