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; package ctbrec.ui.sites.bonga;
import static ctbrec.Model.State.*;
import static ctbrec.io.HttpConstants.*; import static ctbrec.io.HttpConstants.*;
import java.io.IOException; import java.io.IOException;
@ -54,6 +53,7 @@ public class BongaCamsUpdateService extends PaginatedScheduledService {
String content = response.body().string(); String content = response.body().string();
List<Model> models = new ArrayList<>(); List<Model> models = new ArrayList<>();
JSONObject json = new JSONObject(content); JSONObject json = new JSONObject(content);
//LOG.debug(json.toString(2));
if (json.optString("status").equals("success")) { if (json.optString("status").equals("success")) {
JSONArray jsonModels = json.getJSONArray("models"); JSONArray jsonModels = json.getJSONArray("models");
for (int i = 0; i < jsonModels.length(); i++) { for (int i = 0; i < jsonModels.length(); i++) {
@ -63,36 +63,13 @@ public class BongaCamsUpdateService extends PaginatedScheduledService {
continue; continue;
} }
BongaCamsModel model = (BongaCamsModel) bongaCams.createModel(name); BongaCamsModel model = (BongaCamsModel) bongaCams.createModel(name);
boolean away = m.optBoolean("is_away"); model.mapOnlineState(m.optString("room"));
boolean online = m.optBoolean("online"); model.setOnline(m.optInt("viewers") > 0);
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.setPreview("https:" + m.getString("thumb_image")); model.setPreview("https:" + m.getString("thumb_image"));
if (m.has("display_name")) { if (m.has("display_name")) {
model.setDisplayName(m.getString("display_name")); model.setDisplayName(m.getString("display_name"));
} }
model.setDescription(m.optString("topic"));
models.add(model); models.add(model);
} }
} }

View File

@ -285,8 +285,6 @@ public class ThumbCell extends StackPane {
try { try {
resolution = resolutionCache.get(model); resolution = resolutionCache.get(model);
resolutionBackgroundColor = resolutionOnlineColor; 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]; final int w = resolution[1];
String width = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD"; String width = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD";
tagText = width; tagText = width;
@ -297,6 +295,10 @@ public class ThumbCell extends StackPane {
resolutionCache.invalidate(model); resolutionCache.invalidate(model);
} else { } else {
resolutionBackgroundColor = resolutionOfflineColor; resolutionBackgroundColor = resolutionOfflineColor;
if (state == ONLINE) {
// state can't be ONLINE while the model is offline
tagText = OFFLINE.name();
}
} }
} else { } else {
State state = model.getOnlineState(true); State state = model.getOnlineState(true);

View File

@ -32,7 +32,6 @@ import com.iheartradio.m3u8.data.StreamInfo;
import ctbrec.AbstractModel; import ctbrec.AbstractModel;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model;
import ctbrec.io.HtmlParser; import ctbrec.io.HtmlParser;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.recorder.download.StreamSource; import ctbrec.recorder.download.StreamSource;
@ -57,6 +56,7 @@ public class BongaCamsModel extends AbstractModel {
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
if (ignoreCache) { if (ignoreCache) {
JSONObject roomData = getRoomData(); JSONObject roomData = getRoomData();
//LOG.debug(roomData.toString(2));
if (!roomData.has("performerData")) { if (!roomData.has("performerData")) {
return false; return false;
} }
@ -64,7 +64,7 @@ public class BongaCamsModel extends AbstractModel {
setDisplayName(performerData.optString("displayName")); 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=" 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"; + 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() Request req = new Request.Builder()
.url(url) .url(url)
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgentMobile) .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgentMobile)
@ -75,22 +75,18 @@ public class BongaCamsModel extends AbstractModel {
.build(); .build();
try (Response resp = site.getHttpClient().execute(req)) { try (Response resp = site.getHttpClient().execute(req)) {
String body = resp.body().string(); String body = resp.body().string();
LOG.trace(body);
JSONObject json = new JSONObject(body); JSONObject json = new JSONObject(body);
if (json.optString(STATUS).equals(SUCCESS)) { if (json.optString(STATUS).equals(SUCCESS)) {
JSONArray models = json.getJSONArray("models"); JSONArray models = json.getJSONArray("models");
for (int i = 0; i < models.length(); i++) { for (int i = 0; i < models.length(); i++) {
JSONObject model = models.getJSONObject(i); JSONObject model = models.getJSONObject(i);
//LOG.debug(model.toString(2));
setDescription(model.optString("topic")); setDescription(model.optString("topic"));
String username = model.optString("username"); String username = model.optString("username");
if (username.equalsIgnoreCase(getName())) { if (username.equalsIgnoreCase(getName())) {
boolean away = model.optBoolean("is_away");
String room = model.optString("room"); String room = model.optString("room");
online = !away mapOnlineState(room);
&& model.optBoolean("online") online = online && isStreamAvailable();
&& room.equalsIgnoreCase("public")
&& isStreamAvailable();
onlineState = Model.State.ONLINE;
break; break;
} }
} }
@ -261,8 +257,10 @@ public class BongaCamsModel extends AbstractModel {
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage()); LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
resolution = new int[2];
} catch (ExecutionException | IOException | ParseException | PlaylistException e) { } catch (ExecutionException | IOException | ParseException | PlaylistException e) {
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage()); LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
resolution = new int[2];
} }
return resolution; return resolution;
} else { } else {
@ -335,7 +333,7 @@ public class BongaCamsModel extends AbstractModel {
throw new IOException("Not logged in"); throw new IOException("Not logged in");
} }
String url = getSite().getBaseUrl() + "/unfollow/" + getName() + '/' + getUserId(); String url = getSite().getBaseUrl() + "/unfollow/" + getName();
LOG.debug("Calling {}", url); LOG.debug("Calling {}", url);
RequestBody body = new FormBody.Builder() RequestBody body = new FormBody.Builder()
.add("_csrf_token", getCsrfToken()) .add("_csrf_token", getCsrfToken())
@ -377,4 +375,21 @@ public class BongaCamsModel extends AbstractModel {
public void setUserId(int userId) { public void setUserId(int userId) {
this.userId = 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);
}
}
} }