1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-09-01 01:51:56 +02:00

Merge Fix #1868 Imagebam Error : Change Layout

https://github.com/RipMeApp/ripme/issues/1868
https://github.com/RipMeApp/ripme/pull/1876
This commit is contained in:
soloturn
2021-05-22 00:01:34 +02:00
2 changed files with 9 additions and 16 deletions

View File

@@ -11,6 +11,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@@ -80,7 +82,7 @@ public class ImagebamRipper extends AbstractHTMLRipper {
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div > a[target=_blank]:not(.footera)")) {
for (Element thumb : doc.select("div > a[class=thumbnail]:not(.footera)")) {
imageURLs.add(thumb.attr("href"));
}
return imageURLs;
@@ -97,15 +99,12 @@ public class ImagebamRipper extends AbstractHTMLRipper {
public String getAlbumTitle(URL url) throws MalformedURLException {
try {
// Attempt to use album title as GID
Elements elems = getFirstPage().select("legend");
Elements elems = getFirstPage().select("[id=gallery-name]");
String title = elems.first().text();
LOGGER.info("Title text: '" + title + "'");
Pattern p = Pattern.compile("^(.*)\\s\\d* image.*$");
Matcher m = p.matcher(title);
if (m.matches()) {
return getHost() + "_" + getGID(url) + " (" + m.group(1).trim() + ")";
if (StringUtils.isNotBlank(title)) {
return getHost() + "_" + getGID(url) + " (" + title + ")";
}
LOGGER.info("Doesn't match " + p.pattern());
} catch (Exception e) {
// Fall back to default album naming convention
LOGGER.warn("Failed to get album title from " + url, e);
@@ -143,14 +142,9 @@ public class ImagebamRipper extends AbstractHTMLRipper {
Elements metaTags = doc.getElementsByTag("meta");
String imgsrc = "";//initialize, so no NullPointerExceptions should ever happen.
for (Element metaTag: metaTags) {
//the direct link to the image seems to always be linked in the <meta> part of the html.
if (metaTag.attr("property").equals("og:image")) {
imgsrc = metaTag.attr("content");
LOGGER.info("Found URL " + imgsrc);
break;//only one (useful) image possible for an "image page".
}
Elements elem = doc.select("img[class*=main-image]");
if ((elem != null) && (elem.size() > 0)) {
imgsrc = elem.first().attr("src");
}
//for debug, or something goes wrong.

View File

@@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test;
public class ImagebamRipperTest extends RippersTest {
@Test
@Tag("flaky")
public void testImagebamRip() throws IOException {
ImagebamRipper ripper = new ImagebamRipper(new URL("http://www.imagebam.com/gallery/488cc796sllyf7o5srds8kpaz1t4m78i"));
testRipper(ripper);