forked from j62/ctbrec
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:
parent
cdaeaa746b
commit
2eacbae228
|
@ -1,6 +1,8 @@
|
||||||
3.10.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)
|
* Added setting to switch FFmpeg logging on/off (category Advanced/Devtools)
|
||||||
|
|
||||||
3.10.7
|
3.10.7
|
||||||
|
|
|
@ -7,14 +7,16 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.iheartradio.m3u8.ParseException;
|
import com.iheartradio.m3u8.ParseException;
|
||||||
import com.iheartradio.m3u8.PlaylistException;
|
import com.iheartradio.m3u8.PlaylistException;
|
||||||
|
@ -29,6 +31,7 @@ import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class StripchatModel extends AbstractModel {
|
public class StripchatModel extends AbstractModel {
|
||||||
|
private static final transient Logger LOG = LoggerFactory.getLogger(StripchatModel.class);
|
||||||
private String status = null;
|
private String status = null;
|
||||||
private int[] resolution = new int[] {0, 0};
|
private int[] resolution = new int[] {0, 0};
|
||||||
|
|
||||||
|
@ -39,13 +42,28 @@ public class StripchatModel extends AbstractModel {
|
||||||
if (jsonResponse.has("user")) {
|
if (jsonResponse.has("user")) {
|
||||||
JSONObject user = jsonResponse.getJSONObject("user");
|
JSONObject user = jsonResponse.getJSONObject("user");
|
||||||
status = user.optString("status");
|
status = user.optString("status");
|
||||||
|
mapOnlineState(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean online = Objects.equals(status, "public");
|
return onlineState == ONLINE;
|
||||||
if (online) {
|
}
|
||||||
|
|
||||||
|
private void mapOnlineState(String status) {
|
||||||
|
switch (status) {
|
||||||
|
case "public":
|
||||||
setOnlineState(ONLINE);
|
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 {
|
private JSONObject loadModelInfo() throws IOException {
|
||||||
|
@ -84,7 +102,7 @@ public class StripchatModel extends AbstractModel {
|
||||||
try (Response response = site.getHttpClient().execute(req)) {
|
try (Response response = site.getHttpClient().execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject jsonResponse = new JSONObject(response.body().string());
|
JSONObject jsonResponse = new JSONObject(response.body().string());
|
||||||
String streamName = jsonResponse.optString("streamName");
|
String streamName = jsonResponse.optString("streamName", jsonResponse.optString(""));
|
||||||
JSONObject viewServers = jsonResponse.getJSONObject("viewServers");
|
JSONObject viewServers = jsonResponse.getJSONObject("viewServers");
|
||||||
String serverName = viewServers.optString("flashphoner-hls");
|
String serverName = viewServers.optString("flashphoner-hls");
|
||||||
JSONObject broadcastSettings = jsonResponse.getJSONObject("broadcastSettings");
|
JSONObject broadcastSettings = jsonResponse.getJSONObject("broadcastSettings");
|
||||||
|
@ -92,18 +110,20 @@ public class StripchatModel extends AbstractModel {
|
||||||
StreamSource best = new StreamSource();
|
StreamSource best = new StreamSource();
|
||||||
best.height = broadcastSettings.optInt("height");
|
best.height = broadcastSettings.optInt("height");
|
||||||
best.width = broadcastSettings.optInt("width");
|
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);
|
sources.add(best);
|
||||||
JSONObject resolutions = broadcastSettings.optJSONObject("resolutions");
|
JSONObject presets = broadcastSettings.optJSONObject("presets");
|
||||||
if (resolutions instanceof JSONObject) {
|
Object defaultObject = presets.get("testing");
|
||||||
JSONArray heights = resolutions.names();
|
if (defaultObject instanceof JSONObject) {
|
||||||
|
JSONObject defaults = (JSONObject) defaultObject;
|
||||||
|
JSONArray heights = defaults.names();
|
||||||
for (int i = 0; i < heights.length(); i++) {
|
for (int i = 0; i < heights.length(); i++) {
|
||||||
String h = heights.getString(i);
|
String h = heights.getString(i);
|
||||||
StreamSource streamSource = new StreamSource();
|
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();
|
streamSource.width = streamSource.height * best.getWidth() / best.getHeight();
|
||||||
String source = streamName + "-" + streamSource.height + "p";
|
String source = streamName + '_' + streamSource.height + 'p';
|
||||||
streamSource.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + source + "/" + source + ".m3u8";
|
streamSource.mediaPlaylistUrl = "https://b-" + serverName + ".stripst.com/hls/" + source + '/' + source + ".m3u8";
|
||||||
sources.add(streamSource);
|
sources.add(streamSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,9 +131,13 @@ public class StripchatModel extends AbstractModel {
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
} catch(JSONException e) {
|
||||||
|
System.err.println(getName());
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateCacheEntries() {
|
public void invalidateCacheEntries() {
|
||||||
status = null;
|
status = null;
|
||||||
|
|
Loading…
Reference in New Issue