Fix follow / unfollow for Stripchat

This commit is contained in:
0xb00bface 2023-11-16 22:44:51 +01:00
parent 26071d59eb
commit f55a5fc644
3 changed files with 54 additions and 13 deletions

View File

@ -2,6 +2,7 @@
========================
* Fix one directory per group
* Add Stripchat tags thx to @winkru
* Fix follow / unfollow for Stripchat thx to @winkru
* Fix: Loading the config failed with model URLs, which contained spaces
5.2.2

View File

@ -6,16 +6,15 @@ import ctbrec.io.HttpClient;
import ctbrec.io.HttpException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.*;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.net.URLDecoder;
import static ctbrec.io.HttpConstants.*;
import static java.nio.charset.StandardCharsets.UTF_8;
@Slf4j
public class StripchatHttpClient extends HttpClient {
@ -96,7 +95,7 @@ public class StripchatHttpClient extends HttpClient {
}
private void loadCsrfToken() throws IOException {
String url = Stripchat.baseUri + "/api/front/v2/config?requestPath=%2F&timezoneOffset=0";
String url = Stripchat.baseUri + "/api/front/v2/config/data?requestPath=%2F&timezoneOffset=0";
Request request = new Request.Builder()
.url(url)
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
@ -112,6 +111,25 @@ public class StripchatHttpClient extends HttpClient {
csrfToken = data.optString("csrfToken");
csrfTimestamp = data.optString("csrfTimestamp");
csrfNotifyTimestamp = data.optString("csrfNotifyTimestamp");
} else {
throw new HttpException(response.code(), response.message());
}
}
}
private void loadJwtToken() throws IOException {
String url = Stripchat.baseUri + "/api/front/v2/config?requestPath=%2F&timezoneOffset=0";
Request request = new Request.Builder()
.url(url)
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
.header(USER_AGENT, config.getSettings().httpUserAgent)
.header(ORIGIN, Stripchat.baseUri)
.header(REFERER, Stripchat.baseUri)
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
.build();
try (Response response = execute(request)) {
if (response.isSuccessful()) {
JSONObject resp = new JSONObject(response.body().string());
JSONObject config = resp.getJSONObject("config");
jwtToken = config.optString("jwtToken");
} else {
@ -127,7 +145,7 @@ public class StripchatHttpClient extends HttpClient {
*/
public boolean checkLoginSuccess() throws IOException {
try {
loadCsrfToken();
loadJwtToken();
} catch (Exception e) {
log.info("Login check returned unsuccessful: {}", e.getLocalizedMessage());
return false;
@ -158,4 +176,15 @@ public class StripchatHttpClient extends HttpClient {
}
return userId;
}
public JSONObject getAmpl() {
try {
Cookie cookie = getCookieJar().getCookie(HttpUrl.parse(Stripchat.baseUri), "baseAmpl");
String json = URLDecoder.decode(cookie.value(), UTF_8);
JSONObject ampl = new JSONObject(json);
return ampl;
} catch (Exception ex) {
return new JSONObject();
}
}
}

View File

@ -25,10 +25,7 @@ import java.io.InputStream;
import java.text.MessageFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ExecutionException;
import static ctbrec.Model.State.*;
@ -42,7 +39,7 @@ public class StripchatModel extends AbstractModel {
private int[] resolution = new int[]{0, 0};
private int modelId = 0;
private boolean isVr = false;
private JSONObject modelInfo;
private transient JSONObject modelInfo;
private transient Instant lastInfoRequest = Instant.EPOCH;
@ -85,8 +82,8 @@ public class StripchatModel extends AbstractModel {
}
private JSONObject getModelInfo() throws IOException {
if (Duration.between(lastInfoRequest, Instant.now()).getSeconds() < 5) {
return Optional.ofNullable(modelInfo).orElse(new JSONObject());
if (Objects.nonNull(modelInfo) && Duration.between(lastInfoRequest, Instant.now()).getSeconds() < 5) {
return modelInfo;
}
lastInfoRequest = Instant.now();
modelInfo = loadModelInfo();
@ -251,6 +248,8 @@ public class StripchatModel extends AbstractModel {
requestParams.put("csrfToken", client.getCsrfToken());
requestParams.put("csrfTimestamp", client.getCsrfTimestamp());
requestParams.put("csrfNotifyTimestamp", client.getCsrfNotifyTimestamp());
requestParams.put("uniq", getUniq());
requestParams.put("ampl", client.getAmpl());
RequestBody body = RequestBody.Companion.create(requestParams.toString(), JSON);
Request request = new Request.Builder()
.url(url)
@ -286,6 +285,7 @@ public class StripchatModel extends AbstractModel {
requestParams.put("csrfToken", client.getCsrfToken());
requestParams.put("csrfTimestamp", client.getCsrfTimestamp());
requestParams.put("csrfNotifyTimestamp", client.getCsrfNotifyTimestamp());
requestParams.put("uniq", getUniq());
RequestBody body = RequestBody.Companion.create(requestParams.toString(), JSON);
Request request = new Request.Builder()
.url(url)
@ -335,4 +335,15 @@ public class StripchatModel extends AbstractModel {
return new MergedFfmpegHlsDownload(getSite().getHttpClient());
}
}
protected String getUniq() {
Random r = new Random();
String dict = "0123456789abcdefghijklmnopqarstvwxyz";
char[] text = new char[16];
for (int i = 0; i < 16; i++) {
text[i] = dict.charAt(r.nextInt(dict.length()));
}
return new String(text);
}
}