Fixed EightmusesRipper

This commit is contained in:
cyian-1756 2018-07-24 23:49:53 -04:00
parent cbfd363842
commit af33869e52

View File

@ -11,6 +11,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.rarchives.ripme.utils.Utils; import com.rarchives.ripme.utils.Utils;
import org.json.JSONObject;
import org.jsoup.Connection.Response; import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -116,14 +117,13 @@ public class EightmusesRipper extends AbstractHTMLRipper {
image = thumb.attr("data-cfsrc"); image = thumb.attr("data-cfsrc");
} }
else { else {
String imageHref = thumb.attr("href"); // Deobfustace the json data
if (imageHref.equals("")) continue; String rawJson = deobfuscateJSON(page.select("script#ractive-public").html()
if (imageHref.startsWith("/")) { .replaceAll("&gt;", ">").replaceAll("&lt;", "<").replace("&amp;", "&"));
imageHref = "https://www.8muses.com" + imageHref; JSONObject json = new JSONObject(rawJson);
}
try { try {
LOGGER.info("Retrieving full-size image location from " + imageHref); for (int i = 0; i != json.getJSONArray("pictures").length(); i++) {
image = getFullSizeImage(imageHref); image = "https://www.8muses.com/image/fm/" + json.getJSONArray("pictures").getJSONObject(i).getString("publicUri");
URL imageUrl = new URL(image); URL imageUrl = new URL(image);
if (Utils.getConfigBoolean("8muses.use_short_names", false)) { if (Utils.getConfigBoolean("8muses.use_short_names", false)) {
addURLToDownload(imageUrl, getPrefixShort(x), getSubdir(page.select("title").text()), this.url.toExternalForm(), cookies, "", null, true); addURLToDownload(imageUrl, getPrefixShort(x), getSubdir(page.select("title").text()), this.url.toExternalForm(), cookies, "", null, true);
@ -132,9 +132,9 @@ public class EightmusesRipper extends AbstractHTMLRipper {
} }
// X is our page index // X is our page index
x++; x++;
}
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Failed to get full-size image from " + imageHref);
continue; continue;
} }
} }
@ -154,7 +154,7 @@ public class EightmusesRipper extends AbstractHTMLRipper {
sendUpdate(STATUS.LOADING_RESOURCE, imageUrl); sendUpdate(STATUS.LOADING_RESOURCE, imageUrl);
LOGGER.info("Getting full sized image from " + imageUrl); LOGGER.info("Getting full sized image from " + imageUrl);
Document doc = new Http(imageUrl).get(); // Retrieve the webpage of the image URL Document doc = new Http(imageUrl).get(); // Retrieve the webpage of the image URL
String imageName = doc.select("input[id=imageName]").attr("value"); // Select the "input" element from the page String imageName = doc.select("div.photo > a > img").attr("src");
return "https://www.8muses.com/image/fm/" + imageName; return "https://www.8muses.com/image/fm/" + imageName;
} }
@ -189,4 +189,28 @@ public class EightmusesRipper extends AbstractHTMLRipper {
public String getPrefixShort(int index) { public String getPrefixShort(int index) {
return String.format("%03d", index); return String.format("%03d", index);
} }
private String deobfuscateJSON(String obfuscatedString) {
LOGGER.info("obfuscatedString: " + 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()){
LOGGER.info(ch + ":" + deobfuscateChar(ch));
LOGGER.info((int) ch + ":" + (int) deobfuscateChar(ch).charAt(0));
deobfuscatedString.append(deobfuscateChar(ch));
}
return deobfuscatedString.toString();
}
private String deobfuscateChar(char c) {
if ((int) c == 32) {
return fromCharCode(32);
}
return fromCharCode(33 + (c + 14) % 94);
}
private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}
} }