forked from j62/ctbrec
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;
|
return false;
|
||||||
}
|
}
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
//LOG.debug("check model status: {}", json.toString(2));
|
online = Objects.equals(json.optString("status"), "online"); // online is true, even if the model is in private or away
|
||||||
online = Objects.equals(json.optString("status"), "online");
|
updateModelId(json);
|
||||||
id = String.valueOf(json.get("model_id"));
|
|
||||||
if (online) {
|
if (online) {
|
||||||
try {
|
try {
|
||||||
loadStreamUrl();
|
loadModelInfo();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
online = false;
|
online = false;
|
||||||
onlineState = Model.State.OFFLINE;
|
onlineState = Model.State.OFFLINE;
|
||||||
|
@ -109,6 +108,18 @@ public class Flirt4FreeModel extends AbstractModel {
|
||||||
return online;
|
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 {
|
private void loadModelInfo() throws IOException, InterruptedException {
|
||||||
String url = getSite().getBaseUrl() + "/webservices/chat-room-interface.php?a=login_room&model_id=" + id;
|
String url = getSite().getBaseUrl() + "/webservices/chat-room-interface.php?a=login_room&model_id=" + id;
|
||||||
LOG.trace("Loading url {}", url);
|
LOG.trace("Loading url {}", url);
|
||||||
|
@ -127,13 +138,15 @@ public class Flirt4FreeModel extends AbstractModel {
|
||||||
// LOG.debug("chat-room-interface {}", json.toString(2));
|
// LOG.debug("chat-room-interface {}", json.toString(2));
|
||||||
JSONObject config = json.getJSONObject("config");
|
JSONObject config = json.getJSONObject("config");
|
||||||
JSONObject performer = config.getJSONObject("performer");
|
JSONObject performer = config.getJSONObject("performer");
|
||||||
setName(performer.optString("name_seo", "n/a"));
|
|
||||||
setDisplayName(performer.optString("name", "n/a"));
|
|
||||||
setUrl(getSite().getBaseUrl() + "/rooms/" + getName() + '/');
|
setUrl(getSite().getBaseUrl() + "/rooms/" + getName() + '/');
|
||||||
|
setDisplayName(performer.optString("name", getName()));
|
||||||
JSONObject room = config.getJSONObject("room");
|
JSONObject room = config.getJSONObject("room");
|
||||||
chatHost = room.getString("host");
|
chatHost = room.getString("host");
|
||||||
chatPort = room.getString("port_to_be");
|
chatPort = room.getString("port_to_be");
|
||||||
chatToken = json.getString("token_enc");
|
chatToken = json.getString("token_enc");
|
||||||
|
String status = room.optString("status");
|
||||||
|
setOnlineState(mapStatus(status));
|
||||||
|
online = onlineState == State.ONLINE;
|
||||||
JSONObject user = config.getJSONObject("user");
|
JSONObject user = config.getJSONObject("user");
|
||||||
userIp = user.getString("ip");
|
userIp = user.getString("ip");
|
||||||
} else {
|
} 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
|
@Override
|
||||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||||
return getStreamSources(true);
|
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)
|
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;
|
online = true;
|
||||||
isInteractiveShow = data.optString("devices").equals("1");
|
isInteractiveShow = data.optString("devices").equals("1");
|
||||||
if(data.optString("room_state").equals("P")) {
|
String roomState = data.optString("room_state");
|
||||||
onlineState = Model.State.PRIVATE;
|
onlineState = mapStatus(roomState);
|
||||||
online = false;
|
online = onlineState == State.ONLINE;
|
||||||
}
|
|
||||||
if(data.optString("room_state").equals("0") && data.optString("login_group_id").equals("14")) {
|
if(data.optString("room_state").equals("0") && data.optString("login_group_id").equals("14")) {
|
||||||
onlineState = Model.State.GROUP;
|
onlineState = Model.State.GROUP;
|
||||||
online = false;
|
online = false;
|
||||||
|
@ -456,9 +481,11 @@ public class Flirt4FreeModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||||
|
if (reader.hasNext()) {
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
id = reader.nextString();
|
id = reader.nextString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
||||||
|
@ -482,7 +509,7 @@ public class Flirt4FreeModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void acquireSlot() throws InterruptedException {
|
private void acquireSlot() throws InterruptedException {
|
||||||
//LOG.debug("Acquire: {}", requestThrottle.availablePermits());
|
LOG.debug("Acquire: {} - Queue: {}", requestThrottle.availablePermits(), requestThrottle.getQueueLength());
|
||||||
requestThrottle.acquire();
|
requestThrottle.acquire();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long millisSinceLastRequest = now - lastRequest;
|
long millisSinceLastRequest = now - lastRequest;
|
||||||
|
@ -495,6 +522,6 @@ public class Flirt4FreeModel extends AbstractModel {
|
||||||
private void releaseSlot() {
|
private void releaseSlot() {
|
||||||
lastRequest = System.currentTimeMillis();
|
lastRequest = System.currentTimeMillis();
|
||||||
requestThrottle.release();
|
requestThrottle.release();
|
||||||
//LOG.debug("Release: {}", requestThrottle.availablePermits());
|
// LOG.debug("Release: {}", requestThrottle.availablePermits());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue