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 {
httpClient.login();
String saKey = httpClient.getSaKey();
Long userId = httpClient.getUserId();
String _url = url + "&page_number=" + page + "&results_per_page=" + MODELS_PER_PAGE + "&sakey=" + saKey + "&userid=" + userId;
String _url = url + "&page_number=" + page + "&results_per_page=" + MODELS_PER_PAGE + "&sakey=" + saKey;
LOG.debug("Fetching page {}", _url);
Request request = new Request.Builder()
.url(_url)

View File

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

View File

@ -22,10 +22,12 @@ 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 {
@ -128,35 +130,111 @@ public class StreamateModel extends AbstractModel {
@Override
public void receiveTip(int tokens) throws IOException {
// String url = Streamate.BASE_URL + "/chat-ajax-amf-service?" + System.currentTimeMillis();
// int userId = ((StreamateHttpClient)site.getHttpClient()).getUserId();
// RequestBody body = new FormBody.Builder()
// .add("method", "tipModel")
// .add("args[]", getName())
// .add("args[]", Integer.toString(tokens))
// .add("args[]", Integer.toString(userId))
// .add("args[3]", "")
// .build();
// 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());
// if(!json.optString("status").equals("success")) {
// LOG.error("Sending tip failed {}", json.toString(2));
// throw new IOException("Sending tip failed");
// }
// } else {
// throw new IOException(response.code() + ' ' + response.message());
// }
// }
/*
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)) // 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