Use high res stream URL and fallback to low res on error
This commit is contained in:
parent
1784b20719
commit
114acad34c
|
@ -9,6 +9,8 @@
|
|||
* Fixed ConcurrentModificationException, which caused the recorded models tab
|
||||
to turn blank
|
||||
* Fixed recordings not stopping, if playlist requests returned 403 or 404
|
||||
* LiveJasmin recordings no first check the high res stream and fall back to
|
||||
the low res stream, if it is not available
|
||||
|
||||
4.4.3
|
||||
========================
|
||||
|
|
|
@ -165,11 +165,30 @@ public class LiveJasminModel extends AbstractModel {
|
|||
new Random().nextBytes(sessionIdRandom);
|
||||
String sessionId = 'g' + StringUtil.toHexString(sessionIdRandom, 32);
|
||||
|
||||
String url = "https://api-gateway.dditsadn.com/v1/stream/performers/" + getName()
|
||||
+ "/streams/free/formats/hls?brandId=jasmin&session=" + sessionId + "&streamName=stream_1280_720_1953";
|
||||
LOG.debug("Getting master playlist URL from {}", url);
|
||||
String highResUrl = "https://api-gateway.dditsadn.com/v1/stream/performers/" + getName() + "/streams/free/formats/hls?brandId=jasmin&session=" + sessionId + "&streamName=stream_1280_720_3000";
|
||||
String lowResUrl = "https://api-gateway.dditsadn.com/v1/stream/performers/" + getName() + "/streams/free/formats/hls?brandId=jasmin&session=" + sessionId + "&streamName=stream_1280_720_1953";
|
||||
|
||||
String body;
|
||||
try {
|
||||
body = getMasterPlaylistUrl(highResUrl);
|
||||
} catch (Exception e) {
|
||||
LOG.debug("High resolution URL not available for {}. Falling back to low res.", getName());
|
||||
body= getMasterPlaylistUrl(lowResUrl);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(body);
|
||||
if (json.has("data")) {
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
return data.getString("url");
|
||||
} else {
|
||||
throw new IOException("Response was not successful: " + lowResUrl + "\n" + body);
|
||||
}
|
||||
}
|
||||
|
||||
private String getMasterPlaylistUrl(String fromUrl) throws IOException {
|
||||
LOG.debug("Getting master playlist URL from {}", fromUrl);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.url(fromUrl)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgentMobile)
|
||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
|
@ -178,14 +197,7 @@ public class LiveJasminModel extends AbstractModel {
|
|||
.build();
|
||||
try (Response response = site.getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
String body = response.body().string();
|
||||
JSONObject json = new JSONObject(body);
|
||||
if (json.has("data")) {
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
return data.getString("url");
|
||||
} else {
|
||||
throw new IOException("Response was not successful: " + url + "\n" + body);
|
||||
}
|
||||
return response.body().string();
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue