Skip to content

Commit

Permalink
EightmusesRipper fixed (#169)
Browse files Browse the repository at this point in the history
* EightmusesRipper fixed
  • Loading branch information
joroto authored Mar 11, 2024
1 parent f74c727 commit eb351d4
Showing 1 changed file with 9 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.rarchives.ripme.ripper.rippers;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.rarchives.ripme.utils.Utils;
import org.json.JSONObject;
import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -25,7 +20,7 @@

public class EightmusesRipper extends AbstractHTMLRipper {

private Map<String,String> cookies = new HashMap<>();
private Map<String, String> cookies = new HashMap<>();

public EightmusesRipper(URL url) throws IOException {
super(url);
Expand Down Expand Up @@ -82,10 +77,10 @@ public Document getFirstPage() throws IOException {
@Override
public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<>();
int x = 1;
// This contains the thumbnails of all images on the page
Elements pageImages = page.getElementsByClass("c-tile");
for (Element thumb : pageImages) {
for (int i = 0; i < pageImages.size(); i++) {
Element thumb = pageImages.get(i);
// If true this link is a sub album
if (thumb.attr("href").contains("/comics/album/")) {
String subUrl = "https://www.8muses.com" + thumb.attr("href");
Expand All @@ -109,24 +104,14 @@ public List<String> getURLsFromPage(Document page) {
if (thumb.hasAttr("data-cfsrc")) {
image = thumb.attr("data-cfsrc");
} else {
// Deobfustace the json data
String rawJson = deobfuscateJSON(page.select("script#ractive-public").html()
.replaceAll("&gt;", ">").replaceAll("&lt;", "<").replace("&amp;", "&"));
JSONObject json = new JSONObject(rawJson);
Element imageElement = thumb.select("img").first();
image = "https://comics.8muses.com" + imageElement.attr("data-src").replace("/th/", "/fl/");
try {
for (int i = 0; i != json.getJSONArray("pictures").length(); i++) {
image = "https://www.8muses.com/image/fl/" + json.getJSONArray("pictures").getJSONObject(i).getString("publicUri");
URL imageUrl = new URI(image).toURL();
addURLToDownload(imageUrl, getSubdir(page.select("title").text()), this.url.toExternalForm(), cookies, getPrefixShort(x), "", null, true);
// X is our page index
x++;
if (isThisATest()) {
break;
}
}
return imageURLs;
URL imageUrl = new URI(image).toURL();
addURLToDownload(imageUrl, getSubdir(page.select("title").text()), this.url.toExternalForm(), cookies, getPrefixShort(i), "", null, true);
} catch (MalformedURLException | URISyntaxException e) {
LOGGER.error("\"" + image + "\" is malformed");
LOGGER.error(e.getMessage());
}
}
if (!image.contains("8muses.com")) {
Expand Down Expand Up @@ -166,26 +151,4 @@ public String getPrefixLong(int index) {
public String getPrefixShort(int index) {
return String.format("%03d", index);
}

private String deobfuscateJSON(String obfuscatedString) {
StringBuilder deobfuscatedString = new StringBuilder();
// The first char in one of 8muses obfuscated strings is always ! so we replace it
for (char ch : obfuscatedString.replaceFirst("!", "").toCharArray()){
deobfuscatedString.append(deobfuscateChar(ch));
}
return deobfuscatedString.toString();
}

private String deobfuscateChar(char c) {
if ((int) c == 32) {
return fromCharCode(32);
} else if ((int) c > 120){
return fromCharCode((int)c);
}
return fromCharCode(33 + (c + 14) % 94);
}

private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}
}

0 comments on commit eb351d4

Please sign in to comment.