SC cleanup
This commit is contained in:
parent
4dd0b4034d
commit
8e3f28f737
|
@ -6,7 +6,7 @@ import com.iheartradio.m3u8.data.Playlist;
|
||||||
import com.iheartradio.m3u8.data.PlaylistData;
|
import com.iheartradio.m3u8.data.PlaylistData;
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
// import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.ModelGroup;
|
import ctbrec.ModelGroup;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
|
@ -46,38 +46,15 @@ public class StripchatModel extends AbstractModel {
|
||||||
private transient JSONObject modelInfo;
|
private transient JSONObject modelInfo;
|
||||||
private transient Instant lastInfoRequest = Instant.EPOCH;
|
private transient Instant lastInfoRequest = Instant.EPOCH;
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
|
||||||
// JSONObject info;
|
|
||||||
// if (ignoreCache && (info = getModelInfo()).has("user")) {
|
|
||||||
// JSONObject cam;
|
|
||||||
// JSONObject user = info.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());
|
|
||||||
// // Config.getInstance().setModelNotes(this, "Model inactive or deleted"); // <- from v5.0.24
|
|
||||||
// setMarkedForLaterRecording(true);
|
|
||||||
// }
|
|
||||||
// if (onlineState == PRIVATE && info.has("cam") && StringUtil.isNotBlank((cam = info.getJSONObject("cam")).optString(KEY_MODEL_TOKEN))) {
|
|
||||||
// setOnlineState(ONLINE);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return onlineState == ONLINE;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
JSONObject jsonResponse = getModelInfo();
|
JSONObject jsonResponse = getModelInfo();
|
||||||
if (ignoreCache) {
|
|
||||||
if (jsonResponse.has("user")) {
|
if (ignoreCache && jsonResponse.has("user")) {
|
||||||
JSONObject user = jsonResponse.getJSONObject("user").getJSONObject("user");
|
JSONObject user = jsonResponse.getJSONObject("user").getJSONObject("user");
|
||||||
String status = user.optString("status");
|
String status = user.optString("status");
|
||||||
mapOnlineState(status);
|
mapOnlineState(status);
|
||||||
|
|
||||||
if (onlineState == OFFLINE) {
|
if (onlineState == OFFLINE) {
|
||||||
setLastSeen(user.optString("statusChangedAt"));
|
setLastSeen(user.optString("statusChangedAt"));
|
||||||
}
|
}
|
||||||
|
@ -85,12 +62,11 @@ public class StripchatModel extends AbstractModel {
|
||||||
log.debug("Model inactive or deleted: {}", getName());
|
log.debug("Model inactive or deleted: {}", getName());
|
||||||
setMarkedForLaterRecording(true);
|
setMarkedForLaterRecording(true);
|
||||||
}
|
}
|
||||||
if ((onlineState == PRIVATE) && jsonResponse.has("cam")) {
|
if (onlineState == PRIVATE && jsonResponse.has("cam")) {
|
||||||
JSONObject cam = jsonResponse.getJSONObject("cam");
|
JSONObject cam = jsonResponse.getJSONObject("cam");
|
||||||
if (StringUtil.isNotBlank(cam.optString(KEY_MODEL_TOKEN))) {
|
if (StringUtil.isNotBlank(cam.optString(KEY_MODEL_TOKEN))) {
|
||||||
setOnlineState(ONLINE);
|
setOnlineState(ONLINE);
|
||||||
return true;
|
return true; // Model is online PRIVATE and there's a valid token
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jsonResponse.optString("error").equals("Not Found")) {
|
if (jsonResponse.optString("error").equals("Not Found")) {
|
||||||
|
@ -117,34 +93,6 @@ public class StripchatModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void mapOnlineState(String status) {
|
|
||||||
// switch (status) {
|
|
||||||
// case "public": {
|
|
||||||
// setOnlineState(Model.State.ONLINE);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case "idle": {
|
|
||||||
// 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());
|
|
||||||
// setOnlineState(Model.State.OFFLINE);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void mapOnlineState(String status) {
|
private void mapOnlineState(String status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "public" -> setOnlineState(ONLINE);
|
case "public" -> setOnlineState(ONLINE);
|
||||||
|
@ -190,27 +138,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;
|
||||||
|
@ -236,12 +163,9 @@ 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
|
// log.debug("getStreamSources: modelInfo = \n{}", modelInfo.toString(2)); // Added
|
||||||
|
|
||||||
String url = getMasterPlaylistUrl();
|
String url = getMasterPlaylistUrl();
|
||||||
|
// log.debug("getStreamSources: url = {}", url); // Added
|
||||||
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 {
|
||||||
|
@ -276,7 +200,6 @@ public class StripchatModel extends AbstractModel {
|
||||||
// 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('?')));
|
||||||
// }
|
// }
|
||||||
log.debug("Media playlist {}", src.getMediaPlaylistUrl());
|
|
||||||
sources.add(src);
|
sources.add(src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,40 +214,17 @@ 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);
|
// 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 {
|
} 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();
|
||||||
|
@ -346,13 +246,8 @@ public class StripchatModel extends AbstractModel {
|
||||||
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}";
|
return "https://edge-hls.doppiocdn.com/hls/" + id + vrSuffix + "/master/" + id + vrSuffix + "_auto.m3u8?playlistType=Standart" + token;
|
||||||
return MessageFormat.format(hlsUrlTemplate, String.valueOf(id), vrSuffix, token);
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Playlist URL not found");
|
throw new IOException("Playlist URL not found");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue