mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-23 22:14:06 +02:00
Added ripper for Erofus.com
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
package com.rarchives.ripme.ripper.rippers;
|
||||
|
||||
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
||||
import com.rarchives.ripme.ui.RipStatusMessage;
|
||||
import com.rarchives.ripme.utils.Http;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ErofusRipper extends AbstractHTMLRipper {
|
||||
|
||||
private Document albumDoc = null;
|
||||
private Map<String,String> cookies = new HashMap<>();
|
||||
// TODO put up a wiki page on using maps to store titles
|
||||
// the map for storing the title of each album when downloading sub albums
|
||||
private Map<URL,String> urlTitles = new HashMap<>();
|
||||
|
||||
private Boolean rippingSubalbums = false;
|
||||
|
||||
public ErofusRipper(URL url) throws IOException {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasASAPRipping() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return "erofus";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomain() {
|
||||
return "erofus.com";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGID(URL url) throws MalformedURLException {
|
||||
Pattern p = Pattern.compile("^https://www.erofus.com/comics/([a-zA-Z0-9\\-_]+).*$");
|
||||
Matcher m = p.matcher(url.toExternalForm());
|
||||
if (!m.matches()) {
|
||||
throw new MalformedURLException("Expected URL format: http://www.8muses.com/index/category/albumname, got: " + url);
|
||||
}
|
||||
return m.group(m.groupCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getFirstPage() throws IOException {
|
||||
if (albumDoc == null) {
|
||||
Connection.Response resp = Http.url(url).response();
|
||||
cookies.putAll(resp.cookies());
|
||||
albumDoc = resp.parse();
|
||||
}
|
||||
return albumDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getURLsFromPage(Document page) {
|
||||
LOGGER.info(page);
|
||||
List<String> imageURLs = new ArrayList<>();
|
||||
int x = 1;
|
||||
if (pageContainsImages(page)) {
|
||||
LOGGER.info("Page contains images");
|
||||
imageURLs.addAll(ripAlbum(page));
|
||||
} else {
|
||||
// This contains the thumbnails of all images on the page
|
||||
Elements pageImages = page.select("a.a-click");
|
||||
for (Element pageLink : pageImages) {
|
||||
if (super.isStopped()) break;
|
||||
if (pageLink.attr("href").contains("comics")) {
|
||||
String subUrl = "https://erofus.com" + pageLink.attr("href");
|
||||
try {
|
||||
LOGGER.info("Retrieving " + subUrl);
|
||||
sendUpdate(RipStatusMessage.STATUS.LOADING_RESOURCE, subUrl);
|
||||
Document subPage = Http.url(subUrl).get();
|
||||
List<String> subalbumImages = getURLsFromPage(subPage);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Error while loading subalbum " + subUrl, e);
|
||||
}
|
||||
}
|
||||
if (isThisATest()) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return imageURLs;
|
||||
}
|
||||
|
||||
public List<String> ripAlbum(Document page) {
|
||||
int x = 1;
|
||||
List<String> imageURLs = new ArrayList<>();
|
||||
Elements thumbs = page.select("a.a-click > div.thumbnail > img");
|
||||
for (Element thumb : thumbs) {
|
||||
String image = "https://www.erofus.com" + thumb.attr("src").replaceAll("thumb", "medium");
|
||||
imageURLs.add(image);
|
||||
try {
|
||||
addURLToDownload(new URL(image), getPrefix(x));
|
||||
} catch (MalformedURLException e) {
|
||||
LOGGER.info(e.getMessage());
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return imageURLs;
|
||||
}
|
||||
|
||||
private boolean pageContainsImages(Document page) {
|
||||
Elements pageImages = page.select("a.a-click");
|
||||
for (Element pageLink : pageImages) {
|
||||
if (pageLink.attr("href").contains("/pic/")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadURL(URL url, int index) {
|
||||
addURLToDownload(url, getPrefix(index), "", this.url.toExternalForm(), cookies);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user