Fix Flirt4Free models losing their name
This commit is contained in:
parent
0e61421537
commit
192e7093d3
|
@ -86,12 +86,11 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
return false;
|
||||
}
|
||||
JSONObject json = new JSONObject(body);
|
||||
//LOG.debug("check model status: {}", json.toString(2));
|
||||
online = Objects.equals(json.optString("status"), "online");
|
||||
id = String.valueOf(json.get("model_id"));
|
||||
online = Objects.equals(json.optString("status"), "online"); // online is true, even if the model is in private or away
|
||||
updateModelId(json);
|
||||
if (online) {
|
||||
try {
|
||||
loadStreamUrl();
|
||||
loadModelInfo();
|
||||
} catch (Exception e) {
|
||||
online = false;
|
||||
onlineState = Model.State.OFFLINE;
|
||||
|
@ -109,6 +108,18 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
return online;
|
||||
}
|
||||
|
||||
private void updateModelId(JSONObject json) {
|
||||
if (json.has("model_id")) {
|
||||
Object modelId = json.get("model_id");
|
||||
if (modelId instanceof Number) {
|
||||
Number n = (Number) modelId;
|
||||
if (n.intValue() > 0) {
|
||||
id = String.valueOf(json.get("model_id"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModelInfo() throws IOException, InterruptedException {
|
||||
String url = getSite().getBaseUrl() + "/webservices/chat-room-interface.php?a=login_room&model_id=" + id;
|
||||
LOG.trace("Loading url {}", url);
|
||||
|
@ -127,13 +138,15 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
// LOG.debug("chat-room-interface {}", json.toString(2));
|
||||
JSONObject config = json.getJSONObject("config");
|
||||
JSONObject performer = config.getJSONObject("performer");
|
||||
setName(performer.optString("name_seo", "n/a"));
|
||||
setDisplayName(performer.optString("name", "n/a"));
|
||||
setUrl(getSite().getBaseUrl() + "/rooms/" + getName() + '/');
|
||||
setDisplayName(performer.optString("name", getName()));
|
||||
JSONObject room = config.getJSONObject("room");
|
||||
chatHost = room.getString("host");
|
||||
chatPort = room.getString("port_to_be");
|
||||
chatToken = json.getString("token_enc");
|
||||
String status = room.optString("status");
|
||||
setOnlineState(mapStatus(status));
|
||||
online = onlineState == State.ONLINE;
|
||||
JSONObject user = config.getJSONObject("user");
|
||||
userIp = user.getString("ip");
|
||||
} else {
|
||||
|
@ -147,6 +160,19 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
}
|
||||
}
|
||||
|
||||
private State mapStatus(String status) {
|
||||
switch (status) {
|
||||
case "P":
|
||||
case "F":
|
||||
return State.PRIVATE;
|
||||
case "A":
|
||||
return State.AWAY;
|
||||
case "O":
|
||||
default:
|
||||
return State.ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||
return getStreamSources(true);
|
||||
|
@ -238,10 +264,9 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
streamHost = data.getString("stream_host"); // TODO look, if the stream_host is equal to the one encoded in base64 in some of the ajax requests (parameters)
|
||||
online = true;
|
||||
isInteractiveShow = data.optString("devices").equals("1");
|
||||
if(data.optString("room_state").equals("P")) {
|
||||
onlineState = Model.State.PRIVATE;
|
||||
online = false;
|
||||
}
|
||||
String roomState = data.optString("room_state");
|
||||
onlineState = mapStatus(roomState);
|
||||
online = onlineState == State.ONLINE;
|
||||
if(data.optString("room_state").equals("0") && data.optString("login_group_id").equals("14")) {
|
||||
onlineState = Model.State.GROUP;
|
||||
online = false;
|
||||
|
@ -456,8 +481,10 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
reader.nextName();
|
||||
id = reader.nextString();
|
||||
if (reader.hasNext()) {
|
||||
reader.nextName();
|
||||
id = reader.nextString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -482,7 +509,7 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
}
|
||||
|
||||
private void acquireSlot() throws InterruptedException {
|
||||
//LOG.debug("Acquire: {}", requestThrottle.availablePermits());
|
||||
LOG.debug("Acquire: {} - Queue: {}", requestThrottle.availablePermits(), requestThrottle.getQueueLength());
|
||||
requestThrottle.acquire();
|
||||
long now = System.currentTimeMillis();
|
||||
long millisSinceLastRequest = now - lastRequest;
|
||||
|
@ -495,6 +522,6 @@ public class Flirt4FreeModel extends AbstractModel {
|
|||
private void releaseSlot() {
|
||||
lastRequest = System.currentTimeMillis();
|
||||
requestThrottle.release();
|
||||
//LOG.debug("Release: {}", requestThrottle.availablePermits());
|
||||
// LOG.debug("Release: {}", requestThrottle.availablePermits());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue