SC model-dependent CDN host for master playlist
This commit is contained in:
parent
e583aad604
commit
0aa5dadda7
|
@ -93,6 +93,11 @@
|
|||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -30,6 +32,8 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
@ -196,6 +200,26 @@ public class StripchatModel extends AbstractModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getHlsUrlTemplate() throws IOException {
|
||||
log.trace("Loading URL template for {}", getName());
|
||||
Request req = new Request.Builder()
|
||||
.url(getSite().getBaseUrl() + "/api/front/v3/config/initial?requestPath=%2F" + getName() + "&timezoneOffset=0")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
JSONObject jsonResponse = new JSONObject(response.body().string());
|
||||
var common = jsonResponse.getJSONObject("initial").getJSONObject("common");
|
||||
var urlTemplate = common.getString("hlsStreamUrlTemplate");
|
||||
var host = common.getString("hlsStreamHost");
|
||||
|
||||
return urlTemplate.replace("{cdnHost}", host);
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getMasterPlaylistUrl() throws IOException {
|
||||
JSONObject info = getModelInfo();
|
||||
|
@ -215,8 +239,15 @@ public class StripchatModel extends AbstractModel {
|
|||
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 MessageFormat.format(hlsUrlTemplate, String.valueOf(id), vrSuffix, token);
|
||||
|
||||
// the master playlist host can vary per model
|
||||
String hlsUrlTemplate = getHlsUrlTemplate();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("streamName", String.valueOf(id) + vrSuffix);
|
||||
params.put("suffix", "_auto");
|
||||
|
||||
var result = StringSubstitutor.replace(hlsUrlTemplate, params, "{", "}") + "?playlistType=Standart" + token;
|
||||
return result;
|
||||
} else {
|
||||
throw new IOException("Playlist URL not found");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue