Merge pull request #684 from cyian-1756/da
DeviantartRipper now logs in using cookies
This commit is contained in:
commit
57f3133b49
@ -3,6 +3,7 @@ package com.rarchives.ripme.ripper.rippers;
|
|||||||
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
||||||
import com.rarchives.ripme.utils.Base64;
|
import com.rarchives.ripme.utils.Base64;
|
||||||
import com.rarchives.ripme.utils.Http;
|
import com.rarchives.ripme.utils.Http;
|
||||||
|
import com.rarchives.ripme.utils.RipUtils;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -37,6 +38,10 @@ public class DeviantartRipper extends AbstractHTMLRipper {
|
|||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String loginCookies = "auth=__0f9158aaec09f417b235%3B%221ff79836392a515d154216d919eae573%22;" +
|
||||||
|
"auth_secure=__41d14dd0da101f411bb0%3B%2281cf2cf9477776162a1172543aae85ce%22;" +
|
||||||
|
"userinfo=__bf84ac233bfa8ae642e8%3B%7B%22username%22%3A%22grabpy%22%2C%22uniqueid%22%3A%22a0a876aa37dbd4b30e1c80406ee9c280%22%2C%22vd%22%3A%22BbHUXZ%2CBbHUXZ%2CA%2CU%2CA%2C%2CB%2CA%2CB%2CBbHUXZ%2CBbHUdj%2CL%2CL%2CA%2CBbHUdj%2C13%2CA%2CB%2CA%2C%2CA%2CA%2CB%2CA%2CA%2C%2CA%22%2C%22attr%22%3A56%7D";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return "deviantart";
|
return "deviantart";
|
||||||
@ -117,24 +122,17 @@ public class DeviantartRipper extends AbstractHTMLRipper {
|
|||||||
@Override
|
@Override
|
||||||
public Document getFirstPage() throws IOException {
|
public Document getFirstPage() throws IOException {
|
||||||
|
|
||||||
//Test to see if there is a login:
|
// Base64 da login
|
||||||
String username = Utils.getConfigString("deviantart.username", new String(Base64.decode("Z3JhYnB5")));
|
// username: Z3JhYnB5
|
||||||
String password = Utils.getConfigString("deviantart.password", new String(Base64.decode("ZmFrZXJz")));
|
// password: ZmFrZXJz
|
||||||
|
|
||||||
if (username == null || password == null) {
|
|
||||||
LOGGER.debug("No DeviantArt login provided.");
|
cookies = getDACookies();
|
||||||
cookies.put("agegate_state","1"); // Bypasses the age gate
|
if (cookies.isEmpty()) {
|
||||||
} else {
|
LOGGER.warn("Failed to get login cookies");
|
||||||
// Attempt Login
|
|
||||||
try {
|
|
||||||
cookies = loginToDeviantart();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.warn("Failed to login: ", e);
|
|
||||||
cookies.put("agegate_state","1"); // Bypasses the age gate
|
cookies.put("agegate_state","1"); // Bypasses the age gate
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return Http.url(this.url)
|
return Http.url(this.url)
|
||||||
.cookies(cookies)
|
.cookies(cookies)
|
||||||
.get();
|
.get();
|
||||||
@ -426,47 +424,10 @@ public class DeviantartRipper extends AbstractHTMLRipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs into deviant art. Required to rip full-size NSFW content.
|
* Returns DA cookies.
|
||||||
* @return Map of cookies containing session data.
|
* @return Map of cookies containing session data.
|
||||||
*/
|
*/
|
||||||
private Map<String, String> loginToDeviantart() throws IOException {
|
private Map<String, String> getDACookies() {
|
||||||
// Populate postData fields
|
return RipUtils.getCookiesFromString(Utils.getConfigString("deviantart.cookies", loginCookies));
|
||||||
Map<String,String> postData = new HashMap<>();
|
|
||||||
String username = Utils.getConfigString("deviantart.username", new String(Base64.decode("Z3JhYnB5")));
|
|
||||||
String password = Utils.getConfigString("deviantart.password", new String(Base64.decode("ZmFrZXJz")));
|
|
||||||
if (username == null || password == null) {
|
|
||||||
throw new IOException("could not find username or password in config");
|
|
||||||
}
|
|
||||||
Response resp = Http.url("http://www.deviantart.com/")
|
|
||||||
.response();
|
|
||||||
for (Element input : resp.parse().select("form#form-login input[type=hidden]")) {
|
|
||||||
postData.put(input.attr("name"), input.attr("value"));
|
|
||||||
}
|
|
||||||
postData.put("username", username);
|
|
||||||
postData.put("password", password);
|
|
||||||
postData.put("remember_me", "1");
|
|
||||||
|
|
||||||
// Send login request
|
|
||||||
resp = Http.url("https://www.deviantart.com/users/login")
|
|
||||||
.userAgent(USER_AGENT)
|
|
||||||
.data(postData)
|
|
||||||
.cookies(resp.cookies())
|
|
||||||
.method(Method.POST)
|
|
||||||
.response();
|
|
||||||
|
|
||||||
// Assert we are logged in
|
|
||||||
if (resp.hasHeader("Location") && resp.header("Location").contains("password")) {
|
|
||||||
// Wrong password
|
|
||||||
throw new IOException("Wrong password");
|
|
||||||
}
|
|
||||||
if (resp.url().toExternalForm().contains("bad_form")) {
|
|
||||||
throw new IOException("Login form was incorrectly submitted");
|
|
||||||
}
|
|
||||||
if (resp.cookie("auth_secure") == null ||
|
|
||||||
resp.cookie("auth") == null) {
|
|
||||||
throw new IOException("No auth_secure or auth cookies received");
|
|
||||||
}
|
|
||||||
// We are logged in, save the cookies
|
|
||||||
return resp.cookies();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,9 +3,7 @@ package com.rarchives.ripme.utils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -279,4 +277,16 @@ public class RipUtils {
|
|||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Reads a cookie string (Key1=value1;key2=value2) from the config file and turns it into a hashmap
|
||||||
|
* @return Map of cookies containing session data.
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getCookiesFromString(String line) {
|
||||||
|
Map<String,String> cookies = new HashMap<>();
|
||||||
|
for (String pair : line.split(";")) {
|
||||||
|
String[] kv = pair.split("=");
|
||||||
|
cookies.put(kv[0], kv[1]);
|
||||||
|
}
|
||||||
|
return cookies;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user