forked from j62/ctbrec
1
0
Fork 0

Fix Stripchat recordings

For some models the recording didn't start, even if they were online and
publicly visible in the browser. We now use a different JSON object to
determine, which resolutions are available
This commit is contained in:
0xb00bface 2020-12-12 21:06:38 +01:00
parent cdaeaa746b
commit 2eacbae228
2 changed files with 39 additions and 13 deletions

View File

@ -1,6 +1,8 @@
3.10.8
========================
* Fixed Bongacams "New" tab
* Fixed Stripchat recordings. For some models the recording didn't start,
even if they were online and publicly visible in the browser
* Fixed Bongacams "New" tab. It didn't show new models.
* Added setting to switch FFmpeg logging on/off (category Advanced/Devtools)
3.10.7

View File

@ -7,14 +7,16 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javax.xml.bind.JAXBException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.iheartradio.m3u8.ParseException;
import com.iheartradio.m3u8.PlaylistException;
@ -29,6 +31,7 @@ import okhttp3.RequestBody;
import okhttp3.Response;
public class StripchatModel extends AbstractModel {
private static final transient Logger LOG = LoggerFactory.getLogger(StripchatModel.class);
private String status = null;
private int[] resolution = new int[] {0, 0};
@ -39,13 +42,28 @@ public class StripchatModel extends AbstractModel {
if (jsonResponse.has("user")) {
JSONObject user = jsonResponse.getJSONObject("user");
status = user.optString("status");
mapOnlineState(status);
}
}
boolean online = Objects.equals(status, "public");
if (online) {
return onlineState == ONLINE;
}
private void mapOnlineState(String status) {
switch (status) {
case "public":
setOnlineState(ONLINE);
break;
case "idle":
setOnlineState(AWAY);
break;
case "private":
setOnlineState(PRIVATE);
break;
default:
LOG.debug("Unknown online state {} for model {}", status, getName());
setOnlineState(OFFLINE);
break;
}
return online;
}
private JSONObject loadModelInfo() throws IOException {
@ -84,7 +102,7 @@ public class StripchatModel extends AbstractModel {
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
JSONObject jsonResponse = new JSONObject(response.body().string());
String streamName = jsonResponse.optString("streamName");
String streamName = jsonResponse.optString("streamName", jsonResponse.optString(""));
JSONObject viewServers = jsonResponse.getJSONObject("viewServers");
String serverName = viewServers.optString("flashphoner-hls");
JSONObject broadcastSettings = jsonResponse.getJSONObject("broadcastSettings");
@ -92,18 +110,20 @@ public class StripchatModel extends AbstractModel {
StreamSource best = new StreamSource();
best.height = broadcastSettings.optInt("height");
best.width = broadcastSettings.optInt("width");
best.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + streamName + "/" + streamName + ".m3u8";
best.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + streamName + '/' + streamName + ".m3u8";
sources.add(best);
JSONObject resolutions = broadcastSettings.optJSONObject("resolutions");
if (resolutions instanceof JSONObject) {
JSONArray heights = resolutions.names();
JSONObject presets = broadcastSettings.optJSONObject("presets");
Object defaultObject = presets.get("testing");
if (defaultObject instanceof JSONObject) {
JSONObject defaults = (JSONObject) defaultObject;
JSONArray heights = defaults.names();
for (int i = 0; i < heights.length(); i++) {
String h = heights.getString(i);
StreamSource streamSource = new StreamSource();
streamSource.height = Integer.parseInt(h.replace("p", ""));
streamSource.height = Integer.parseInt(h.replaceAll("[^\\d]", ""));
streamSource.width = streamSource.height * best.getWidth() / best.getHeight();
String source = streamName + "-" + streamSource.height + "p";
streamSource.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + source + "/" + source + ".m3u8";
String source = streamName + '_' + streamSource.height + 'p';
streamSource.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + source + '/' + source + ".m3u8";
sources.add(streamSource);
}
}
@ -111,9 +131,13 @@ public class StripchatModel extends AbstractModel {
} else {
throw new HttpException(response.code(), response.message());
}
} catch(JSONException e) {
System.err.println(getName());
throw e;
}
}
@Override
public void invalidateCacheEntries() {
status = null;