Add stream source "Origin"
This commit is contained in:
parent
a4d517aa25
commit
3c86310edf
|
@ -0,0 +1,13 @@
|
|||
package ctbrec;
|
||||
|
||||
public class NotImplementedExcetion extends RuntimeException {
|
||||
|
||||
public NotImplementedExcetion() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NotImplementedExcetion(String mesg) {
|
||||
super(mesg);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package ctbrec.recorder.download;
|
|||
import java.text.DecimalFormat;
|
||||
|
||||
public class StreamSource implements Comparable<StreamSource> {
|
||||
public static final int ORIGIN = Integer.MAX_VALUE - 1;
|
||||
public int bandwidth;
|
||||
public int width;
|
||||
public int height;
|
||||
|
@ -44,8 +45,10 @@ public class StreamSource implements Comparable<StreamSource> {
|
|||
public String toString() {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
float mbit = bandwidth / 1024.0f / 1024.0f;
|
||||
if(height == Integer.MAX_VALUE) {
|
||||
if (height == Integer.MAX_VALUE) {
|
||||
return "unknown resolution (" + df.format(mbit) + " Mbit/s)";
|
||||
} else if (height == ORIGIN) {
|
||||
return "Origin";
|
||||
} else {
|
||||
return height + "p (" + df.format(mbit) + " Mbit/s)";
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.squareup.moshi.JsonWriter;
|
|||
|
||||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.NotImplementedExcetion;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import okhttp3.MediaType;
|
||||
|
@ -31,6 +32,8 @@ import okhttp3.Response;
|
|||
|
||||
public class StreamateModel extends AbstractModel {
|
||||
|
||||
private static final String ORIGIN = "origin";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamateModel.class);
|
||||
|
||||
private boolean online = false;
|
||||
|
@ -40,7 +43,7 @@ public class StreamateModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||
if(ignoreCache) {
|
||||
if (ignoreCache) {
|
||||
String url = "https://sea1c-ls.naiadsystems.com/sea1c-edge-ls/80/live/s:" + getName() + ".json";
|
||||
Request req = new Request.Builder().url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
|
@ -49,7 +52,7 @@ public class StreamateModel extends AbstractModel {
|
|||
.addHeader(REFERER, Streamate.BASE_URL + '/' + getName())
|
||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
try(Response response = site.getHttpClient().execute(req)) {
|
||||
try (Response response = site.getHttpClient().execute(req)) {
|
||||
online = response.isSuccessful();
|
||||
}
|
||||
}
|
||||
|
@ -87,8 +90,8 @@ public class StreamateModel extends AbstractModel {
|
|||
.addHeader(REFERER, Streamate.BASE_URL + '/' + getName())
|
||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
try(Response response = site.getHttpClient().execute(req)) {
|
||||
if(response.isSuccessful()) {
|
||||
try (Response response = site.getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
JSONObject formats = json.getJSONObject("formats");
|
||||
JSONObject hls = formats.getJSONObject("mp4-hls");
|
||||
|
@ -107,17 +110,18 @@ public class StreamateModel extends AbstractModel {
|
|||
}
|
||||
|
||||
// add raw source stream
|
||||
if(formats.has("mp4-ws")) {
|
||||
JSONObject ws = formats.getJSONObject("mp4-ws");
|
||||
JSONObject origin = hls.getJSONObject("origin");
|
||||
if (hls.has(ORIGIN)) {
|
||||
JSONObject origin = hls.getJSONObject(ORIGIN);
|
||||
StreamSource src = new StreamSource();
|
||||
src.mediaPlaylistUrl = origin.getString("location");
|
||||
origin = ws.getJSONObject("origin"); // switch to web socket origin, because it has width, height and bitrates
|
||||
origin = hls.getJSONObject(ORIGIN);
|
||||
src.width = origin.optInt("videoWidth");
|
||||
src.height = origin.optInt("videoHeight");
|
||||
src.bandwidth = (origin.optInt("videoKbps") + origin.optInt("audioKbps")) * 1024;
|
||||
src.height = StreamSource.ORIGIN;
|
||||
streamSources.add(src);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
|
@ -159,10 +163,13 @@ public class StreamateModel extends AbstractModel {
|
|||
if(!isOnline()) {
|
||||
return new int[2];
|
||||
}
|
||||
List<StreamSource> streamSources = getStreamSources();
|
||||
Collections.sort(streamSources);
|
||||
StreamSource best = streamSources.get(streamSources.size()-1);
|
||||
resolution = new int[] {best.width, best.height};
|
||||
List<StreamSource> sources = getStreamSources();
|
||||
Collections.sort(sources);
|
||||
StreamSource best = sources.get(sources.size() - 1);
|
||||
if (best.height == StreamSource.ORIGIN) {
|
||||
best = sources.get(sources.size() - 2);
|
||||
}
|
||||
resolution = new int[] { best.width, best.height };
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||
Thread.currentThread().interrupt();
|
||||
|
@ -208,7 +215,7 @@ public class StreamateModel extends AbstractModel {
|
|||
.addHeader(REFERER, getSite().getBaseUrl())
|
||||
.post(body)
|
||||
.build();
|
||||
try(Response response = getSite().getHttpClient().execute(request)) {
|
||||
try (Response response = getSite().getHttpClient().execute(request)) {
|
||||
String content = response.body().string();
|
||||
if (response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(content);
|
||||
|
@ -229,14 +236,13 @@ public class StreamateModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
|
||||
reader.nextName();
|
||||
id = reader.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
try {
|
||||
loadModelId();
|
||||
} catch (IOException e) {
|
||||
|
@ -248,7 +254,6 @@ public class StreamateModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void receiveTip(Double tokens) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new NotImplementedExcetion("Tipping is not implemented for Streamate");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue