forked from j62/ctbrec
Create specialized HLS downloads for server and client
This commit is contained in:
parent
df47f4ba91
commit
86f086eb20
|
@ -41,7 +41,7 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
if(ignoreCache) {
|
if (ignoreCache) {
|
||||||
loadModelInfo();
|
loadModelInfo();
|
||||||
}
|
}
|
||||||
return online;
|
return online;
|
||||||
|
@ -49,29 +49,29 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
|
|
||||||
protected void loadModelInfo() throws IOException {
|
protected void loadModelInfo() throws IOException {
|
||||||
String url = "https://m.livejasmin.com/en/chat-html5/" + getName();
|
String url = "https://m.livejasmin.com/en/chat-html5/" + getName();
|
||||||
Request req = new Request.Builder().url(url)
|
Request req = new Request.Builder().url(url).header("User-Agent",
|
||||||
.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")
|
"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", "application/json,*/*")
|
||||||
.header("Accept-Language", "en")
|
.header("Accept-Language", "en")
|
||||||
.header("Referer", getSite().getBaseUrl())
|
.header("Referer", getSite().getBaseUrl())
|
||||||
.header("X-Requested-With", "XMLHttpRequest")
|
.header("X-Requested-With", "XMLHttpRequest")
|
||||||
.build();
|
.build();
|
||||||
try(Response response = getSite().getHttpClient().execute(req)) {
|
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||||
if(response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = response.body().string();
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
//LOG.debug(json.toString(2));
|
// LOG.debug(json.toString(2));
|
||||||
if(json.optBoolean("success")) {
|
if (json.optBoolean("success")) {
|
||||||
JSONObject data = json.getJSONObject("data");
|
JSONObject data = json.getJSONObject("data");
|
||||||
JSONObject config = data.getJSONObject("config");
|
JSONObject config = data.getJSONObject("config");
|
||||||
JSONObject chatRoom = config.getJSONObject("chatRoom");
|
JSONObject chatRoom = config.getJSONObject("chatRoom");
|
||||||
setId(chatRoom.getString("p_id"));
|
setId(chatRoom.getString("p_id"));
|
||||||
if(chatRoom.has("profile_picture_url")) {
|
if (chatRoom.has("profile_picture_url")) {
|
||||||
setPreview(chatRoom.getString("profile_picture_url"));
|
setPreview(chatRoom.getString("profile_picture_url"));
|
||||||
}
|
}
|
||||||
int status = chatRoom.optInt("status", -1);
|
int status = chatRoom.optInt("status", -1);
|
||||||
onlineState = mapStatus(status);
|
onlineState = mapStatus(status);
|
||||||
if(chatRoom.optInt("is_on_private", 0) == 1) {
|
if (chatRoom.optInt("is_on_private", 0) == 1) {
|
||||||
onlineState = State.PRIVATE;
|
onlineState = State.PRIVATE;
|
||||||
}
|
}
|
||||||
resolution = new int[2];
|
resolution = new int[2];
|
||||||
|
@ -89,7 +89,7 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static State mapStatus(int status) {
|
public static State mapStatus(int status) {
|
||||||
switch(status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
return State.OFFLINE;
|
return State.OFFLINE;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -115,8 +115,8 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
LOG.debug("Master playlist: {}", masterUrl);
|
LOG.debug("Master playlist: {}", masterUrl);
|
||||||
List<StreamSource> streamSources = new ArrayList<>();
|
List<StreamSource> streamSources = new ArrayList<>();
|
||||||
Request req = new Request.Builder().url(masterUrl).build();
|
Request req = new Request.Builder().url(masterUrl).build();
|
||||||
try(Response response = site.getHttpClient().execute(req)) {
|
try (Response response = site.getHttpClient().execute(req)) {
|
||||||
if(response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
InputStream inputStream = response.body().byteStream();
|
InputStream inputStream = response.body().byteStream();
|
||||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||||
Playlist playlist = parser.parse();
|
Playlist playlist = parser.parse();
|
||||||
|
@ -161,7 +161,7 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = response.body().string();
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
if(json.optBoolean("success")) {
|
if (json.optBoolean("success")) {
|
||||||
JSONObject data = json.getJSONObject("data");
|
JSONObject data = json.getJSONObject("data");
|
||||||
JSONObject hlsStream = data.getJSONObject("hls_stream");
|
JSONObject hlsStream = data.getJSONObject("hls_stream");
|
||||||
return hlsStream.getString("url");
|
return hlsStream.getString("url");
|
||||||
|
@ -188,8 +188,8 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
||||||
if(resolution == null) {
|
if (resolution == null) {
|
||||||
if(failFast) {
|
if (failFast) {
|
||||||
return new int[2];
|
return new int[2];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -260,7 +260,7 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
||||||
if(id == null) {
|
if (id == null) {
|
||||||
try {
|
try {
|
||||||
loadModelInfo();
|
loadModelInfo();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -276,16 +276,10 @@ public class LiveJasminModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Download createDownload() {
|
public Download createDownload() {
|
||||||
// if(Config.getInstance().getSettings().livejasminSession.isEmpty()) {
|
if(Config.isServerMode()) {
|
||||||
// if(Config.isServerMode()) {
|
return new LiveJasminHlsDownload(getSite().getHttpClient());
|
||||||
// return new HlsDownload(getSite().getHttpClient());
|
} else {
|
||||||
// } else {
|
return new LiveJasminMergedHlsDownload(getSite().getHttpClient());
|
||||||
// return new LiveJasminMergedHlsDownload(getSite().getHttpClient());
|
}
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// return new LiveJasminWebSocketDownload(getSite().getHttpClient());
|
|
||||||
// }
|
|
||||||
//return new LiveJasminChunkedHttpDownload(getSite().getHttpClient());
|
|
||||||
return new LiveJasminWebSocketDownload(getSite().getHttpClient());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue