forked from j62/ctbrec
Fix chaturbate follow/unfollow response parsing
This commit is contained in:
parent
985ce12f52
commit
52cdc82044
|
@ -15,6 +15,7 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -211,11 +212,12 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
||||||
.url(getUrl())
|
.url(getUrl())
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.build();
|
.build();
|
||||||
Response resp = site.getHttpClient().execute(req);
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
resp.close();
|
// do an initial request to get cookies
|
||||||
|
}
|
||||||
|
|
||||||
String url = null;
|
String url = null;
|
||||||
if(follow) {
|
if (follow) {
|
||||||
url = getSite().getBaseUrl() + "/follow/follow/" + getName() + "/";
|
url = getSite().getBaseUrl() + "/follow/follow/" + getName() + "/";
|
||||||
} else {
|
} else {
|
||||||
url = getSite().getBaseUrl() + "/follow/unfollow/" + getName() + "/";
|
url = getSite().getBaseUrl() + "/follow/unfollow/" + getName() + "/";
|
||||||
|
@ -232,19 +234,20 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
||||||
.header("X-CSRFToken", ((ChaturbateHttpClient)site.getHttpClient()).getToken())
|
.header("X-CSRFToken", ((ChaturbateHttpClient)site.getHttpClient()).getToken())
|
||||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.build();
|
.build();
|
||||||
resp = site.getHttpClient().execute(req);
|
try (Response resp2 = site.getHttpClient().execute(req)) {
|
||||||
if(resp.isSuccessful()) {
|
if (resp2.isSuccessful()) {
|
||||||
String msg = resp.body().string();
|
String responseBody = resp2.body().string();
|
||||||
if(!msg.equalsIgnoreCase("ok")) {
|
JSONObject json = new JSONObject(responseBody);
|
||||||
LOG.debug(msg);
|
if (!json.has("following")) {
|
||||||
throw new IOException("Response was " + msg.substring(0, Math.min(msg.length(), 500)));
|
LOG.debug(responseBody);
|
||||||
|
throw new IOException("Response was " + responseBody.substring(0, Math.min(responseBody.length(), 500)));
|
||||||
|
} else {
|
||||||
|
LOG.debug("Follow/Unfollow -> {}", responseBody);
|
||||||
|
return json.getBoolean("following") == follow;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("Follow/Unfollow -> {}", msg);
|
throw new HttpException(resp2.code(), resp2.message());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
resp.close();
|
|
||||||
throw new IOException("HTTP status " + resp.code() + " " + resp.message());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue