forked from j62/ctbrec
1
0
Fork 0

Make sure, that the model ID is set

When a Streamate model is added by URL, make sure, that the ID is
loaded, so that saving and loading works properly, since the ID is saved
as site specific data.
This commit is contained in:
0xboobface 2018-12-17 17:13:15 +01:00
parent e362980028
commit 9958e04ef8
2 changed files with 16 additions and 2 deletions

View File

@ -193,7 +193,13 @@ public class Streamate extends AbstractSite {
Matcher m = Pattern.compile("https?://.*?streamate.com/cam/([^/]*?)/?").matcher(url);
if (m.matches()) {
String modelName = m.group(1);
return createModel(modelName);
StreamateModel model = (StreamateModel) createModel(modelName);
try {
model.loadModelInfo();
} catch (IOException e) {
LOG.error("Couldn't load model info. This can cause problems with saving / loading the model");
}
return model;
} else {
return super.createModelFromUrl(url);
}

View File

@ -37,6 +37,7 @@ public class StreamateModel extends AbstractModel {
private List<StreamSource> streamSources = new ArrayList<>();
private int[] resolution;
private Long id;
private String streamId;
@Override
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
@ -218,6 +219,11 @@ public class StreamateModel extends AbstractModel {
}
private String getStreamId() throws IOException {
loadModelInfo();
return streamId;
}
void loadModelInfo() throws IOException {
String url = "https://hybridclient.naiadsystems.com/api/v1/config/?name=" + getName()
+ "&sabasic=&sakey=&sk=www.streamate.com&userid=0&version=6.3.17&ajax=1";
Request request = new Request.Builder()
@ -232,7 +238,9 @@ public class StreamateModel extends AbstractModel {
if(response.isSuccessful()) {
JSONObject json = new JSONObject(response.body().string());
JSONObject stream = json.getJSONObject("stream");
return stream.getString("streamId");
streamId = stream.getString("streamId");
JSONObject performer = json.getJSONObject("performer");
id = performer.getLong("id");
} else {
throw new HttpException(response.code(), response.message());
}