forked from j62/ctbrec
Adjust to Stripchat API changes
This commit is contained in:
parent
a91923baff
commit
33a0094b19
|
@ -19,9 +19,8 @@ import ctbrec.sites.stripchat.StripchatModel;
|
|||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
||||
|
@ -44,28 +43,22 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
|
||||
private List<Model> loadModels(JSONArray favoriteModelIds) throws IOException {
|
||||
List<Model> models = new ArrayList<>();
|
||||
StripchatHttpClient client = (StripchatHttpClient) stripchat.getHttpClient();
|
||||
String url = stripchat.getBaseUrl() + "/api/front/users/list";
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("userIds", favoriteModelIds);
|
||||
requestParams.put("csrfToken", client.getCsrfToken());
|
||||
requestParams.put("csrfTimestamp", client.getCsrfTimestamp());
|
||||
requestParams.put("csrfNotifyTimestamp", client.getCsrfNotifyTimestamp());
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), requestParams.toString());
|
||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(stripchat.getBaseUrl() + "/api/front/models/list").newBuilder();
|
||||
for (int i = 0; i < favoriteModelIds.length(); i++) {
|
||||
urlBuilder.addQueryParameter("modelIds["+i+"]", Integer.toString(favoriteModelIds.getInt(i)));
|
||||
}
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.url(urlBuilder.build())
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.BASE_URI)
|
||||
.header(REFERER, Stripchat.BASE_URI + "/favorites")
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.post(body)
|
||||
.build();
|
||||
try (Response response = stripchat.getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
if (json.has("users")) {
|
||||
JSONArray users = json.getJSONArray("users");
|
||||
if (json.has("models")) {
|
||||
JSONArray users = json.getJSONArray("models");
|
||||
for (int i = 0; i < users.length(); i++) {
|
||||
JSONObject user = users.getJSONObject(i);
|
||||
StripchatModel model = stripchat.createModel(user.optString("username"));
|
||||
|
|
|
@ -81,7 +81,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
}
|
||||
|
||||
private void loadCsrfToken() throws IOException {
|
||||
String url = Stripchat.BASE_URI + "/api/front/config";
|
||||
String url = Stripchat.BASE_URI + "/api/front/v2/config/data?requestPath=%2F&timezoneOffset=0";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ctbrec.sites.stripchat;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,7 +43,11 @@ public class StripchatModel extends AbstractModel {
|
|||
status = user.optString("status");
|
||||
}
|
||||
}
|
||||
return Objects.equals(status, "public");
|
||||
boolean online = Objects.equals(status, "public");
|
||||
if (online) {
|
||||
setOnlineState(ONLINE);
|
||||
}
|
||||
return online;
|
||||
}
|
||||
|
||||
private JSONObject loadModelInfo() throws IOException {
|
||||
|
@ -153,10 +158,10 @@ public class StripchatModel extends AbstractModel {
|
|||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), requestParams.toString());
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.BASE_URI)
|
||||
.header(REFERER, Stripchat.BASE_URI)
|
||||
.header(REFERER, Stripchat.BASE_URI + '/' + getName())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.put(body)
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue