forked from j62/ctbrec
1
0
Fork 0

Add tipping for Streamate

Tipping does not work, yet. The server returns success: false. I don't
know, what the parameters have to look like
This commit is contained in:
0xboobface 2018-12-14 23:37:55 +01:00
parent b83235a32f
commit 1ce9a111a9
3 changed files with 124 additions and 32 deletions

View File

@ -47,8 +47,7 @@ public class StreamateFollowedService extends PaginatedScheduledService {
public List<Model> call() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { public List<Model> call() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
httpClient.login(); httpClient.login();
String saKey = httpClient.getSaKey(); String saKey = httpClient.getSaKey();
Long userId = httpClient.getUserId(); String _url = url + "&page_number=" + page + "&results_per_page=" + MODELS_PER_PAGE + "&sakey=" + saKey;
String _url = url + "&page_number=" + page + "&results_per_page=" + MODELS_PER_PAGE + "&sakey=" + saKey + "&userid=" + userId;
LOG.debug("Fetching page {}", _url); LOG.debug("Fetching page {}", _url);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(_url) .url(_url)

View File

@ -23,6 +23,7 @@ public class StreamateHttpClient extends HttpClient {
private Long userId; private Long userId;
private String saKey = ""; private String saKey = "";
private String userNickname = "";
public StreamateHttpClient() { public StreamateHttpClient() {
super("streamate"); super("streamate");
@ -57,6 +58,11 @@ public class StreamateHttpClient extends HttpClient {
return true; return true;
} }
loggedIn = loginWithoutCookies();
return loggedIn;
}
private synchronized boolean loginWithoutCookies() throws IOException {
JSONObject loginRequest = new JSONObject(); JSONObject loginRequest = new JSONObject();
loginRequest.put("email", Config.getInstance().getSettings().streamateUsername); loginRequest.put("email", Config.getInstance().getSettings().streamateUsername);
loginRequest.put("password", Config.getInstance().getSettings().streamatePassword); loginRequest.put("password", Config.getInstance().getSettings().streamatePassword);
@ -76,10 +82,12 @@ public class StreamateHttpClient extends HttpClient {
String content = response.body().string(); String content = response.body().string();
if(response.isSuccessful()) { if(response.isSuccessful()) {
JSONObject json = new JSONObject(content); JSONObject json = new JSONObject(content);
LOG.debug(json.toString(2));
loggedIn = json.has("sakey"); loggedIn = json.has("sakey");
saKey = json.optString("sakey"); saKey = json.optString("sakey");
JSONObject account = json.getJSONObject("account"); JSONObject account = json.getJSONObject("account");
userId = account.getLong("userid"); userId = account.getLong("userid");
userNickname = account.getString("nickname");
} else { } else {
throw new IOException("Login failed: " + response.code() + " " + response.message()); throw new IOException("Login failed: " + response.code() + " " + response.message());
} }
@ -123,7 +131,14 @@ public class StreamateHttpClient extends HttpClient {
return saKey; return saKey;
} }
public Long getUserId() { public Long getUserId() throws IOException {
if(userId == null) {
loginWithoutCookies();
}
return userId; return userId;
} }
public String getUserNickname() {
return userNickname;
}
} }

View File

@ -22,10 +22,12 @@ import ctbrec.AbstractModel;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.recorder.download.StreamSource; import ctbrec.recorder.download.StreamSource;
import okhttp3.FormBody;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import okio.Buffer;
public class StreamateModel extends AbstractModel { public class StreamateModel extends AbstractModel {
@ -128,35 +130,111 @@ public class StreamateModel extends AbstractModel {
@Override @Override
public void receiveTip(int tokens) throws IOException { public void receiveTip(int tokens) throws IOException {
// String url = Streamate.BASE_URL + "/chat-ajax-amf-service?" + System.currentTimeMillis(); /*
// int userId = ((StreamateHttpClient)site.getHttpClient()).getUserId(); Mt._giveGoldAjax = function(e, t) {
// RequestBody body = new FormBody.Builder() var n = _t.getState(),
// .add("method", "tipModel") a = n.nickname,
// .add("args[]", getName()) o = n.id,
// .add("args[]", Integer.toString(tokens)) i = Ds.getState(),
// .add("args[]", Integer.toString(userId)) r = i.userStreamId,
// .add("args[3]", "") s = i.sakey,
// .build(); l = i.userId,
// Request request = new Request.Builder() c = i.nickname,
// .url(url) u = "";
// .addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent) switch (Ot.getState().streamType) {
// .addHeader("Accept", "application/json, text/javascript, */*") case z.STREAM_TYPE_PRIVATE:
// .addHeader("Accept-Language", "en") case z.STREAM_TYPE_BLOCK:
// .addHeader("Referer", Streamate.BASE_URL + '/' + getName()) u = "premium";
// .addHeader("X-Requested-With", "XMLHttpRequest") break;
// .post(body) case z.STREAM_TYPE_EXCLUSIVE:
// .build(); case z.STREAM_TYPE_BLOCK_EXCLUSIVE:
// try(Response response = site.getHttpClient().execute(request)) { u = "exclusive"
// if(response.isSuccessful()) { }
// JSONObject json = new JSONObject(response.body().string()); if (!l) return ae.a.reject("no userId!");
// if(!json.optString("status").equals("success")) { var d = {
// LOG.error("Sending tip failed {}", json.toString(2)); amt: e,
// throw new IOException("Sending tip failed"); isprepopulated: t,
// } modelname: a,
// } else { nickname: c,
// throw new IOException(response.code() + ' ' + response.message()); 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)) // 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()
.url(url)
.addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent)
.addHeader("Accept", "application/json, text/javascript, */*")
.addHeader("Accept-Language", "en")
.addHeader("Referer", Streamate.BASE_URL + '/' + getName())
.addHeader("X-Requested-With", "XMLHttpRequest")
.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 {
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", "application/json, text/javascript, */*")
.addHeader("Accept-Language", "en")
.addHeader("Referer", Streamate.BASE_URL + '/' + getName())
.addHeader("X-Requested-With", "XMLHttpRequest")
.build();
try(Response response = site.getHttpClient().execute(request)) {
if(response.isSuccessful()) {
JSONObject json = new JSONObject(response.body().string());
JSONObject stream = json.getJSONObject("stream");
return stream.getString("streamId");
} else {
throw new HttpException(response.code(), response.message());
}
}
} }
@Override @Override