From 7ffa41944cafc2dbe6eca443d6bf353be60b6306 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Thu, 4 Apr 2019 18:07:19 +0200 Subject: [PATCH] Fix online check for BongaCams The online check now consists of three steps: 1. check, if the model's state is online on its profile page. 2. check, if the room status is public with getRoomData 3. check, if the stream playlist is available --- .../ctbrec/sites/bonga/BongaCamsModel.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java b/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java index 0b9e05f6..f400d49e 100644 --- a/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java +++ b/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java @@ -9,12 +9,12 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; -import org.json.JSONException; import org.json.JSONObject; import org.jsoup.nodes.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Objects; import com.iheartradio.m3u8.Encoding; import com.iheartradio.m3u8.Format; import com.iheartradio.m3u8.ParseException; @@ -45,36 +45,36 @@ public class BongaCamsModel extends AbstractModel { private List streamSources = new ArrayList<>(); private int[] resolution; - // @Override - // public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { - // if(ignoreCache) { - // String url = BongaCams.baseUrl + "/profile/" + getName(); - // Request req = new Request.Builder().url(url).build(); - // try(Response resp = site.getHttpClient().execute(req)) { - // String body = resp.body().string(); - // online = !body.contains("class=\"badge_online __hidden\""); - // } - // } - // return online; - // } - @Override public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { - if(ignoreCache) { - try { - String url = getStreamUrl(); - Request req = new Request.Builder().url(url).build(); - try(Response resp = site.getHttpClient().execute(req)) { - online = resp.isSuccessful(); + if (ignoreCache) { + String url = BongaCams.baseUrl + "/profile/" + getName(); + Request req = new Request.Builder() + .url(url) + .header("User-Agent", Config.getInstance().getSettings().httpUserAgentMobile) + .build(); + try (Response resp = site.getHttpClient().execute(req)) { + String body = resp.body().string(); + Element span = HtmlParser.getTag(body, "div.online_status_block span"); + String status = span.attr("class"); + if(Objects.equal(status, "online")) { + JSONObject roomData = getRoomData(); + String showType = roomData.getJSONObject("performerData").optString("showType"); + online = Objects.equal(showType, "public") && isStreamAvailable(); } - } catch (JSONException e) { - LOG.info("Video Server URL not available for {}. Assuming she's offline", getDisplayName()); - online = false; } } return online; } + private boolean isStreamAvailable() throws IOException, ExecutionException, InterruptedException { + String url = getStreamUrl(); + Request req = new Request.Builder().url(url).build(); + try(Response resp = site.getHttpClient().execute(req)) { + return resp.isSuccessful(); + } + } + private JSONObject getRoomData() throws IOException { String url = BongaCams.baseUrl + "/tools/amf.php"; RequestBody body = new FormBody.Builder()