diff --git a/CHANGELOG.md b/CHANGELOG.md index be1c2f5c..032d806f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ======================== diff --git a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminModel.java b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminModel.java index 5a4f566d..d47dcca8 100644 --- a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminModel.java +++ b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminModel.java @@ -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()); }