diff --git a/common/src/main/java/ctbrec/sites/manyvids/MVLiveClient.java b/common/src/main/java/ctbrec/sites/manyvids/MVLiveClient.java index 02b44195..8b6b9f22 100644 --- a/common/src/main/java/ctbrec/sites/manyvids/MVLiveClient.java +++ b/common/src/main/java/ctbrec/sites/manyvids/MVLiveClient.java @@ -169,7 +169,7 @@ public class MVLiveClient { public void onMessage(WebSocket webSocket, String text) { super.onMessage(webSocket, text); //msgBuffer.append(text); - LOG.debug("Message: {}", text); + LOG.trace("Message: {}", text); text = Optional.ofNullable(text).orElse(""); if (Objects.equal("o", text)) { sendMessages(new Ping()); diff --git a/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java b/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java index 3adebaf2..2eb72385 100644 --- a/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java +++ b/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java @@ -9,8 +9,10 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.concurrent.ExecutionException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,8 +44,8 @@ public class MVLiveModel extends AbstractModel { @Override public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { - // TODO return getOnlineState(true) == Model.State.ONLINE; - return true; + JSONObject json = getRoomLocation(); + return json.optBoolean("success"); } @Override @@ -102,7 +104,7 @@ public class MVLiveModel extends AbstractModel { public void updateCloudFlareCookies() throws IOException, InterruptedException { 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() .url(url) .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) @@ -111,20 +113,40 @@ public class MVLiveModel extends AbstractModel { if (!response.isSuccessful()) { throw new HttpException(response.code(), response.message()); } - // else { - // LOG.debug("headers: {}", response.headers()); - // } } } public String getRoomNumber() throws IOException, InterruptedException { if (roomNumber == null) { - StreamLocation streamLocation = getClient().getStreamLocation(this); - roomNumber = streamLocation.roomNumber; + JSONObject json = getRoomLocation(); + if (json.optBoolean("success")) { + roomNumber = json.getString("floorId"); + } else { + throw new RuntimeException(getName() + " is offline"); + } } 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() { if (client == null) { MVLive site = (MVLive) getSite();