forked from j62/ctbrec
Fix loading of the Streamate model ID
This commit is contained in:
parent
741072b1f0
commit
316d2a7e22
|
@ -24,22 +24,19 @@ import ctbrec.AbstractModel;
|
|||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okio.Buffer;
|
||||
|
||||
public class StreamateModel extends AbstractModel {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamateModel.class);
|
||||
|
||||
private boolean online = false;
|
||||
private List<StreamSource> streamSources = new ArrayList<>();
|
||||
private transient List<StreamSource> streamSources = new ArrayList<>();
|
||||
private int[] resolution;
|
||||
private Long id;
|
||||
private String streamId;
|
||||
|
||||
@Override
|
||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||
|
@ -133,116 +130,19 @@ public class StreamateModel extends AbstractModel {
|
|||
resolution = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveTip(Double tokens) throws IOException {
|
||||
/*
|
||||
Mt._giveGoldAjax = function(e, t) {
|
||||
var n = _t.getState(),
|
||||
a = n.nickname,
|
||||
o = n.id,
|
||||
i = Ds.getState(),
|
||||
r = i.userStreamId,
|
||||
s = i.sakey,
|
||||
l = i.userId,
|
||||
c = i.nickname,
|
||||
u = "";
|
||||
switch (Ot.getState().streamType) {
|
||||
case z.STREAM_TYPE_PRIVATE:
|
||||
case z.STREAM_TYPE_BLOCK:
|
||||
u = "premium";
|
||||
break;
|
||||
case z.STREAM_TYPE_EXCLUSIVE:
|
||||
case z.STREAM_TYPE_BLOCK_EXCLUSIVE:
|
||||
u = "exclusive"
|
||||
}
|
||||
if (!l) return ae.a.reject("no userId!");
|
||||
var d = {
|
||||
amt: e,
|
||||
isprepopulated: t,
|
||||
modelname: a,
|
||||
nickname: c,
|
||||
performernickname: a,
|
||||
sakey: s,
|
||||
session: u,
|
||||
smid: o,
|
||||
streamid: r,
|
||||
userid: l,
|
||||
username: c
|
||||
},
|
||||
p = de.a.getBaseUrl() + "/api/v1/givegold/";
|
||||
return de.a.postPromise(p, d, "json")
|
||||
},
|
||||
*/
|
||||
|
||||
StreamateHttpClient client = (StreamateHttpClient) getSite().getHttpClient();
|
||||
client.login();
|
||||
String saKey = client.getSaKey();
|
||||
Long userId = client.getUserId();
|
||||
String nickname = client.getUserNickname();
|
||||
|
||||
String url = "https://hybridclient.naiadsystems.com/api/v1/givegold/"; // this returns 404 at the moment. not sure if it's the wrong server, or if this is not used anymore
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("amt", Integer.toString(tokens.intValue())) // amount
|
||||
.add("isprepopulated", "1") // ?
|
||||
.add("modelname", getName()) // model's name
|
||||
.add("nickname", nickname) // user's nickname
|
||||
.add("performernickname", getName()) // model's name
|
||||
.add("sakey", saKey) // sakey from login
|
||||
.add("session", "") // is related to gold an private shows, for normal tips keep it empty
|
||||
.add("smid", Long.toString(getId())) // model id
|
||||
.add("streamid", getStreamId()) // id of the current stream
|
||||
.add("userid", Long.toString(userId)) // user's id
|
||||
.add("username", nickname) // user's nickname
|
||||
.build();
|
||||
Buffer b = new Buffer();
|
||||
body.writeTo(b);
|
||||
LOG.debug("tip params {}", b.readUtf8());
|
||||
Request request = new Request.Builder()
|
||||
void loadModelId() throws IOException {
|
||||
String url = "https://www.streamate.com/api/performer/lookup?nicknames=" + getName();
|
||||
StreamateHttpClient httpClient = (StreamateHttpClient) getSite().getHttpClient();
|
||||
Request request = httpClient.newRequestBuilder()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, Streamate.BASE_URL + '/' + getName())
|
||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.post(body)
|
||||
.build();
|
||||
try(Response response = site.getHttpClient().execute(request)) {
|
||||
if(response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
LOG.debug(json.toString(2));
|
||||
if(!json.optString("status").equals("success")) {
|
||||
LOG.error("Sending tip failed {}", json.toString(2));
|
||||
throw new IOException("Sending tip failed");
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, Streamate.BASE_URL + '/' + getName())
|
||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
try(Response response = site.getHttpClient().execute(request)) {
|
||||
if(response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
JSONObject stream = json.getJSONObject("stream");
|
||||
streamId = stream.getString("streamId");
|
||||
JSONObject performer = json.getJSONObject("performer");
|
||||
id = performer.getLong("id");
|
||||
try (Response response = site.getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
String body = response.body().string();
|
||||
LOG.info(body);
|
||||
JSONObject json = new JSONObject(body);
|
||||
JSONObject performer = json.getJSONObject("result");
|
||||
id = performer.getLong(getName());
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
|
@ -263,7 +163,10 @@ public class StreamateModel extends AbstractModel {
|
|||
Collections.sort(streamSources);
|
||||
StreamSource best = streamSources.get(streamSources.size()-1);
|
||||
resolution = new int[] {best.width, best.height};
|
||||
} catch (ExecutionException | IOException | ParseException | PlaylistException | InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException | IOException | ParseException | PlaylistException e) {
|
||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||
}
|
||||
return resolution;
|
||||
|
@ -326,6 +229,7 @@ public class StreamateModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
|
||||
reader.nextName();
|
||||
id = reader.nextLong();
|
||||
}
|
||||
|
@ -334,11 +238,17 @@ public class StreamateModel extends AbstractModel {
|
|||
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
||||
if(id == null) {
|
||||
try {
|
||||
loadModelInfo();
|
||||
loadModelId();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't load model ID for {}. This can cause problems with saving / loading the model", getName());
|
||||
}
|
||||
}
|
||||
writer.name("id").value(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveTip(Double tokens) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue