diff --git a/common/src/main/java/ctbrec/sites/stripchat/StripchatModel.java b/common/src/main/java/ctbrec/sites/stripchat/StripchatModel.java index 96072ef3..8746d6ee 100644 --- a/common/src/main/java/ctbrec/sites/stripchat/StripchatModel.java +++ b/common/src/main/java/ctbrec/sites/stripchat/StripchatModel.java @@ -8,7 +8,6 @@ import ctbrec.AbstractModel; import ctbrec.Config; import ctbrec.io.HttpException; import ctbrec.recorder.download.StreamSource; -import ctbrec.sites.Site; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -20,10 +19,10 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Objects; import java.util.concurrent.ExecutionException; import static ctbrec.Model.State.*; @@ -33,11 +32,10 @@ import static java.nio.charset.StandardCharsets.UTF_8; public class StripchatModel extends AbstractModel { private static final Logger LOG = LoggerFactory.getLogger(StripchatModel.class); + private String status = null; private int[] resolution = new int[]{0, 0}; - private static StripchatConfig stripchatConfig; - @Override public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { if (ignoreCache || status == null) { @@ -128,7 +126,6 @@ public class StripchatModel extends AbstractModel { } private String getMasterPlaylistUrl() throws IOException { - loadStripchatConfig(getSite()); String name = getName(); String url = getSite().getBaseUrl() + "/api/front/models/username/" + name + "/cam?triggerRequest=loadCam"; Request req = new Request.Builder() @@ -145,35 +142,8 @@ public class StripchatModel extends AbstractModel { String streamName = jsonResponse.optString("streamName", jsonResponse.optString("")); JSONObject viewServers = jsonResponse.getJSONObject("viewServers"); String serverName = viewServers.optString("flashphoner-hls"); - return "https://b-" + serverName + '.' + stripchatConfig.hlsStreamHost + "/hls/" + streamName + "/master/" + streamName + "_auto.m3u8"; - } else { - throw new HttpException(response.code(), response.message()); - } - } - } - - private static synchronized void loadStripchatConfig(Site site) throws IOException { - if (stripchatConfig != null) { - return; - } - Request req = new Request.Builder() - .url(site.getBaseUrl() + "/api/front/v2/config?uniq=g8wizmarpvck4dj5") - .header(ACCEPT, "*/*") - .header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage()) - .header(X_REQUESTED_WITH, XML_HTTP_REQUEST) - .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) - .header(REFERER, site.getBaseUrl()) - .build(); - - LOG.debug("Loading config from {}", req.url()); - try (Response response = site.getHttpClient().execute(req)) { - if (response.isSuccessful()) { - JSONObject json = new JSONObject(Objects.requireNonNull(response.body(), "HTTP response body is null").string()); - LOG.trace(json.toString(2)); - JSONObject config = json.getJSONObject("config"); - String hlsStreamHost = config.getString("hlsStreamHost"); - stripchatConfig = new StripchatConfig(); - stripchatConfig.hlsStreamHost = hlsStreamHost; + String hslUrlTemplate = "https://b-{0}.doppiocdn.com/hls/{1}/master/{1}_auto.m3u8"; + return MessageFormat.format(hslUrlTemplate, serverName, streamName); } else { throw new HttpException(response.code(), response.message()); } @@ -274,8 +244,4 @@ public class StripchatModel extends AbstractModel { } } } - - private static class StripchatConfig { - String hlsStreamHost; - } }