forked from j62/ctbrec
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
This commit is contained in:
parent
f5a302337f
commit
7ffa41944c
|
@ -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<StreamSource> 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()
|
||||
|
|
Loading…
Reference in New Issue