2017-08-12 22:28:06 +02:00
|
|
|
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.Connection.Response;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author losipher
|
|
|
|
*/
|
|
|
|
public class EromeRipper extends AbstractHTMLRipper {
|
|
|
|
|
2018-06-25 11:32:37 +02:00
|
|
|
boolean rippingProfile;
|
|
|
|
|
2017-08-12 22:28:06 +02:00
|
|
|
|
|
|
|
public EromeRipper (URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return "erome.com";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return "erome";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
|
|
|
}
|
|
|
|
|
2018-06-25 11:32:37 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasQueueSupport() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean pageContainsAlbums(URL url) {
|
|
|
|
Pattern pa = Pattern.compile("https?://www.erome.com/([a-zA-Z0-9_-]*)/?");
|
|
|
|
Matcher ma = pa.matcher(url.toExternalForm());
|
|
|
|
return ma.matches();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getAlbumsToQueue(Document doc) {
|
|
|
|
List<String> urlsToAddToQueue = new ArrayList<>();
|
|
|
|
for (Element elem : doc.select("div#albums > div.album > a")) {
|
|
|
|
urlsToAddToQueue.add(elem.attr("href"));
|
|
|
|
}
|
|
|
|
return urlsToAddToQueue;
|
|
|
|
}
|
|
|
|
|
2017-08-12 22:28:06 +02:00
|
|
|
@Override
|
|
|
|
public String getAlbumTitle(URL url) throws MalformedURLException {
|
|
|
|
try {
|
|
|
|
// Attempt to use album title as GID
|
|
|
|
Element titleElement = getFirstPage().select("meta[property=og:title]").first();
|
|
|
|
String title = titleElement.attr("content");
|
|
|
|
title = title.substring(title.lastIndexOf('/') + 1);
|
|
|
|
return getHost() + "_" + getGID(url) + "_" + title.trim();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Fall back to default album naming convention
|
2018-06-03 03:14:41 +02:00
|
|
|
LOGGER.info("Unable to find title at " + url);
|
2018-06-25 11:32:37 +02:00
|
|
|
} catch (NullPointerException e) {
|
|
|
|
return getHost() + "_" + getGID(url);
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
|
|
|
return super.getAlbumTitle(url);
|
|
|
|
}
|
|
|
|
|
2017-12-18 20:35:20 +01:00
|
|
|
@Override
|
|
|
|
public URL sanitizeURL(URL url) throws MalformedURLException {
|
|
|
|
return new URL(url.toExternalForm().replaceAll("https?://erome.com", "https://www.erome.com"));
|
|
|
|
}
|
|
|
|
|
2017-08-12 22:28:06 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
2017-10-24 16:33:28 +02:00
|
|
|
List<String> URLs = new ArrayList<>();
|
2018-06-25 11:32:37 +02:00
|
|
|
return getMediaFromPage(doc);
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
Response resp = Http.url(this.url)
|
|
|
|
.ignoreContentType()
|
|
|
|
.response();
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
return resp.parse();
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^https?://www.erome.com/a/([a-zA-Z0-9]*)/?$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
2017-12-18 20:35:20 +01:00
|
|
|
|
2018-06-25 11:32:37 +02:00
|
|
|
p = Pattern.compile("^https?://www.erome.com/([a-zA-Z0-9_-]+)/?$");
|
2017-12-18 20:35:20 +01:00
|
|
|
m = p.matcher(url.toExternalForm());
|
|
|
|
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException("erome album not found in " + url + ", expected https://www.erome.com/album");
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 11:32:37 +02:00
|
|
|
private List<String> getMediaFromPage(Document doc) {
|
|
|
|
List<String> results = new ArrayList<>();
|
|
|
|
for (Element el : doc.select("img.img-front")) {
|
|
|
|
results.add("https:" + el.attr("src"));
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
2018-06-25 11:32:37 +02:00
|
|
|
for (Element el : doc.select("source[label=HD]")) {
|
|
|
|
results.add("https:" + el.attr("src"));
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
2018-06-25 11:32:37 +02:00
|
|
|
return results;
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|
2018-06-25 11:32:37 +02:00
|
|
|
|
2017-08-12 22:28:06 +02:00
|
|
|
}
|