Myhentaicomics ripper now rips all pages from tag and searches (#540)
* Now starts download right away when downloading from tags and searches * Now rips from searches/tags ASAP
This commit is contained in:
parent
89df4d7812
commit
0c507c23aa
@ -11,6 +11,8 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class MyhentaicomicsRipper extends AbstractHTMLRipper {
|
public class MyhentaicomicsRipper extends AbstractHTMLRipper {
|
||||||
public static boolean isTag;
|
public static boolean isTag;
|
||||||
@ -45,7 +47,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
|
|||||||
return ma.group(1);
|
return ma.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern pat = Pattern.compile("^http://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+\\?=:]*)?$");
|
Pattern pat = Pattern.compile("^https?://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+\\?=:]*)?$");
|
||||||
Matcher mat = pat.matcher(url.toExternalForm());
|
Matcher mat = pat.matcher(url.toExternalForm());
|
||||||
if (mat.matches()) {
|
if (mat.matches()) {
|
||||||
isTag = true;
|
isTag = true;
|
||||||
@ -113,70 +115,133 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
|
|||||||
return albumPagesList;
|
return albumPagesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAlbumsFromPage(String url) {
|
||||||
@Override
|
|
||||||
public List<String> getURLsFromPage(Document doc) {
|
|
||||||
List<String> result = new ArrayList<String>();
|
|
||||||
List<String> pagesToRip;
|
List<String> pagesToRip;
|
||||||
// Checks if this is a comic page or a page of albums
|
List<String> result = new ArrayList<String>();
|
||||||
if (doc.toString().contains("class=\"g-item g-album\"")) {
|
logger.info("Running getAlbumsFromPage");
|
||||||
for (Element elem : doc.select("li.g-album > a")) {
|
Document doc;
|
||||||
String link = elem.attr("href");
|
try {
|
||||||
logger.info("Grabbing album " + link);
|
doc = Http.url("http://myhentaicomics.com" + url).get();
|
||||||
pagesToRip = getNextAlbumPage(link);
|
} catch(IOException e){
|
||||||
logger.info(pagesToRip);
|
logger.warn("Failed to log link in Jsoup");
|
||||||
for (String element : pagesToRip) {
|
doc = null;
|
||||||
Document album_doc;
|
e.printStackTrace();
|
||||||
try {
|
}
|
||||||
logger.info("grabbing " + element + " with jsoup");
|
// This for goes over every album on the page
|
||||||
boolean startsWithhttp = element.startsWith("http");
|
for (Element elem : doc.select("li.g-album > a")) {
|
||||||
if (startsWithhttp == false) {
|
String link = elem.attr("href");
|
||||||
album_doc = Http.url("http://myhentaicomics.com/" + element).get();
|
logger.info("Grabbing album " + link);
|
||||||
}
|
pagesToRip = getNextAlbumPage(link);
|
||||||
else {
|
logger.info(pagesToRip);
|
||||||
album_doc = Http.url(element).get();
|
for (String element : pagesToRip) {
|
||||||
}
|
Document album_doc;
|
||||||
} catch(IOException e) {
|
try {
|
||||||
logger.warn("Failed to log link in Jsoup");
|
logger.info("grabbing " + element + " with jsoup");
|
||||||
album_doc = null;
|
boolean startsWithHttp = element.startsWith("http://");
|
||||||
e.printStackTrace();
|
if (!startsWithHttp) {
|
||||||
|
album_doc = Http.url("http://myhentaicomics.com/" + element).get();
|
||||||
}
|
}
|
||||||
for (Element el :album_doc.select("img")) {
|
else {
|
||||||
String imageSource = el.attr("src");
|
album_doc = Http.url(element).get();
|
||||||
// This bool is here so we don't try and download the site logo
|
}
|
||||||
boolean b = imageSource.startsWith("http");
|
} catch(IOException e){
|
||||||
if (b == false) {
|
logger.warn("Failed to log link in Jsoup");
|
||||||
// We replace thumbs with resizes so we can the full sized images
|
album_doc = null;
|
||||||
imageSource = imageSource.replace("thumbs", "resizes");
|
e.printStackTrace();
|
||||||
String url_string = "http://myhentaicomics.com/" + imageSource;
|
}
|
||||||
url_string = url_string.replace("%20", "_");
|
for (Element el :album_doc.select("img")) {
|
||||||
url_string = url_string.replace("%27", "");
|
String imageSource = el.attr("src");
|
||||||
url_string = url_string.replace("%28", "_");
|
// This bool is here so we don't try and download the site logo
|
||||||
url_string = url_string.replace("%29", "_");
|
if (!imageSource.startsWith("http://")) {
|
||||||
url_string = url_string.replace("%2C", "_");
|
// We replace thumbs with resizes so we can the full sized images
|
||||||
if (isTag == true) {
|
imageSource = imageSource.replace("thumbs", "resizes");
|
||||||
logger.info("Downloading from a tag or search");
|
String url_string = "http://myhentaicomics.com/" + imageSource;
|
||||||
try {
|
url_string = url_string.replace("%20", "_");
|
||||||
addURLToDownload(new URL("http://myhentaicomics.com/" + imageSource), "", url_string.split("/")[6]);
|
url_string = url_string.replace("%27", "");
|
||||||
}
|
url_string = url_string.replace("%28", "_");
|
||||||
catch(MalformedURLException e) {
|
url_string = url_string.replace("%29", "_");
|
||||||
logger.warn("Malformed URL");
|
url_string = url_string.replace("%2C", "_");
|
||||||
e.printStackTrace();
|
if (isTag == true) {
|
||||||
}
|
logger.info("Downloading from a tag or search");
|
||||||
|
try {
|
||||||
|
sleep(500);
|
||||||
result.add("http://myhentaicomics.com/" + imageSource);
|
result.add("http://myhentaicomics.com/" + imageSource);
|
||||||
|
addURLToDownload(new URL("http://myhentaicomics.com/" + imageSource), "", url_string.split("/")[6]);
|
||||||
|
}
|
||||||
|
catch(MalformedURLException e) {
|
||||||
|
logger.warn("Malformed URL");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getListOfPages(Document doc) {
|
||||||
|
List<String> pages = new ArrayList<String>();
|
||||||
|
// Get the link from the last button
|
||||||
|
String nextPageUrl = doc.select("a.ui-icon-right").last().attr("href");
|
||||||
|
Pattern pat = Pattern.compile("\\/index\\.php\\/tag\\/[0-9]*\\/[a-zA-Z0-9_\\-\\:+]*\\?page=(\\d+)");
|
||||||
|
Matcher mat = pat.matcher(nextPageUrl);
|
||||||
|
if (mat.matches()) {
|
||||||
|
logger.debug("Getting pages from a tag");
|
||||||
|
String base_link = mat.group(0).replaceAll("\\?page=\\d+", "");
|
||||||
|
logger.debug("base_link is " + base_link);
|
||||||
|
int numOfPages = Integer.parseInt(mat.group(1));
|
||||||
|
for (int x = 1; x != numOfPages +1; x++) {
|
||||||
|
logger.debug("running loop");
|
||||||
|
String link = base_link + "?page=" + Integer.toString(x);
|
||||||
|
pages.add(link);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Pattern pa = Pattern.compile("\\/index\\.php\\/search\\?q=[a-zA-Z0-9_\\-\\:]*\\&page=(\\d+)");
|
||||||
|
Matcher ma = pa.matcher(nextPageUrl);
|
||||||
|
if (ma.matches()) {
|
||||||
|
logger.debug("Getting pages from a search");
|
||||||
|
String base_link = ma.group(0).replaceAll("page=\\d+", "");
|
||||||
|
logger.debug("base_link is " + base_link);
|
||||||
|
int numOfPages = Integer.parseInt(ma.group(1));
|
||||||
|
for (int x = 1; x != numOfPages +1; x++) {
|
||||||
|
logger.debug("running loop");
|
||||||
|
String link = base_link + "page=" + Integer.toString(x);
|
||||||
|
logger.debug(link);
|
||||||
|
pages.add(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getURLsFromPage(Document doc) {
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
// Checks if this is a comic page or a page of albums
|
||||||
|
// If true the page is a page of albums
|
||||||
|
if (doc.toString().contains("class=\"g-item g-album\"")) {
|
||||||
|
// This if checks that there is more than 1 page
|
||||||
|
if (doc.select("a.ui-icon-right").last().attr("href") != "") {
|
||||||
|
// There is more than one page so we call getListOfPages
|
||||||
|
List<String> pagesToRip = getListOfPages(doc);
|
||||||
|
logger.debug("Pages to rip = " + pagesToRip);
|
||||||
|
for (String url : pagesToRip) {
|
||||||
|
logger.debug("Getting albums from " + url);
|
||||||
|
result = getAlbumsFromPage(url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.debug("There is only one page on this page of albums");
|
||||||
|
// There is only 1 page so we call getAlbumsFromPage and pass it the page url
|
||||||
|
result = getAlbumsFromPage(doc.select("div.g-description > a").attr("href"));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (Element el : doc.select("img")) {
|
for (Element el : doc.select("img")) {
|
||||||
String imageSource = el.attr("src");
|
String imageSource = el.attr("src");
|
||||||
// This bool is here so we don't try and download the site logo
|
// This bool is here so we don't try and download the site logo
|
||||||
boolean b = imageSource.startsWith("http");
|
if (!imageSource.startsWith("http://")) {
|
||||||
if (b == false) {
|
|
||||||
// We replace thumbs with resizes so we can the full sized images
|
// We replace thumbs with resizes so we can the full sized images
|
||||||
imageSource = imageSource.replace("thumbs", "resizes");
|
imageSource = imageSource.replace("thumbs", "resizes");
|
||||||
result.add("http://myhentaicomics.com/" + imageSource);
|
result.add("http://myhentaicomics.com/" + imageSource);
|
||||||
|
Loading…
Reference in New Issue
Block a user