Add getCurrentlyRecording to recorder

This method returns the models, which are currently recorded. It is
implemented as default method, so that LocalRecorder and RemoteRecorder
don't have to implement the same logic.
This commit is contained in:
0xboobface 2019-02-05 15:07:56 +01:00
parent 76f4583ebc
commit 097fb251cb
2 changed files with 25 additions and 3 deletions

View File

@ -254,8 +254,8 @@ public class CamrecApplication extends Application {
public void handleEvent(Event evt) {
if(evt.getType() == Event.Type.MODEL_ONLINE || evt.getType() == Event.Type.MODEL_STATUS_CHANGED || evt.getType() == Event.Type.RECORDING_STATUS_CHANGED) {
try {
List<Model> models = recorder.getOnlineModels();
long count = models.stream().filter(m -> !recorder.isSuspended(m)).count();
List<Model> models = recorder.getCurrentlyRecording();
long count = models.size();
String _title = count > 0 ? "(" + count + ") " + title : title;
Platform.runLater(() -> primaryStage.setTitle(_title));
} catch (Exception e) {

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.stream.Collectors;
import ctbrec.Model;
import ctbrec.Recording;
@ -41,11 +42,31 @@ public interface Recorder {
public boolean isSuspended(Model model);
/**
* Returns only the models from getModelsRecording(), which are online
* Returns only the models from getModels(), which are online
* @return
*/
public List<Model> getOnlineModels();
/**
* Returns only the models from getModels(), which are actually recorded right now
* @return
* @throws IOException
* @throws IllegalStateException
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
*/
public default List<Model> getCurrentlyRecording() throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, IOException {
List<Recording> recordings = getRecordings();
return getModels().stream().filter(m -> {
for (Recording recording : recordings) {
if (recording.getStatus() == Recording.State.RECORDING && recording.getModelName().equals(m.getName())) {
return true;
}
}
return false;
}).collect(Collectors.toList());
}
public HttpClient getHttpClient();
/**
@ -72,4 +93,5 @@ public interface Recorder {
* @throws IOException
*/
public void regeneratePlaylist(Recording recording) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException;
}