diff --git a/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java b/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java index 3a82a1f5..bffbed64 100644 --- a/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java +++ b/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java @@ -175,22 +175,27 @@ public class RecordingPreconditions { return; } - for (String modelUrl : modelGroup.get().getModelUrls()) { - if (modelUrl.equals(model.getUrl())) { + for (var groupModel : modelGroup.get().getModelUrls().stream() + .map(modelUrl -> getModelForUrl(modelUrl)) + .filter(x -> x.isPresent()) + .map(x -> x.get()) + .sorted((l, r) -> Integer.compare(r.getPriority(), l.getPriority())) // high to low + .toList()) { + if (model.getUrl().equals(groupModel.getUrl())) { // no other model with higher prio is online, start recording // but before that stop all recordings of models with lower prio stopModelsWithLowerPrio(modelGroup.get()); return; } else { - Optional otherModel = getModelForUrl(modelUrl); + Optional otherModel = getModelForUrl(groupModel.getUrl()); if (otherModel.isPresent()) { - if (otherModelIsRecorded(otherModel.get())) { + if (!otherModel.get().isSuspended() && otherModelIsRecorded(otherModel.get())) { throw new PreconditionNotMetException(otherModel.get() + " from the same group is already recorded"); } else if (otherModelCanBeRecorded(otherModel.get())) { throw new PreconditionNotMetException(otherModel.get() + " from the same group can be recorded"); } } else { - LOG.warn("Couldn't check if model from same group has higer prio for {}", modelUrl); + LOG.warn("Couldn't check if model from same group has higer prio for {}", groupModel.getUrl()); } } }