forked from j62/ctbrec
1
0
Fork 0

Fix BongaCams online check

Fix Bongacams unfollow
This commit is contained in:
0xb00bface 2020-10-03 16:14:24 +02:00
parent 3b3854c488
commit 1350dce14f
3 changed files with 37 additions and 43 deletions

View File

@ -1,6 +1,5 @@
package ctbrec.ui.sites.bonga;
import static ctbrec.Model.State.*;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
@ -54,45 +53,23 @@ public class BongaCamsUpdateService extends PaginatedScheduledService {
String content = response.body().string();
List<Model> models = new ArrayList<>();
JSONObject json = new JSONObject(content);
if(json.optString("status").equals("success")) {
//LOG.debug(json.toString(2));
if (json.optString("status").equals("success")) {
JSONArray jsonModels = json.getJSONArray("models");
for (int i = 0; i < jsonModels.length(); i++) {
JSONObject m = jsonModels.getJSONObject(i);
String name = m.optString("username");
if(name.isEmpty()) {
if (name.isEmpty()) {
continue;
}
BongaCamsModel model = (BongaCamsModel) bongaCams.createModel(name);
boolean away = m.optBoolean("is_away");
boolean online = m.optBoolean("online");
model.setOnline(online);
if(online) {
model.setOnlineState(ONLINE);
if(away) {
model.setOnlineState(AWAY);
} else {
switch(m.optString("room")) {
case "private":
case "fullprivate":
model.setOnlineState(PRIVATE);
break;
case "group":
case "public":
model.setOnlineState(ONLINE);
break;
default:
LOG.debug(m.optString("room"));
model.setOnlineState(ONLINE);
}
}
} else {
model.setOnlineState(OFFLINE);
}
model.mapOnlineState(m.optString("room"));
model.setOnline(m.optInt("viewers") > 0);
model.setPreview("https:" + m.getString("thumb_image"));
if(m.has("display_name")) {
if (m.has("display_name")) {
model.setDisplayName(m.getString("display_name"));
}
model.setDescription(m.optString("topic"));
models.add(model);
}
}

View File

@ -285,8 +285,6 @@ public class ThumbCell extends StackPane {
try {
resolution = resolutionCache.get(model);
resolutionBackgroundColor = resolutionOnlineColor;
LOG.trace("Model resolution {} {}x{}", model.getName(), resolution[0], resolution[1]);
LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size());
final int w = resolution[1];
String width = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD";
tagText = width;
@ -297,6 +295,10 @@ public class ThumbCell extends StackPane {
resolutionCache.invalidate(model);
} else {
resolutionBackgroundColor = resolutionOfflineColor;
if (state == ONLINE) {
// state can't be ONLINE while the model is offline
tagText = OFFLINE.name();
}
}
} else {
State state = model.getOnlineState(true);

View File

@ -32,7 +32,6 @@ import com.iheartradio.m3u8.data.StreamInfo;
import ctbrec.AbstractModel;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.io.HtmlParser;
import ctbrec.io.HttpException;
import ctbrec.recorder.download.StreamSource;
@ -57,6 +56,7 @@ public class BongaCamsModel extends AbstractModel {
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
if (ignoreCache) {
JSONObject roomData = getRoomData();
//LOG.debug(roomData.toString(2));
if (!roomData.has("performerData")) {
return false;
}
@ -64,7 +64,7 @@ public class BongaCamsModel extends AbstractModel {
setDisplayName(performerData.optString("displayName"));
String url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=&online_only=true&offset=0&model_search%5Bdisplay_name%5D%5Btext%5D="
+ URLEncoder.encode(getDisplayName(), StandardCharsets.UTF_8.name()) + "&_online_filter=0";
LOG.trace("Online Check: {}", url);
//LOG.debug("Online Check: {}", url);
Request req = new Request.Builder()
.url(url)
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgentMobile)
@ -75,22 +75,18 @@ public class BongaCamsModel extends AbstractModel {
.build();
try (Response resp = site.getHttpClient().execute(req)) {
String body = resp.body().string();
LOG.trace(body);
JSONObject json = new JSONObject(body);
if (json.optString(STATUS).equals(SUCCESS)) {
JSONArray models = json.getJSONArray("models");
for (int i = 0; i < models.length(); i++) {
JSONObject model = models.getJSONObject(i);
//LOG.debug(model.toString(2));
setDescription(model.optString("topic"));
String username = model.optString("username");
if (username.equalsIgnoreCase(getName())) {
boolean away = model.optBoolean("is_away");
String room = model.optString("room");
online = !away
&& model.optBoolean("online")
&& room.equalsIgnoreCase("public")
&& isStreamAvailable();
onlineState = Model.State.ONLINE;
mapOnlineState(room);
online = online && isStreamAvailable();
break;
}
}
@ -197,7 +193,7 @@ public class BongaCamsModel extends AbstractModel {
private String getStreamUrl() throws IOException {
JSONObject roomData = getRoomData();
if(roomData.optString(STATUS).equals(SUCCESS)) {
if (roomData.optString(STATUS).equals(SUCCESS)) {
JSONObject localData = roomData.getJSONObject("localData");
String server = localData.getString("videoServerUrl");
return "https:" + server + "/hls/stream_" + getName() + "/playlist.m3u8";
@ -261,8 +257,10 @@ public class BongaCamsModel extends AbstractModel {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
resolution = new int[2];
} catch (ExecutionException | IOException | ParseException | PlaylistException e) {
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
resolution = new int[2];
}
return resolution;
} else {
@ -335,7 +333,7 @@ public class BongaCamsModel extends AbstractModel {
throw new IOException("Not logged in");
}
String url = getSite().getBaseUrl() + "/unfollow/" + getName() + '/' + getUserId();
String url = getSite().getBaseUrl() + "/unfollow/" + getName();
LOG.debug("Calling {}", url);
RequestBody body = new FormBody.Builder()
.add("_csrf_token", getCsrfToken())
@ -377,4 +375,21 @@ public class BongaCamsModel extends AbstractModel {
public void setUserId(int userId) {
this.userId = userId;
}
public void mapOnlineState(String roomState) {
switch (roomState) {
case "private":
case "fullprivate":
setOnlineState(PRIVATE);
break;
case "group":
case "public":
setOnlineState(ONLINE);
setOnline(true);
break;
default:
LOG.debug(roomState);
setOnlineState(OFFLINE);
}
}
}