Update MFC model state when a page is loaded, so that offline models are detected as offline
This commit is contained in:
parent
8004915125
commit
adf129a0c0
|
@ -1,35 +1,30 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.sites.mfc.MyFreeCams;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.MyFreeCamsModel;
|
||||
import ctbrec.sites.mfc.SessionState;
|
||||
import ctbrec.sites.mfc.User;
|
||||
import ctbrec.sites.mfc.*;
|
||||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static ctbrec.io.HttpConstants.REFERER;
|
||||
import static ctbrec.io.HttpConstants.USER_AGENT;
|
||||
|
||||
public class FriendsUpdateService extends PaginatedScheduledService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FriendsUpdateService.class);
|
||||
private MyFreeCams myFreeCams;
|
||||
private final MyFreeCams myFreeCams;
|
||||
private Mode mode = Mode.ONLINE;
|
||||
|
||||
public enum Mode {
|
||||
|
@ -42,7 +37,7 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<List<Model>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
if (StringUtil.isBlank(ctbrec.Config.getInstance().getSettings().mfcUsername)) {
|
||||
|
@ -76,9 +71,10 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
}
|
||||
})
|
||||
.sorted((m1, m2) -> (int) (m2.getCamScore() - m1.getCamScore()))
|
||||
.skip((page - 1) * 50l)
|
||||
.skip((page - 1) * 50L)
|
||||
.limit(50)
|
||||
.collect(Collectors.toList());
|
||||
.map(Model.class::cast)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,26 +2,21 @@ package ctbrec.ui.sites.myfreecams;
|
|||
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.SessionState;
|
||||
import ctbrec.sites.mfc.User;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HDCamsUpdateService extends PaginatedScheduledService {
|
||||
public class HDCamsUpdateService extends MyFreeCamsAbstractUpdateService {
|
||||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() {
|
||||
var client = MyFreeCamsClient.getInstance();
|
||||
var modelsPerPage = 50;
|
||||
|
||||
return client.getModels().stream()
|
||||
return HDCamsUpdateService.super.getModels().stream()
|
||||
.filter(m -> m.getPreview() != null)
|
||||
.filter(m -> m.getStreamUrl() != null)
|
||||
.filter(m -> Optional.ofNullable(client.getSessionState(m))
|
||||
|
@ -39,8 +34,8 @@ public class HDCamsUpdateService extends PaginatedScheduledService {
|
|||
}
|
||||
})
|
||||
.sorted((m1, m2) -> (int) (m2.getCamScore() - m1.getCamScore()))
|
||||
.skip((page - 1L) * modelsPerPage)
|
||||
.limit(modelsPerPage)
|
||||
.skip((page - 1L) * MODELS_PER_PAGE)
|
||||
.limit(MODELS_PER_PAGE)
|
||||
.map(Model.class::cast)
|
||||
.toList();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.MyFreeCamsModel;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public abstract class MyFreeCamsAbstractUpdateService extends PaginatedScheduledService {
|
||||
static final int MODELS_PER_PAGE = 50;
|
||||
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
||||
|
||||
protected List<MyFreeCamsModel> getModels() {
|
||||
List<MyFreeCamsModel> models = client.getModels().stream()
|
||||
.toList();
|
||||
|
||||
for (Model model : models) {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
client.getSessionState(model);
|
||||
model.isOnline(true);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception e) {
|
||||
log.debug("Couldn't update model on line state", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -1,24 +1,18 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
public class NewModelService extends PaginatedScheduledService {
|
||||
import java.util.List;
|
||||
|
||||
public class NewModelService extends MyFreeCamsAbstractUpdateService {
|
||||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<List<Model>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
var client = MyFreeCamsClient.getInstance();
|
||||
var modelsPerPage = 50;
|
||||
return client.getModels().stream()
|
||||
public List<Model> call() {
|
||||
return NewModelService.super.getModels().stream()
|
||||
.filter(m -> m.getPreview() != null)
|
||||
.filter(m -> m.getStreamUrl() != null)
|
||||
.filter(m -> {
|
||||
|
@ -29,9 +23,10 @@ public class NewModelService extends PaginatedScheduledService {
|
|||
}
|
||||
})
|
||||
.sorted((m1, m2) -> m2.getViewerCount() - m1.getViewerCount())
|
||||
.skip( (page-1) * (long)modelsPerPage)
|
||||
.limit(modelsPerPage)
|
||||
.collect(Collectors.toList());
|
||||
.skip((page - 1) * (long) MODELS_PER_PAGE)
|
||||
.limit(MODELS_PER_PAGE)
|
||||
.map(Model.class::cast)
|
||||
.toList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
public class OnlineCamsUpdateService extends PaginatedScheduledService {
|
||||
import java.util.List;
|
||||
|
||||
public class OnlineCamsUpdateService extends MyFreeCamsAbstractUpdateService {
|
||||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<List<Model>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
var client = MyFreeCamsClient.getInstance();
|
||||
var modelsPerPage = 50;
|
||||
return client.getModels().stream()
|
||||
public List<Model> call() {
|
||||
|
||||
return OnlineCamsUpdateService.super.getModels().stream()
|
||||
.filter(m -> m.getPreview() != null)
|
||||
.filter(m -> m.getStreamUrl() != null)
|
||||
.filter(m -> {
|
||||
|
@ -32,10 +27,11 @@ public class OnlineCamsUpdateService extends PaginatedScheduledService {
|
|||
return false;
|
||||
}
|
||||
})
|
||||
.sorted((m1,m2) -> (int)(m2.getCamScore() - m1.getCamScore()))
|
||||
.skip( (page-1) * (long)modelsPerPage)
|
||||
.limit(modelsPerPage)
|
||||
.collect(Collectors.toList());
|
||||
.sorted((m1, m2) -> (int) (m2.getCamScore() - m1.getCamScore()))
|
||||
.skip((page - 1) * (long) MODELS_PER_PAGE)
|
||||
.limit(MODELS_PER_PAGE)
|
||||
.map(Model.class::cast)
|
||||
.toList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,24 +1,18 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
public class PopularModelService extends PaginatedScheduledService {
|
||||
import java.util.List;
|
||||
|
||||
public class PopularModelService extends MyFreeCamsAbstractUpdateService {
|
||||
|
||||
@Override
|
||||
protected Task<List<Model>> createTask() {
|
||||
return new Task<List<Model>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
var client = MyFreeCamsClient.getInstance();
|
||||
var modelsPerPage = 50;
|
||||
return client.getModels().stream()
|
||||
public List<Model> call() {
|
||||
return PopularModelService.super.getModels().stream()
|
||||
.filter(m -> m.getPreview() != null)
|
||||
.filter(m -> m.getStreamUrl() != null)
|
||||
.filter(m -> {
|
||||
|
@ -32,9 +26,10 @@ public class PopularModelService extends PaginatedScheduledService {
|
|||
}
|
||||
})
|
||||
.sorted((m1, m2) -> m2.getViewerCount() - m1.getViewerCount())
|
||||
.skip( (page-1) * (long)modelsPerPage)
|
||||
.limit(modelsPerPage)
|
||||
.collect(Collectors.toList());
|
||||
.skip((page - 1) * (long) MODELS_PER_PAGE)
|
||||
.limit(MODELS_PER_PAGE)
|
||||
.map(Model.class::cast)
|
||||
.toList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package ctbrec.ui.sites.myfreecams;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import ctbrec.sites.mfc.MyFreeCams;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.SessionState;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class TableUpdateService extends ScheduledService<Collection<SessionState>> {
|
||||
|
||||
private MyFreeCams mfc;
|
||||
private final MyFreeCams mfc;
|
||||
|
||||
public TableUpdateService(MyFreeCams mfc) {
|
||||
this.mfc = mfc;
|
||||
|
@ -19,9 +18,9 @@ public class TableUpdateService extends ScheduledService<Collection<SessionState
|
|||
|
||||
@Override
|
||||
protected Task<Collection<SessionState>> createTask() {
|
||||
return new Task<Collection<SessionState>>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
public Collection<SessionState> call() throws IOException {
|
||||
public Collection<SessionState> call() {
|
||||
MyFreeCamsClient client = mfc.getClient();
|
||||
return client.getSessionStates();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue