forked from j62/ctbrec
1
0
Fork 0

Fix followed page for MFC

This commit is contained in:
0xboobface 2019-12-21 19:54:49 +01:00
parent 2fb2c932aa
commit 45d18c754a
1 changed files with 21 additions and 29 deletions

View File

@ -1,6 +1,5 @@
package ctbrec.ui.sites.myfreecams;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@ -26,13 +25,12 @@ import okhttp3.Response;
public class FriendsUpdateService extends PaginatedScheduledService {
private static final transient Logger LOG = LoggerFactory.getLogger(FriendsUpdateService.class);
private static final Logger LOG = LoggerFactory.getLogger(FriendsUpdateService.class);
private MyFreeCams myFreeCams;
private Mode mode = Mode.ONLINE;
public static enum Mode {
ONLINE,
OFFLINE
public enum Mode {
ONLINE, OFFLINE
}
public FriendsUpdateService(MyFreeCams myFreeCams) {
@ -44,25 +42,22 @@ public class FriendsUpdateService extends PaginatedScheduledService {
return new Task<List<Model>>() {
@Override
public List<Model> call() throws IOException {
if(StringUtil.isBlank(ctbrec.Config.getInstance().getSettings().mfcUsername)) {
if (StringUtil.isBlank(ctbrec.Config.getInstance().getSettings().mfcUsername)) {
return Collections.emptyList();
} else {
List<MyFreeCamsModel> models = new ArrayList<>();
SiteUiFactory.getUi(myFreeCams).login();
String url = myFreeCams.getBaseUrl() + "/php/manage_lists2.php?passcode=&list_type=friends&data_mode=online&get_user_list=1";
Request req = new Request.Builder()
.url(url)
.header("Referer", myFreeCams.getBaseUrl())
.build();
try(Response resp = myFreeCams.getHttpClient().execute(req)) {
if(resp.isSuccessful()) {
Request req = new Request.Builder().url(url).header("Referer", myFreeCams.getBaseUrl()).build();
try (Response resp = myFreeCams.getHttpClient().execute(req)) {
if (resp.isSuccessful()) {
String body = resp.body().string().substring(4);
try {
JSONObject json = new JSONObject(body);
for (String key : json.keySet()) {
int uid = Integer.parseInt(key);
MyFreeCamsModel model = MyFreeCamsClient.getInstance().getModel(uid);
if(model == null) {
if (model == null) {
JSONObject modelObject = json.getJSONObject(key);
String name = modelObject.getString("u");
model = myFreeCams.createModel(name);
@ -73,31 +68,28 @@ public class FriendsUpdateService extends PaginatedScheduledService {
st.setUid(uid);
st.setLv(modelObject.getInt("lv"));
st.setVs(127);
model.update(st, myFreeCams.getClient().getStreamUrl(st));
}
models.add(model);
}
} catch(Exception e) {
LOG.info("Exception getting friends list. Response was: {}", body);
} catch (Exception e) {
LOG.info("Exception getting friends list. Response was: {}", body, e);
}
} else {
LOG.error("Couldn't load friends list {} {}", resp.code(), resp.message());
}
}
boolean filterOnline = mode == Mode.ONLINE;
return models.stream()
.filter(m -> {
try {
return m.isOnline() == filterOnline;
} catch(Exception e) {
return false;
}
})
.sorted((m1,m2) -> (int)(m2.getCamScore() - m1.getCamScore()))
.skip((page-1) * 50)
.limit(50)
.collect(Collectors.toList());
return models.stream().filter(m -> {
try {
return m.isOnline() == filterOnline;
} catch (Exception e) {
return false;
}
})
.sorted((m1, m2) -> (int) (m2.getCamScore() - m1.getCamScore()))
.skip((page - 1) * 50l)
.limit(50)
.collect(Collectors.toList());
}
}
};