From 0fe16f8ff8102ff3dacbf50473fe3481f5067232 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sun, 9 Aug 2020 12:27:04 +0200 Subject: [PATCH] Add setting to disable online check for paused models --- .../src/main/java/ctbrec/ui/CamrecApplication.java | 2 +- .../main/java/ctbrec/ui/settings/SettingsTab.java | 7 +++++-- .../main/resources/html/docs/ConfigurationFile.md | 6 +++++- common/src/main/java/ctbrec/Settings.java | 1 + .../main/java/ctbrec/recorder/OnlineMonitor.java | 14 ++++++++++---- .../java/ctbrec/recorder/server/HttpServer.java | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 7c23ec30..29469fb1 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -151,7 +151,7 @@ public class CamrecApplication extends Application { } } } - onlineMonitor = new OnlineMonitor(recorder); + onlineMonitor = new OnlineMonitor(recorder, config); onlineMonitor.start(); } diff --git a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java index 7d3a3c52..3ce04942 100644 --- a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java @@ -83,6 +83,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { private DiscreteRange rangeValues = new DiscreteRange<>(values, labels); private SimpleIntegerProperty concurrentRecordings; private SimpleIntegerProperty onlineCheckIntervalInSecs; + private SimpleBooleanProperty onlineCheckSkipsPausedModels; private SimpleLongProperty leaveSpaceOnDevice; private SimpleIntegerProperty minimumLengthInSecs; private SimpleStringProperty ffmpegParameters; @@ -146,6 +147,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { postProcessing = new SimpleFileProperty(null, "postProcessing", settings.postProcessing); postProcessingThreads = new SimpleIntegerProperty(null, "postProcessingThreads", settings.postProcessingThreads); removeRecordingAfterPp = new SimpleBooleanProperty(null, "removeRecordingAfterPostProcessing", settings.removeRecordingAfterPostProcessing); + onlineCheckSkipsPausedModels = new SimpleBooleanProperty(null, "onlineCheckSkipsPausedModels", settings.onlineCheckSkipsPausedModels); } private void createGui() { @@ -183,10 +185,11 @@ public class SettingsTab extends Tab implements TabSelectionListener { Setting.of("Split recordings after (minutes)", splitAfter).converter(SplitAfterOption.converter()), Setting.of("Restrict Resolution", resolutionRange, "Only record streams with resolution within the given range"), Setting.of("Concurrent Recordings (0 = unlimited)", concurrentRecordings), - Setting.of("Check online state every (seconds)", onlineCheckIntervalInSecs, "Check every x seconds, if a model came online"), Setting.of("Leave space on device (GiB)", leaveSpaceOnDevice, "Stop recording, if the free space on the device gets below this threshold").converter(new GigabytesConverter()), Setting.of("FFmpeg parameters", ffmpegParameters, "FFmpeg parameters to use when merging stream segments"), - Setting.of("File Extension", fileExtension, "File extension to use for recordings") + Setting.of("File Extension", fileExtension, "File extension to use for recordings"), + Setting.of("Check online state every (seconds)", onlineCheckIntervalInSecs, "Check every x seconds, if a model came online"), + Setting.of("Skip online check for paused models", onlineCheckSkipsPausedModels, "Skip online check for paused models") ), Group.of("Location", Setting.of("Record Location", recordLocal), diff --git a/client/src/main/resources/html/docs/ConfigurationFile.md b/client/src/main/resources/html/docs/ConfigurationFile.md index d1312750..e3ea4bf1 100644 --- a/client/src/main/resources/html/docs/ConfigurationFile.md +++ b/client/src/main/resources/html/docs/ConfigurationFile.md @@ -41,13 +41,17 @@ the port ctbrec tries to connect to, if it is run in remote mode. - **livePreviews** (app only) - Enables the live preview feature in the app. +- **minimumResolution** - [1 - 2147483647]. Sets the minimum video height for a recording. ctbrec tries to find a stream quality, which is higher than or equal to this value. If the only provided stream quality is below this threshold, ctbrec won't record the stream. + - **maximumResolution** - [1 - 2147483647]. Sets the maximum video height for a recording. ctbrec tries to find a stream quality, which is lower than or equal to this value. If the only provided stream quality is above this threshold, ctbrec won't record the stream. - **minimumLengthInSeconds** - [0 - 2147483647] Automatically delete recordings, which are shorter than this amount of seconds. 0 disables this feature. - **minimumSpaceLeftInBytes** - [0 - 9223372036854775807] The space in bytes ctbrec should conserve on the hard drive. 1 GiB = 1024 MiB = 1048576 KiB = 1073741824 bytes -- **onlineCheckIntervalInSecs** - [1 - 2147483647] How often ctbrec checks, if a model is online. This is not a guaranteed interval: If you record many models, the online check for all models can take longer than this interval. A minute is a reasonable value, but you can go lower, if you don't want to miss a anything. But don't go too low, or you risk to do too many requests in a short amount of time and get banned by some sites. +- **onlineCheckIntervalInSecs** - [1 - 2147483647] How often ctbrec checks, if a model is online. This is not a guaranteed interval: If you record many models, the online check for all models can take longer than this interval. A minute is a reasonable value, but you can go lower, if you don't want to miss a anything. But don't go too low, or you risk to do too many requests in a short amount of time and get banned by some sites. + +- **onlineCheckSkipsPausedModels** - [`true`,`false`] Skip the online check for paused models. If you have many models in the recording list, this can reduce the delay when a recording starts after a model came online. - **postProcessing** - Absolute path to a script, which is executed once a recording is finished. See [Post-Processing](/docs/PostProcessing.md). diff --git a/common/src/main/java/ctbrec/Settings.java b/common/src/main/java/ctbrec/Settings.java index 9094117b..e6c7e5fc 100644 --- a/common/src/main/java/ctbrec/Settings.java +++ b/common/src/main/java/ctbrec/Settings.java @@ -89,6 +89,7 @@ public class Settings { public List models = new ArrayList<>(); public List modelsIgnored = new ArrayList<>(); public int onlineCheckIntervalInSecs = 60; + public boolean onlineCheckSkipsPausedModels = false; public int overviewUpdateIntervalInSecs = 10; public String password = ""; // chaturbate password TODO maybe rename this onetime public String postProcessing = ""; diff --git a/common/src/main/java/ctbrec/recorder/OnlineMonitor.java b/common/src/main/java/ctbrec/recorder/OnlineMonitor.java index 6d633d61..8cfcc801 100644 --- a/common/src/main/java/ctbrec/recorder/OnlineMonitor.java +++ b/common/src/main/java/ctbrec/recorder/OnlineMonitor.java @@ -38,9 +38,11 @@ public class OnlineMonitor extends Thread { private Map states = new HashMap<>(); private Map executors = new HashMap<>(); + private Config config; - public OnlineMonitor(Recorder recorder) { + public OnlineMonitor(Recorder recorder, Config config) { this.recorder = recorder; + this.config = config; setName("OnlineMonitor"); setDaemon(true); } @@ -80,7 +82,11 @@ public class OnlineMonitor extends Thread { // submit online check jobs to the executor for the model's site List> futures = new LinkedList<>(); for (Model model : models) { - futures.add(updateModel(model)); + if (config.getSettings().onlineCheckSkipsPausedModels && model.isSuspended()) { + continue; + } else { + futures.add(updateModel(model)); + } } // wait for all jobs to finish for (Future future : futures) { @@ -111,7 +117,7 @@ public class OnlineMonitor extends Thread { model.setLastSeen(Instant.now()); } Model.State state = model.getOnlineState(false); - LOG.trace("Model online state: {} {}", model.getName(), state); + LOG.debug("Model online state: {} {}", model.getName(), state); Model.State oldState = states.getOrDefault(model, UNKNOWN); states.put(model, state); if (state != oldState) { @@ -134,7 +140,7 @@ public class OnlineMonitor extends Thread { private void suspendUntilNextIteration(List models, Duration timeCheckTook) { LOG.trace("Online check for {} models took {} seconds", models.size(), timeCheckTook.getSeconds()); - long sleepTime = Config.getInstance().getSettings().onlineCheckIntervalInSecs; + long sleepTime = config.getSettings().onlineCheckIntervalInSecs; if(timeCheckTook.getSeconds() < sleepTime) { try { if (running) { diff --git a/server/src/main/java/ctbrec/recorder/server/HttpServer.java b/server/src/main/java/ctbrec/recorder/server/HttpServer.java index f97d49b2..fb179fbe 100644 --- a/server/src/main/java/ctbrec/recorder/server/HttpServer.java +++ b/server/src/main/java/ctbrec/recorder/server/HttpServer.java @@ -106,7 +106,7 @@ public class HttpServer { safeLogin(site); } } - onlineMonitor = new OnlineMonitor(recorder); + onlineMonitor = new OnlineMonitor(recorder, config); onlineMonitor.start(); startHttpServer(); }