Fix SC spy show auth token

This commit is contained in:
Jafea7 2025-04-22 21:17:02 +10:00
parent 7bd51fb6e2
commit 239831daa8
1 changed files with 19 additions and 132 deletions

View File

@ -48,10 +48,12 @@ public class StripchatModel extends AbstractModel {
@Override @Override
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
JSONObject info; JSONObject info = getModelInfo();
if (ignoreCache && (info = getModelInfo()).has("user")) { if (ignoreCache && info.has("user")) {
JSONObject cam;
JSONObject user = info.getJSONObject("user").getJSONObject("user"); JSONObject user = info.getJSONObject("user").getJSONObject("user");
if (info.has("cam")) {
JSONObject cam = info.getJSONObject("cam");
}
String status = user.optString("status"); String status = user.optString("status");
mapOnlineState(status); mapOnlineState(status);
if (onlineState == OFFLINE) { if (onlineState == OFFLINE) {
@ -59,10 +61,10 @@ public class StripchatModel extends AbstractModel {
} }
if (isBanned(user)) { if (isBanned(user)) {
log.debug("Model inactive or deleted: {}", getName()); log.debug("Model inactive or deleted: {}", getName());
// Config.getInstance().setModelNotes(this, "Model inactive or deleted"); // Config.getInstance().setModelNotes(this, "Model inactive or deleted"); <- from v5.0.24
setMarkedForLaterRecording(true); setMarkedForLaterRecording(true);
} }
if (onlineState == PRIVATE && info.has("cam") && StringUtil.isNotBlank((cam = info.getJSONObject("cam")).optString(KEY_MODEL_TOKEN))) { if (onlineState == PRIVATE && StringUtil.isNotBlank((cam.optString(KEY_MODEL_TOKEN))) {
setOnlineState(ONLINE); setOnlineState(ONLINE);
return true; return true;
} }
@ -70,37 +72,6 @@ public class StripchatModel extends AbstractModel {
return onlineState == ONLINE; return onlineState == ONLINE;
} }
// @Override
// public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
// JSONObject jsonResponse = getModelInfo();
// if (ignoreCache) {
// if (jsonResponse.has("user")) {
// JSONObject user = jsonResponse.getJSONObject("user").getJSONObject("user");
// String status = user.optString("status");
// mapOnlineState(status);
// if (onlineState == OFFLINE) {
// setLastSeen(user.optString("statusChangedAt"));
// }
// if (isBanned(user)) {
// log.debug("Model inactive or deleted: {}", getName());
// setMarkedForLaterRecording(true);
// }
// if ((onlineState == PRIVATE) && jsonResponse.has("cam")) {
// JSONObject cam = jsonResponse.getJSONObject("cam");
// if (StringUtil.isNotBlank(cam.optString(KEY_MODEL_TOKEN))) {
// setOnlineState(ONLINE);
// return true;
// }
// }
// }
// if (jsonResponse.optString("error").equals("Not Found")) {
// setMarkedForLaterRecording(true);
// setOnlineState(OFFLINE);
// }
// }
// return onlineState == ONLINE;
// }
private boolean isBanned(JSONObject user) { private boolean isBanned(JSONObject user) {
boolean isDeleted = user.optBoolean("isDeleted", false); boolean isDeleted = user.optBoolean("isDeleted", false);
boolean isApprovedModel = user.optBoolean("isApprovedModel", true); boolean isApprovedModel = user.optBoolean("isApprovedModel", true);
@ -119,45 +90,17 @@ public class StripchatModel extends AbstractModel {
private void mapOnlineState(String status) { private void mapOnlineState(String status) {
switch (status) { switch (status) {
case "public": { case "public" -> setOnlineState(ONLINE);
setOnlineState(Model.State.ONLINE); case "idle" -> setOnlineState(AWAY);
break; case "private", "p2p", "groupShow", "virtualPrivate" -> setOnlineState(PRIVATE);
} case "off" -> setOnlineState(OFFLINE);
case "idle": { default -> {
setOnlineState(Model.State.AWAY);
break;
}
case "private":
case "p2p":
case "groupShow":
case "virtualPrivate": {
setOnlineState(Model.State.PRIVATE);
break;
}
case "off": {
setOnlineState(Model.State.OFFLINE);
break;
}
default: {
log.debug("Unknown online state {} for model {}", status, getName()); log.debug("Unknown online state {} for model {}", status, getName());
setOnlineState(Model.State.OFFLINE); setOnlineState(OFFLINE);
} }
} }
} }
// private void mapOnlineState(String status) {
// switch (status) {
// case "public" -> setOnlineState(ONLINE);
// case "idle" -> setOnlineState(AWAY);
// case "private", "p2p", "groupShow", "virtualPrivate" -> setOnlineState(PRIVATE);
// case "off" -> setOnlineState(OFFLINE);
// default -> {
// log.debug("Unknown online state {} for model {}", status, getName());
// setOnlineState(OFFLINE);
// }
// }
// }
private JSONObject getModelInfo() throws IOException { private JSONObject getModelInfo() throws IOException {
if (Objects.nonNull(modelInfo) && Duration.between(lastInfoRequest, Instant.now()).getSeconds() < 5) { if (Objects.nonNull(modelInfo) && Duration.between(lastInfoRequest, Instant.now()).getSeconds() < 5) {
return modelInfo; return modelInfo;
@ -190,27 +133,6 @@ public class StripchatModel extends AbstractModel {
} }
} }
// private JSONObject loadModelInfo() throws IOException {
// String url = getSite().getBaseUrl() + "/api/front/v2/models/username/" + getName() + "/cam?timezoneOffset=0&triggerRequest=loadCam&uniq=" + getUniq();
// Request req = new Request.Builder()
// .url(url)
// .header(ACCEPT, MIMETYPE_APPLICATION_JSON)
// .header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
// .header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
// .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
// .header(REFERER, getUrl())
// .header(ORIGIN, getSite().getBaseUrl())
// .build();
// try (Response response = site.getHttpClient().execute(req)) {
// if (response.isSuccessful()) {
// JSONObject jsonResponse = new JSONObject(response.body().string());
// return jsonResponse;
// } else {
// throw new HttpException(response.code(), response.message());
// }
// }
// }
private void checkIfRenamed(String responseText) { private void checkIfRenamed(String responseText) {
try { try {
String newName; String newName;
@ -223,7 +145,7 @@ public class StripchatModel extends AbstractModel {
if (modelGroup.isPresent()) { if (modelGroup.isPresent()) {
modelGroup.get().add(newUrl); modelGroup.get().add(newUrl);
} }
// Config.getInstance().setModelNotes(this, "Old username: " + oldName); // Config.getInstance().setModelNotes(this, "Old username: " + oldName); <- From v5.0.24
setName(newName); setName(newName);
setUrl(newUrl); setUrl(newUrl);
log.warn("Model {} renamed to {}", (Object)oldName, (Object)newName); log.warn("Model {} renamed to {}", (Object)oldName, (Object)newName);
@ -236,12 +158,7 @@ public class StripchatModel extends AbstractModel {
@Override @Override
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException { public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
log.debug("getStreamSources: modelInfo = \n{}", modelInfo.toString(2)); // Added
String url = getMasterPlaylistUrl(); String url = getMasterPlaylistUrl();
log.debug("getStreamSources: url = {}", url); // Added
MasterPlaylist masterPlaylist = getMasterPlaylist(url); MasterPlaylist masterPlaylist = getMasterPlaylist(url);
List<StreamSource> streamSources = extractStreamSources(masterPlaylist); List<StreamSource> streamSources = extractStreamSources(masterPlaylist);
try { try {
@ -272,6 +189,7 @@ public class StripchatModel extends AbstractModel {
src.setHeight(playlist.getStreamInfo().getResolution().height); src.setHeight(playlist.getStreamInfo().getResolution().height);
src.setWidth(playlist.getStreamInfo().getResolution().width); src.setWidth(playlist.getStreamInfo().getResolution().width);
src.setMediaPlaylistUrl(playlist.getUri()); src.setMediaPlaylistUrl(playlist.getUri());
// v5.3.2 commented out - truncating auth token
// if (src.getMediaPlaylistUrl().contains("?")) { // if (src.getMediaPlaylistUrl().contains("?")) {
// src.setMediaPlaylistUrl(src.getMediaPlaylistUrl().substring(0, src.getMediaPlaylistUrl().lastIndexOf('?'))); // src.setMediaPlaylistUrl(src.getMediaPlaylistUrl().substring(0, src.getMediaPlaylistUrl().lastIndexOf('?')));
// } // }
@ -290,44 +208,18 @@ public class StripchatModel extends AbstractModel {
try (Response response = getSite().getHttpClient().execute(req)) { try (Response response = getSite().getHttpClient().execute(req)) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
String body = response.body().string(); String body = response.body().string();
log.debug(body);
InputStream inputStream = new ByteArrayInputStream(body.getBytes(UTF_8)); InputStream inputStream = new ByteArrayInputStream(body.getBytes(UTF_8));
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT); PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist playlist = parser.parse(); Playlist playlist = parser.parse();
MasterPlaylist master = playlist.getMasterPlaylist(); MasterPlaylist master = playlist.getMasterPlaylist();
return master; return master;
} // else { }
throw new HttpException(response.code(), response.message()); throw new HttpException(response.code(), response.message());
// }
} }
} }
// private String getMasterPlaylistUrl() throws IOException {
// JSONObject info = getModelInfo();
// if (info.has("user")) {
// JSONObject cam;
// JSONObject user = info.getJSONObject("user").getJSONObject("user");
// long modelId = user.optLong("id");
// boolean saveVR = Config.getInstance().getSettings().stripchatVR;
// boolean isVRStream = user.optBoolean("isVr", false);
// String vrSuffix = (saveVR && isVRStream) ? "_vr" : "";
// Object token = "";
// if (info.has("cam") && StringUtil.isNotBlank((cam = info.getJSONObject("cam")).optString(KEY_MODEL_TOKEN))) {
// log.debug("Cam token: {}", token); // Added
// token = "&aclAuth=" + cam.getString(KEY_MODEL_TOKEN);
// log.debug("Spy start for {}", getName());
// }
// String hlsUrlTemplate = "https://edge-hls.doppiocdn.com/hls/{0}/master/{0}_auto.m3u8?playlistType=Standart{1}";
// return MessageFormat.format(hlsUrlTemplate, String.valueOf(modelId), token);
// }
// throw new IOException("Playlist URL not found");
// }
private String getMasterPlaylistUrl() throws IOException { private String getMasterPlaylistUrl() throws IOException {
JSONObject info = getModelInfo(); JSONObject info = getModelInfo();
log.debug("getMasterPlaylistUrl: modelInfo = \n{}", info.toString(2)); // Added
if (info.has("user")) { if (info.has("user")) {
JSONObject user = info.getJSONObject("user").getJSONObject("user"); JSONObject user = info.getJSONObject("user").getJSONObject("user");
long id = user.optLong("id"); long id = user.optLong("id");
@ -340,15 +232,10 @@ public class StripchatModel extends AbstractModel {
if (info.has("cam")) { if (info.has("cam")) {
JSONObject cam = info.getJSONObject("cam"); JSONObject cam = info.getJSONObject("cam");
token = cam.optString(KEY_MODEL_TOKEN); token = cam.optString(KEY_MODEL_TOKEN);
log.debug("getMasterPlaylistUrl: Cam token: {}", token); // Added
if (StringUtil.isNotBlank(token)) { if (StringUtil.isNotBlank(token)) {
token = "&aclAuth=" + token; token = "&aclAuth=" + token;
log.debug("Spy start for {}", getName()); log.debug("Spy start for {}", getName());
} }
// if (StringUtil.isNotBlank(cam.optString(KEY_MODEL_TOKEN))) {
// token = "&aclAuth=" + cam.getString(KEY_MODEL_TOKEN);
// log.debug("Spy start for {}", getName());
// }
} }
String hlsUrlTemplate = "https://edge-hls.doppiocdn.com/hls/{0}{1}/master/{0}{1}_auto.m3u8?playlistType=Standart{2}"; String hlsUrlTemplate = "https://edge-hls.doppiocdn.com/hls/{0}{1}/master/{0}{1}_auto.m3u8?playlistType=Standart{2}";
return MessageFormat.format(hlsUrlTemplate, String.valueOf(id), vrSuffix, token); return MessageFormat.format(hlsUrlTemplate, String.valueOf(id), vrSuffix, token);
@ -436,7 +323,7 @@ public class StripchatModel extends AbstractModel {
long id = user.optLong("id"); long id = user.optLong("id");
long userId = client.getUserId(); long userId = client.getUserId();
JSONArray favoriteIds = new JSONArray().put(id); JSONArray favoriteIds = new JSONArray().put(id);
// favoriteIds.put(id); // favoriteIds.put(id); <- v5.3.2 duplication of above
String url = Stripchat.getBaseUri() + "/api/front/users/" + client.getUserId() + "/favorites"; String url = Stripchat.getBaseUri() + "/api/front/users/" + client.getUserId() + "/favorites";
JSONObject eventData = StripchatUtil.getEventData() JSONObject eventData = StripchatUtil.getEventData()