Got DeviantartRipper working again

This commit is contained in:
cyian-1756 2018-07-01 14:55:48 -04:00
parent 33a692be24
commit dab771f2da

View File

@ -148,8 +148,8 @@ public class DeviantartRipper extends AbstractJSONRipper {
JSONObject firstPageJSON = getFirstPageJSON(page); JSONObject firstPageJSON = getFirstPageJSON(page);
requestID = firstPageJSON.getJSONObject("dapx").getString("requestid"); requestID = firstPageJSON.getJSONObject("dapx").getString("requestid");
galleryID = page.select("input[name=set]").attr("value"); galleryID = getGalleryID(page);
username = page.select("div.tt-tv150").attr("username"); username = getUsername(page);
csrf = firstPageJSON.getString("csrf"); csrf = firstPageJSON.getString("csrf");
pageCookies = res.cookies(); pageCookies = res.cookies();
@ -190,6 +190,25 @@ public class DeviantartRipper extends AbstractJSONRipper {
return null; return null;
} }
private String getGalleryID(Document doc) {
for (Element el : doc.select("input[name=set]")) {
try {
String galleryID = el.attr("value");
if (galleryID.length() == 8) {
return galleryID;
}
} catch (NullPointerException e) {
continue;
}
}
LOGGER.error("Could not find gallery ID");
return null;
}
private String getUsername(Document doc) {
return doc.select("meta[property=og:title]").attr("content").replaceAll("'s DeviantArt gallery", "");
}
@Override @Override
public List<String> getURLsFromJSON(JSONObject json) { public List<String> getURLsFromJSON(JSONObject json) {
@ -197,7 +216,6 @@ public class DeviantartRipper extends AbstractJSONRipper {
LOGGER.info(json); LOGGER.info(json);
JSONArray results = json.getJSONObject("content").getJSONArray("results"); JSONArray results = json.getJSONObject("content").getJSONArray("results");
for (int i = 0; i < results.length(); i++) { for (int i = 0; i < results.length(); i++) {
LOGGER.info(results.getJSONObject(i).toString());
Document doc = Jsoup.parseBodyFragment(results.getJSONObject(i).getString("html")); Document doc = Jsoup.parseBodyFragment(results.getJSONObject(i).getString("html"));
try { try {
String imageURL = doc.select("span").first().attr("data-super-full-img"); String imageURL = doc.select("span").first().attr("data-super-full-img");
@ -240,12 +258,12 @@ public class DeviantartRipper extends AbstractJSONRipper {
throw new IOException("No more pages"); throw new IOException("No more pages");
} }
@Override // @Override
public boolean keepSortOrder() { // public boolean keepSortOrder() {
// Don't keep sort order (do not add prefixes). // // Don't keep sort order (do not add prefixes).
// Causes file duplication, as outlined in https://github.com/4pr0n/ripme/issues/113 // // Causes file duplication, as outlined in https://github.com/4pr0n/ripme/issues/113
return false; // return false;
} // }
@Override @Override
public void downloadURL(URL url, int index) { public void downloadURL(URL url, int index) {