Change the request to get the room number
This commit is contained in:
parent
d0f1834bda
commit
e06bfaf88b
|
@ -169,7 +169,7 @@ public class MVLiveClient {
|
||||||
public void onMessage(WebSocket webSocket, String text) {
|
public void onMessage(WebSocket webSocket, String text) {
|
||||||
super.onMessage(webSocket, text);
|
super.onMessage(webSocket, text);
|
||||||
//msgBuffer.append(text);
|
//msgBuffer.append(text);
|
||||||
LOG.debug("Message: {}", text);
|
LOG.trace("Message: {}", text);
|
||||||
text = Optional.ofNullable(text).orElse("");
|
text = Optional.ofNullable(text).orElse("");
|
||||||
if (Objects.equal("o", text)) {
|
if (Objects.equal("o", text)) {
|
||||||
sendMessages(new Ping());
|
sendMessages(new Ping());
|
||||||
|
|
|
@ -9,8 +9,10 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -42,8 +44,8 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
// TODO return getOnlineState(true) == Model.State.ONLINE;
|
JSONObject json = getRoomLocation();
|
||||||
return true;
|
return json.optBoolean("success");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +104,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
public void updateCloudFlareCookies() throws IOException, InterruptedException {
|
public void updateCloudFlareCookies() throws IOException, InterruptedException {
|
||||||
String url = MVLive.WS_ORIGIN + "/api/" + getRoomNumber() + "/player-settings/" + getName();
|
String url = MVLive.WS_ORIGIN + "/api/" + getRoomNumber() + "/player-settings/" + getName();
|
||||||
LOG.debug("Getting CF cookies: {}", url);
|
LOG.trace("Getting CF cookies: {}", url);
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
@ -111,20 +113,40 @@ public class MVLiveModel extends AbstractModel {
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// LOG.debug("headers: {}", response.headers());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoomNumber() throws IOException, InterruptedException {
|
public String getRoomNumber() throws IOException, InterruptedException {
|
||||||
if (roomNumber == null) {
|
if (roomNumber == null) {
|
||||||
StreamLocation streamLocation = getClient().getStreamLocation(this);
|
JSONObject json = getRoomLocation();
|
||||||
roomNumber = streamLocation.roomNumber;
|
if (json.optBoolean("success")) {
|
||||||
|
roomNumber = json.getString("floorId");
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(getName() + " is offline");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return roomNumber;
|
return roomNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JSONObject getRoomLocation() throws IOException {
|
||||||
|
String url = MVLive.WS_ORIGIN + "/api/roomlocation/" + getName() + "?private=false";
|
||||||
|
Request req = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
|
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.header(REFERER, MVLive.WS_ORIGIN + "/stream/" + getName())
|
||||||
|
.build();
|
||||||
|
try (Response response = site.getHttpClient().execute(req)) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
JSONObject json = new JSONObject(response.body().string());
|
||||||
|
return json;
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized MVLiveClient getClient() {
|
private synchronized MVLiveClient getClient() {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
MVLive site = (MVLive) getSite();
|
MVLive site = (MVLive) getSite();
|
||||||
|
|
Loading…
Reference in New Issue