forked from j62/ctbrec
1
0
Fork 0

Fix bug in MyFreeCams online detection

This commit is contained in:
0xb00bface 2022-06-11 19:18:23 +02:00
parent 73598fa590
commit cdd8ae0d7a
2 changed files with 52 additions and 70 deletions

View File

@ -22,12 +22,12 @@ import org.slf4j.LoggerFactory;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import java.util.concurrent.ExecutionException;
import static ctbrec.io.HttpConstants.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Optional.ofNullable;
public class MyFreeCamsModel extends AbstractModel {
@ -44,7 +44,9 @@ public class MyFreeCamsModel extends AbstractModel {
/**
* This constructor exists only for deserialization. Please don't call it directly
*/
public MyFreeCamsModel() {}
@SuppressWarnings("unused")
public MyFreeCamsModel() {
}
MyFreeCamsModel(MyFreeCams site) {
this.site = site;
@ -62,6 +64,7 @@ public class MyFreeCamsModel extends AbstractModel {
List<ctbrec.Model> searchResult = MyFreeCamsClient.getInstance().search(getName());
if (!searchResult.isEmpty()) {
MyFreeCamsModel m = (MyFreeCamsModel) searchResult.get(0);
this.state = m.state;
this.onlineState = m.getOnlineState(true);
}
}
@ -248,20 +251,10 @@ public class MyFreeCamsModel extends AbstractModel {
setPreview(previewUrl);
// tags
ofNullable(state.getM()).map(Model::getTags).ifPresent(tags -> {
ArrayList<String> t = new ArrayList<>();
t.addAll(tags);
setTags(t);
});
ofNullable(state.getM()).map(Model::getTags).ifPresent(tags -> setTags(new ArrayList<>(tags)));
// description
ofNullable(state.getM()).map(Model::getTopic).ifPresent(topic -> {
try {
setDescription(URLDecoder.decode(topic, "utf-8"));
} catch (UnsupportedEncodingException e) {
LOG.warn("Couldn't url decode topic", e);
}
});
ofNullable(state.getM()).map(Model::getTopic).ifPresent(topic -> setDescription(URLDecoder.decode(topic, UTF_8)));
viewerCount = ofNullable(state.getM()).map(Model::getRc).orElse(0);
}

View File

@ -15,38 +15,27 @@ public enum State {
OFFLINE("offline"),
UNKNOWN("unknown");
String literal;
final String literal;
State(String literal) {
this.literal = literal;
}
public static State of(Integer vs) {
Integer s = Optional.ofNullable(vs).orElse(Integer.MAX_VALUE);
switch (s) {
case 0:
return ONLINE;
case 90:
return CAMOFF;
case -4:
return RECORDING;
case -3:
return INCLUDE;
case -2:
return EXCLUDE;
case -1:
return DELETE;
case 2:
return AWAY;
case 12:
case 91:
return PRIVATE;
case 13:
return GROUP_SHOW;
case 127:
return OFFLINE;
default:
return UNKNOWN;
}
return switch (s) {
case 0 -> ONLINE;
case 90 -> CAMOFF;
case -4 -> RECORDING;
case -3 -> INCLUDE;
case -2 -> EXCLUDE;
case -1 -> DELETE;
case 2 -> AWAY;
case 12, 91 -> PRIVATE;
case 13 -> GROUP_SHOW;
case 127 -> OFFLINE;
default -> UNKNOWN;
};
}
@Override