ImgScroll/src/main/java/com/rarchives/ripme/ripper/rippers/JagodibujaRipper.java

79 lines
2.3 KiB
Java
Raw Normal View History

2017-03-29 10:08:15 +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.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http;
public class JagodibujaRipper extends AbstractHTMLRipper {
public JagodibujaRipper(URL url) throws IOException {
2017-04-25 19:09:00 +02:00
super(url);
2017-03-29 10:08:15 +02:00
}
2017-04-25 19:09:00 +02:00
@Override
public String getHost() {
return "jagodibuja";
}
2017-03-29 10:08:15 +02:00
2017-04-25 19:09:00 +02:00
@Override
public String getDomain() {
return "jagodibuja.com";
}
2017-03-29 10:08:15 +02:00
2017-04-25 19:09:00 +02:00
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://www.jagodibuja.com/([a-zA-Z0-9_-]*)/?");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
2017-03-29 10:08:15 +02:00
}
2017-04-25 19:09:00 +02:00
throw new MalformedURLException("Expected jagodibuja.com gallery formats hwww.jagodibuja.com/Comic name/ got " + url + " instead");
}
2017-03-29 10:08:15 +02:00
2017-04-25 19:09:00 +02:00
@Override
public Document getFirstPage() throws IOException {
// "url" is an instance field of the superclass
return Http.url(url).get();
}
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>();
2017-04-25 19:09:00 +02:00
for (Element comicPageUrl : doc.select("div.gallery-icon > a")) {
try {
sleep(500);
Document comicPage = Http.url(comicPageUrl.attr("href")).get();
Element elem = comicPage.select("span.full-size-link > a").first();
2018-06-03 03:14:41 +02:00
LOGGER.info("Got link " + elem.attr("href"));
2017-03-29 14:04:19 +02:00
try {
2017-04-25 19:09:00 +02:00
addURLToDownload(new URL(elem.attr("href")), "");
} catch (MalformedURLException e) {
2018-06-03 03:14:41 +02:00
LOGGER.warn("Malformed URL");
2017-04-25 19:09:00 +02:00
e.printStackTrace();
2017-03-29 14:04:19 +02:00
}
2017-04-25 19:09:00 +02:00
result.add(elem.attr("href"));
} catch (IOException e) {
2018-06-03 03:14:41 +02:00
LOGGER.info("Error loading " + comicPageUrl);
2017-03-29 14:04:19 +02:00
}
2017-03-29 10:08:15 +02:00
}
2017-04-25 19:09:00 +02:00
return result;
}
2017-03-29 10:08:15 +02:00
2017-04-25 19:09:00 +02:00
@Override
public void downloadURL(URL url, int index) {
// sleep(500);
// addURLToDownload(url, getPrefix(index));
2017-03-29 10:08:15 +02:00
}
2017-04-25 19:09:00 +02:00
}