forked from j62/ctbrec
1
0
Fork 0

Create specialized HLS downloads for server and client

This commit is contained in:
0xboobface 2019-01-18 16:32:47 +01:00
parent df47f4ba91
commit 86f086eb20
1 changed files with 21 additions and 27 deletions

View File

@ -41,7 +41,7 @@ public class LiveJasminModel extends AbstractModel {
@Override
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
if(ignoreCache) {
if (ignoreCache) {
loadModelInfo();
}
return online;
@ -49,29 +49,29 @@ public class LiveJasminModel extends AbstractModel {
protected void loadModelInfo() throws IOException {
String url = "https://m.livejasmin.com/en/chat-html5/" + getName();
Request req = new Request.Builder().url(url)
.header("User-Agent", "Mozilla/5.0 (iPhone; CPU OS 10_14 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Mobile/14E304 Safari/605.1.15")
Request req = new Request.Builder().url(url).header("User-Agent",
"Mozilla/5.0 (iPhone; CPU OS 10_14 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Mobile/14E304 Safari/605.1.15")
.header("Accept", "application/json,*/*")
.header("Accept-Language", "en")
.header("Referer", getSite().getBaseUrl())
.header("X-Requested-With", "XMLHttpRequest")
.build();
try(Response response = getSite().getHttpClient().execute(req)) {
if(response.isSuccessful()) {
try (Response response = getSite().getHttpClient().execute(req)) {
if (response.isSuccessful()) {
String body = response.body().string();
JSONObject json = new JSONObject(body);
//LOG.debug(json.toString(2));
if(json.optBoolean("success")) {
// LOG.debug(json.toString(2));
if (json.optBoolean("success")) {
JSONObject data = json.getJSONObject("data");
JSONObject config = data.getJSONObject("config");
JSONObject chatRoom = config.getJSONObject("chatRoom");
setId(chatRoom.getString("p_id"));
if(chatRoom.has("profile_picture_url")) {
if (chatRoom.has("profile_picture_url")) {
setPreview(chatRoom.getString("profile_picture_url"));
}
int status = chatRoom.optInt("status", -1);
onlineState = mapStatus(status);
if(chatRoom.optInt("is_on_private", 0) == 1) {
if (chatRoom.optInt("is_on_private", 0) == 1) {
onlineState = State.PRIVATE;
}
resolution = new int[2];
@ -89,7 +89,7 @@ public class LiveJasminModel extends AbstractModel {
}
public static State mapStatus(int status) {
switch(status) {
switch (status) {
case 0:
return State.OFFLINE;
case 1:
@ -115,8 +115,8 @@ public class LiveJasminModel extends AbstractModel {
LOG.debug("Master playlist: {}", masterUrl);
List<StreamSource> streamSources = new ArrayList<>();
Request req = new Request.Builder().url(masterUrl).build();
try(Response response = site.getHttpClient().execute(req)) {
if(response.isSuccessful()) {
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
InputStream inputStream = response.body().byteStream();
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist playlist = parser.parse();
@ -161,7 +161,7 @@ public class LiveJasminModel extends AbstractModel {
if (response.isSuccessful()) {
String body = response.body().string();
JSONObject json = new JSONObject(body);
if(json.optBoolean("success")) {
if (json.optBoolean("success")) {
JSONObject data = json.getJSONObject("data");
JSONObject hlsStream = data.getJSONObject("hls_stream");
return hlsStream.getString("url");
@ -188,8 +188,8 @@ public class LiveJasminModel extends AbstractModel {
@Override
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
if(resolution == null) {
if(failFast) {
if (resolution == null) {
if (failFast) {
return new int[2];
}
try {
@ -260,7 +260,7 @@ public class LiveJasminModel extends AbstractModel {
@Override
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
if(id == null) {
if (id == null) {
try {
loadModelInfo();
} catch (IOException e) {
@ -276,16 +276,10 @@ public class LiveJasminModel extends AbstractModel {
@Override
public Download createDownload() {
// if(Config.getInstance().getSettings().livejasminSession.isEmpty()) {
// if(Config.isServerMode()) {
// return new HlsDownload(getSite().getHttpClient());
// } else {
// return new LiveJasminMergedHlsDownload(getSite().getHttpClient());
// }
// } else {
// return new LiveJasminWebSocketDownload(getSite().getHttpClient());
// }
//return new LiveJasminChunkedHttpDownload(getSite().getHttpClient());
return new LiveJasminWebSocketDownload(getSite().getHttpClient());
if(Config.isServerMode()) {
return new LiveJasminHlsDownload(getSite().getHttpClient());
} else {
return new LiveJasminMergedHlsDownload(getSite().getHttpClient());
}
}
}