Use live previews for Stripchat thumbs where available
This commit is contained in:
parent
0c4cdfb795
commit
be225a1613
|
@ -0,0 +1,24 @@
|
|||
package ctbrec.ui.sites.stripchat;
|
||||
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public abstract class AbstractStripchatUpdateService extends PaginatedScheduledService {
|
||||
|
||||
protected String getPreviewUrl(JSONObject model) {
|
||||
try {
|
||||
long id = model.getLong("id");
|
||||
long timestamp = model.getLong("snapshotTimestamp");
|
||||
String snapshotServer = model.getString("snapshotServer");
|
||||
if (timestamp == 0 || StringUtil.isBlank(snapshotServer)) {
|
||||
throw new IllegalStateException("Model seems to be offline");
|
||||
}
|
||||
return MessageFormat.format("https://img.strpst.com/{0}/thumbs/{1}/{2}_jpg", snapshotServer, String.valueOf(timestamp), String.valueOf(id));
|
||||
} catch (Exception e) {
|
||||
return model.optString("previewUrlThumbBig");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,5 @@
|
|||
package ctbrec.ui.sites.stripchat;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -18,14 +7,24 @@ import ctbrec.sites.stripchat.Stripchat;
|
|||
import ctbrec.sites.stripchat.StripchatHttpClient;
|
||||
import ctbrec.sites.stripchat.StripchatModel;
|
||||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
public class StripchatFollowedUpdateService extends AbstractStripchatUpdateService {
|
||||
private static final int PAGE_SIZE = 30;
|
||||
private Stripchat stripchat;
|
||||
private static final String FAVORITES = "/favorites";
|
||||
private final Stripchat stripchat;
|
||||
|
||||
public StripchatFollowedUpdateService(Stripchat stripchat) {
|
||||
this.stripchat = stripchat;
|
||||
|
@ -33,7 +32,7 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<List<Model>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
return loadModels();
|
||||
|
@ -62,13 +61,13 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
List<Model> models = new ArrayList<>();
|
||||
var urlBuilder = HttpUrl.parse(stripchat.getBaseUrl() + "/api/front/models/list").newBuilder();
|
||||
for (var i = 0; i < modelIdsToLoad.size(); i++) {
|
||||
urlBuilder.addQueryParameter("modelIds["+i+"]", modelIdsToLoad.get(i).toString());
|
||||
urlBuilder.addQueryParameter("modelIds[" + i + "]", modelIdsToLoad.get(i).toString());
|
||||
}
|
||||
var request = new Request.Builder()
|
||||
.url(urlBuilder.build())
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(REFERER, Stripchat.baseUri + "/favorites")
|
||||
.header(REFERER, Stripchat.baseUri + FAVORITES)
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.build();
|
||||
try (var response = stripchat.getHttpClient().execute(request)) {
|
||||
|
@ -80,7 +79,7 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
var user = users.getJSONObject(i);
|
||||
StripchatModel model = stripchat.createModel(user.optString("username"));
|
||||
model.setDescription(user.optString("description"));
|
||||
model.setPreview(user.optString("previewUrlThumbBig"));
|
||||
model.setPreview(getPreviewUrl(user));
|
||||
model.setOnlineState(mapStatus(user.optString("status")));
|
||||
models.add(model);
|
||||
}
|
||||
|
@ -96,13 +95,13 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
SiteUiFactory.getUi(stripchat).login();
|
||||
stripchat.getHttpClient().login();
|
||||
long userId = ((StripchatHttpClient) stripchat.getHttpClient()).getUserId();
|
||||
String url = stripchat.getBaseUrl() + "/api/front/users/" + userId + "/favorites";
|
||||
String url = stripchat.getBaseUrl() + "/api/front/users/" + userId + FAVORITES;
|
||||
var request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri + "/favorites")
|
||||
.header(REFERER, Stripchat.baseUri + FAVORITES)
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.build();
|
||||
try (var response = stripchat.getHttpClient().execute(request)) {
|
||||
|
@ -121,15 +120,11 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
|
|||
}
|
||||
|
||||
protected ctbrec.Model.State mapStatus(String status) {
|
||||
switch (status) {
|
||||
case "public":
|
||||
return ONLINE;
|
||||
case "idle":
|
||||
return AWAY;
|
||||
case "off":
|
||||
return OFFLINE;
|
||||
default:
|
||||
return UNKNOWN;
|
||||
}
|
||||
return switch (status) {
|
||||
case "public" -> ONLINE;
|
||||
case "idle" -> AWAY;
|
||||
case "off" -> OFFLINE;
|
||||
default -> UNKNOWN;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import ctbrec.io.HttpException;
|
|||
import ctbrec.sites.stripchat.Stripchat;
|
||||
import ctbrec.sites.stripchat.StripchatModel;
|
||||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONObject;
|
||||
|
@ -14,6 +13,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -21,7 +22,7 @@ import java.util.Locale;
|
|||
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
public class StripchatUpdateService extends PaginatedScheduledService {
|
||||
public class StripchatUpdateService extends AbstractStripchatUpdateService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StripchatUpdateService.class);
|
||||
|
||||
|
@ -71,17 +72,18 @@ public class StripchatUpdateService extends PaginatedScheduledService {
|
|||
};
|
||||
}
|
||||
|
||||
private List<Model> parseModels(String body) {
|
||||
private List<Model> parseModels(String body) throws IOException {
|
||||
List<Model> models = new ArrayList<>();
|
||||
var json = new JSONObject(body);
|
||||
if (json.has("models")) {
|
||||
var jsonModels = json.getJSONArray("models");
|
||||
Files.writeString(Path.of("/tmp/sc-models.json"), jsonModels.toString(2));
|
||||
for (var i = 0; i < jsonModels.length(); i++) {
|
||||
var jsonModel = jsonModels.getJSONObject(i);
|
||||
try {
|
||||
StripchatModel model = stripchat.createModel(jsonModel.getString("username"));
|
||||
model.setDescription("");
|
||||
model.setPreview(jsonModel.optString("previewUrlThumbBig"));
|
||||
model.setPreview(getPreviewUrl(jsonModel));
|
||||
model.setDisplayName(model.getName());
|
||||
model.setOnlineState(Model.State.ONLINE);
|
||||
models.add(model);
|
||||
|
|
Loading…
Reference in New Issue