From b94f64652d456ac411da9d94b07cff87c41501d1 Mon Sep 17 00:00:00 2001 From: saladzic Date: Mon, 8 Feb 2021 04:39:54 +0100 Subject: [PATCH] Fix #1830 + add config option "erome.laravel_session" for EromeRipper to avoid JS-Browser-Check --- .../ripme/ripper/rippers/EromeRipper.java | 77 ++++++++++++------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/EromeRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/EromeRipper.java index 9b586b9a..b44d34d4 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/EromeRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/EromeRipper.java @@ -4,10 +4,12 @@ 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.regex.Matcher; import java.util.regex.Pattern; +import com.rarchives.ripme.utils.Utils; import org.jsoup.Connection.Response; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -23,7 +25,7 @@ import com.rarchives.ripme.utils.Http; public class EromeRipper extends AbstractHTMLRipper { boolean rippingProfile; - + private HashMap cookies = new HashMap<>(); public EromeRipper (URL url) throws IOException { super(url); @@ -31,12 +33,12 @@ public class EromeRipper extends AbstractHTMLRipper { @Override public String getDomain() { - return "erome.com"; + return "erome.com"; } @Override public String getHost() { - return "erome"; + return "erome"; } @Override @@ -67,19 +69,19 @@ public class EromeRipper extends AbstractHTMLRipper { @Override public String getAlbumTitle(URL url) throws MalformedURLException { - try { - // Attempt to use album title as GID - Element titleElement = getFirstPage().select("meta[property=og:title]").first(); - String title = titleElement.attr("content"); - title = title.substring(title.lastIndexOf('/') + 1); - return getHost() + "_" + getGID(url) + "_" + title.trim(); - } catch (IOException e) { - // Fall back to default album naming convention - LOGGER.info("Unable to find title at " + url); - } catch (NullPointerException e) { - return getHost() + "_" + getGID(url); - } - return super.getAlbumTitle(url); + try { + // Attempt to use album title as GID + Element titleElement = getFirstPage().select("meta[property=og:title]").first(); + String title = titleElement.attr("content"); + title = title.substring(title.lastIndexOf('/') + 1); + return getHost() + "_" + getGID(url) + "_" + title.trim(); + } catch (IOException e) { + // Fall back to default album naming convention + LOGGER.info("Unable to find title at " + url); + } catch (NullPointerException e) { + return getHost() + "_" + getGID(url); + } + return super.getAlbumTitle(url); } @Override @@ -96,9 +98,11 @@ public class EromeRipper extends AbstractHTMLRipper { @Override public Document getFirstPage() throws IOException { + this.setAuthCookie(); Response resp = Http.url(this.url) - .ignoreContentType() - .response(); + .cookies(cookies) + .ignoreContentType() + .response(); return resp.parse(); } @@ -124,18 +128,18 @@ public class EromeRipper extends AbstractHTMLRipper { private List getMediaFromPage(Document doc) { List results = new ArrayList<>(); for (Element el : doc.select("img.img-front")) { - if (el.hasAttr("src")) { - if (el.attr("src").startsWith("https:")) { - results.add(el.attr("src")); - } else { - results.add("https:" + el.attr("src")); - } - } else if (el.hasAttr("data-src")) { - //to add images that are not loaded( as all images are lasyloaded as we scroll). - results.add(el.attr("data-src")); - } + if (el.hasAttr("src")) { + if (el.attr("src").startsWith("https:")) { + results.add(el.attr("src")); + } else { + results.add("https:" + el.attr("src")); + } + } else if (el.hasAttr("data-src")) { + //to add images that are not loaded( as all images are lasyloaded as we scroll). + results.add(el.attr("data-src")); + } - } + } for (Element el : doc.select("source[label=HD]")) { if (el.attr("src").startsWith("https:")) { results.add(el.attr("src")); @@ -152,7 +156,22 @@ public class EromeRipper extends AbstractHTMLRipper { results.add("https:" + el.attr("src")); } } + + if (results.size() == 0) { + if (cookies.isEmpty()) { + LOGGER.warn("You might try setting erome.laravel_session manually " + + "if you think this page definitely contains media."); + } + } + return results; } + private void setAuthCookie() { + String sessionId = Utils.getConfigString("erome.laravel_session", null); + if (sessionId != null) { + cookies.put("laravel_session", sessionId); + } + } + }