2017-02-21 23:14:59 +01:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
|
|
import com.rarchives.ripme.utils.Http;
|
|
|
|
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;
|
|
|
|
|
|
|
|
public class MyhentaicomicsRipper extends AbstractHTMLRipper {
|
2017-10-24 16:33:28 +02:00
|
|
|
private static boolean isTag;
|
2017-02-21 23:14:59 +01:00
|
|
|
|
|
|
|
public MyhentaicomicsRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() {
|
|
|
|
return "myhentaicomics";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDomain() {
|
|
|
|
return "myhentaicomics.com";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^https?://myhentaicomics.com/index.php/([a-zA-Z0-9-]*)/?$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern pa = Pattern.compile("^https?://myhentaicomics.com/index.php/search\\?q=([a-zA-Z0-9-]*)([a-zA-Z0-9=&]*)?$");
|
|
|
|
Matcher ma = pa.matcher(url.toExternalForm());
|
|
|
|
if (ma.matches()) {
|
|
|
|
return ma.group(1);
|
|
|
|
}
|
|
|
|
|
2017-10-24 16:33:28 +02:00
|
|
|
Pattern pat = Pattern.compile("^https?://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+?=:]*)?$");
|
2017-02-21 23:14:59 +01:00
|
|
|
Matcher mat = pat.matcher(url.toExternalForm());
|
|
|
|
if (mat.matches()) {
|
|
|
|
return mat.group(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new MalformedURLException("Expected myhentaicomics.com URL format: " +
|
|
|
|
"myhentaicomics.com/index.php/albumName - got " + url + " instead");
|
|
|
|
}
|
|
|
|
|
2018-05-14 14:21:59 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasQueueSupport() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean pageContainsAlbums(URL url) {
|
|
|
|
Pattern pa = Pattern.compile("^https?://myhentaicomics.com/index.php/search\\?q=([a-zA-Z0-9-]*)([a-zA-Z0-9=&]*)?$");
|
|
|
|
Matcher ma = pa.matcher(url.toExternalForm());
|
|
|
|
if (ma.matches()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern pat = Pattern.compile("^https?://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+?=:]*)?$");
|
|
|
|
Matcher mat = pat.matcher(url.toExternalForm());
|
|
|
|
if (mat.matches()) {
|
|
|
|
isTag = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getAlbumsToQueue(Document doc) {
|
|
|
|
List<String> urlsToAddToQueue = new ArrayList<>();
|
|
|
|
for (Element elem : doc.select(".g-album > a")) {
|
|
|
|
urlsToAddToQueue.add(getDomain() + elem.attr("href"));
|
|
|
|
}
|
|
|
|
return urlsToAddToQueue;
|
|
|
|
}
|
|
|
|
|
2017-02-21 23:14:59 +01:00
|
|
|
@Override
|
|
|
|
public Document getFirstPage() throws IOException {
|
|
|
|
// "url" is an instance field of the superclass
|
|
|
|
return Http.url(url).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Document getNextPage(Document doc) throws IOException {
|
|
|
|
// Find next page
|
|
|
|
String nextUrl = "";
|
|
|
|
Element elem = doc.select("a.ui-icon-right").first();
|
|
|
|
String nextPage = elem.attr("href");
|
|
|
|
Pattern p = Pattern.compile("/index.php/[a-zA-Z0-9_-]*\\?page=\\d");
|
|
|
|
Matcher m = p.matcher(nextPage);
|
|
|
|
if (m.matches()) {
|
2018-05-22 17:28:44 +02:00
|
|
|
nextUrl = "https://myhentaicomics.com" + m.group(0);
|
2017-02-21 23:14:59 +01:00
|
|
|
}
|
2018-04-19 17:35:36 +02:00
|
|
|
if (nextUrl.equals("")) {
|
2017-02-21 23:14:59 +01:00
|
|
|
throw new IOException("No more pages");
|
|
|
|
}
|
|
|
|
// Sleep for half a sec to avoid getting IP banned
|
|
|
|
sleep(500);
|
|
|
|
return Http.url(nextUrl).get();
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:59:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromPage(Document doc) {
|
2017-10-24 16:33:28 +02:00
|
|
|
List<String> result = new ArrayList<>();
|
2017-02-21 23:14:59 +01:00
|
|
|
for (Element el : doc.select("img")) {
|
|
|
|
String imageSource = el.attr("src");
|
|
|
|
// This bool is here so we don't try and download the site logo
|
2017-10-15 17:56:50 +02:00
|
|
|
if (!imageSource.startsWith("http://") && !imageSource.startsWith("https://")) {
|
2017-02-21 23:14:59 +01:00
|
|
|
// We replace thumbs with resizes so we can the full sized images
|
|
|
|
imageSource = imageSource.replace("thumbs", "resizes");
|
2018-05-22 17:28:44 +02:00
|
|
|
result.add("https://myhentaicomics.com" + imageSource);
|
2017-02-21 23:14:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
2017-05-09 23:11:17 +02:00
|
|
|
addURLToDownload(url, getPrefix(index));
|
2017-02-21 23:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|