Add stream source "Origin"

This commit is contained in:
0xboobface 2020-04-23 19:28:12 +02:00
parent a4d517aa25
commit 3c86310edf
3 changed files with 39 additions and 18 deletions

View File

@ -0,0 +1,13 @@
package ctbrec;
public class NotImplementedExcetion extends RuntimeException {
public NotImplementedExcetion() {
super();
}
public NotImplementedExcetion(String mesg) {
super(mesg);
}
}

View File

@ -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;
@ -46,6 +47,8 @@ public class StreamSource implements Comparable<StreamSource> {
float mbit = bandwidth / 1024.0f / 1024.0f;
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)";
}

View File

@ -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;
@ -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,9 +163,12 @@ 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);
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());
@ -229,7 +236,6 @@ public class StreamateModel extends AbstractModel {
@Override
public void readSiteSpecificData(JsonReader reader) throws IOException {
reader.nextName();
id = reader.nextLong();
}
@ -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");
}
}