forked from j62/ctbrec
1
0
Fork 0

Add GUI for setting splitRecordingsBiggerThanBytes

This commit is contained in:
0xb00bface 2020-12-05 22:39:03 +01:00
parent a31debcdea
commit d88e5ab960
4 changed files with 131 additions and 8 deletions

View File

@ -1,3 +1,10 @@
3.10.7
========================
* Fixed credentials related bugs for Streamate and Stripchat
They used the user name from Chaturbate for some requests. Whoopsie!
* Renamed settings for Chaturbate's user name and password
* Add setting to split recordings by size
3.10.6 3.10.6
======================== ========================
* Fixed Cam4 downloads * Fixed Cam4 downloads

View File

@ -28,6 +28,7 @@ import javafx.beans.property.ListProperty;
import javafx.beans.property.LongProperty; import javafx.beans.property.LongProperty;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
@ -267,6 +268,9 @@ public class CtbrecPreferencesStorage implements PreferencesStorage {
} }
config.save(); config.save();
})); }));
if(setting.getChangeListener() != null) {
comboBox.valueProperty().addListener((ChangeListener<? super Object>) setting.getChangeListener());
}
return comboBox; return comboBox;
} }

View File

@ -2,6 +2,7 @@ package ctbrec.ui.settings;
import static ctbrec.Settings.DirectoryStructure.*; import static ctbrec.Settings.DirectoryStructure.*;
import static ctbrec.Settings.ProxyType.*; import static ctbrec.Settings.ProxyType.*;
import static ctbrec.Settings.SplitStrategy.*;
import static java.util.Optional.*; import static java.util.Optional.*;
import java.io.IOException; import java.io.IOException;
@ -57,6 +58,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private static final Logger LOG = LoggerFactory.getLogger(SettingsTab.class); private static final Logger LOG = LoggerFactory.getLogger(SettingsTab.class);
public static final int CHECKBOX_MARGIN = 6; public static final int CHECKBOX_MARGIN = 6;
private static final long MiB = 1024 * 1024L;
private static final long GiB = 1024 * MiB;
private List<Site> sites; private List<Site> sites;
private Recorder recorder; private Recorder recorder;
@ -85,6 +88,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private SimpleDirectoryProperty recordingsDir; private SimpleDirectoryProperty recordingsDir;
private SimpleListProperty<DirectoryStructure> directoryStructure; private SimpleListProperty<DirectoryStructure> directoryStructure;
private SimpleListProperty<SplitAfterOption> splitAfter; private SimpleListProperty<SplitAfterOption> splitAfter;
private SimpleListProperty<SplitBiggerThanOption> splitBiggerThan;
private SimpleRangeProperty<Integer> resolutionRange; private SimpleRangeProperty<Integer> resolutionRange;
private List<Integer> labels = Arrays.asList(0, 240, 360, 480, 600, 720, 960, 1080, 1440, 2160, 4320, 8640); private List<Integer> labels = Arrays.asList(0, 240, 360, 480, 600, 720, 960, 1080, 1440, 2160, 4320, 8640);
private List<Integer> values = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); private List<Integer> values = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
@ -104,8 +108,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private ExclusiveSelectionProperty recordLocal; private ExclusiveSelectionProperty recordLocal;
private SimpleIntegerProperty postProcessingThreads; private SimpleIntegerProperty postProcessingThreads;
private IgnoreList ignoreList; private IgnoreList ignoreList;
private PostProcessingStepPanel postProcessingStepPanel;
private Button variablesHelpButton;
public SettingsTab(List<Site> sites, Recorder recorder) { public SettingsTab(List<Site> sites, Recorder recorder) {
this.sites = sites; this.sites = sites;
@ -137,7 +139,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
proxyPassword = new SimpleStringProperty(null, "proxyPassword", settings.proxyPassword); proxyPassword = new SimpleStringProperty(null, "proxyPassword", settings.proxyPassword);
recordingsDir = new SimpleDirectoryProperty(null, "recordingsDir", settings.recordingsDir); recordingsDir = new SimpleDirectoryProperty(null, "recordingsDir", settings.recordingsDir);
directoryStructure = new SimpleListProperty<>(null, "recordingsDirStructure", FXCollections.observableList(List.of(FLAT, ONE_PER_MODEL, ONE_PER_RECORDING))); directoryStructure = new SimpleListProperty<>(null, "recordingsDirStructure", FXCollections.observableList(List.of(FLAT, ONE_PER_MODEL, ONE_PER_RECORDING)));
splitAfter = new SimpleListProperty<>(null, "splitRecordings", FXCollections.observableList(getSplitOptions())); splitAfter = new SimpleListProperty<>(null, "splitRecordingsAfterSecs", FXCollections.observableList(getSplitAfterSecsOptions()));
splitBiggerThan = new SimpleListProperty<>(null, "splitRecordingsBiggerThanBytes", FXCollections.observableList(getSplitBiggerThanOptions()));
resolutionRange = new SimpleRangeProperty<>(rangeValues, "minimumResolution", "maximumResolution", settings.minimumResolution, settings.maximumResolution); resolutionRange = new SimpleRangeProperty<>(rangeValues, "minimumResolution", "maximumResolution", settings.minimumResolution, settings.maximumResolution);
concurrentRecordings = new SimpleIntegerProperty(null, "concurrentRecordings", settings.concurrentRecordings); concurrentRecordings = new SimpleIntegerProperty(null, "concurrentRecordings", settings.concurrentRecordings);
onlineCheckIntervalInSecs = new SimpleIntegerProperty(null, "onlineCheckIntervalInSecs", settings.onlineCheckIntervalInSecs); onlineCheckIntervalInSecs = new SimpleIntegerProperty(null, "onlineCheckIntervalInSecs", settings.onlineCheckIntervalInSecs);
@ -157,8 +160,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
} }
private void createGui() { private void createGui() {
postProcessingStepPanel = new PostProcessingStepPanel(config); PostProcessingStepPanel postProcessingStepPanel = new PostProcessingStepPanel(config);
variablesHelpButton = createHelpButton("Variables", "http://localhost:5689/docs/PostProcessing.md#variables"); Button variablesHelpButton = createHelpButton("Variables", "http://localhost:5689/docs/PostProcessing.md#variables");
ignoreList = new IgnoreList(sites); ignoreList = new IgnoreList(sites);
List<Category> siteCategories = new ArrayList<>(); List<Category> siteCategories = new ArrayList<>();
for (Site site : sites) { for (Site site : sites) {
@ -191,7 +194,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
Group.of("Settings", Group.of("Settings",
Setting.of("Recordings Directory", recordingsDir), Setting.of("Recordings Directory", recordingsDir),
Setting.of("Directory Structure", directoryStructure), Setting.of("Directory Structure", directoryStructure),
Setting.of("Split recordings after (minutes)", splitAfter).converter(SplitAfterOption.converter()), Setting.of("Split recordings after", splitAfter).converter(SplitAfterOption.converter()).onChange(this::splitValuesChanged),
Setting.of("Split recordings bigger than", splitBiggerThan).converter(SplitBiggerThanOption.converter()).onChange(this::splitValuesChanged),
Setting.of("Restrict Resolution", resolutionRange, "Only record streams with resolution within the given range"), Setting.of("Restrict Resolution", resolutionRange, "Only record streams with resolution within the given range"),
Setting.of("Concurrent Recordings (0 = unlimited)", concurrentRecordings), Setting.of("Concurrent Recordings (0 = unlimited)", concurrentRecordings),
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("Leave space on device (GiB)", leaveSpaceOnDevice, "Stop recording, if the free space on the device gets below this threshold").converter(new GigabytesConverter()),
@ -251,7 +255,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
prefs.getSetting("requireAuthentication").ifPresent(s -> bindEnabledProperty(s, recordLocal)); prefs.getSetting("requireAuthentication").ifPresent(s -> bindEnabledProperty(s, recordLocal));
prefs.getSetting("transportLayerSecurity").ifPresent(s -> bindEnabledProperty(s, recordLocal)); prefs.getSetting("transportLayerSecurity").ifPresent(s -> bindEnabledProperty(s, recordLocal));
prefs.getSetting("recordingsDir").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); prefs.getSetting("recordingsDir").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
prefs.getSetting("splitRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); prefs.getSetting("splitRecordingsAfterSecs").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
prefs.getSetting("splitRecordingsBiggerThanBytes").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
prefs.getSetting("minimumResolution").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); prefs.getSetting("minimumResolution").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
prefs.getSetting("recordingsDirStructure").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); prefs.getSetting("recordingsDirStructure").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
prefs.getSetting("onlineCheckIntervalInSecs").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); prefs.getSetting("onlineCheckIntervalInSecs").ifPresent(s -> bindEnabledProperty(s, recordLocal.not()));
@ -266,6 +271,23 @@ public class SettingsTab extends Tab implements TabSelectionListener {
prefs.getSetting("downloadFilename").ifPresent(s -> bindEnabledProperty(s, recordLocal)); prefs.getSetting("downloadFilename").ifPresent(s -> bindEnabledProperty(s, recordLocal));
postProcessingStepPanel.disableProperty().bind(recordLocal.not()); postProcessingStepPanel.disableProperty().bind(recordLocal.not());
variablesHelpButton.disableProperty().bind(recordLocal); variablesHelpButton.disableProperty().bind(recordLocal);
}
private void splitValuesChanged(ObservableValue<?> value, Object oldV, Object newV) {
boolean splitAfterSet = settings.splitRecordingsAfterSecs > 0;
boolean splitBiggerThanSet = settings.splitRecordingsBiggerThanBytes > 0;
if (splitAfterSet && splitBiggerThanSet) {
settings.splitStrategy = TIME_OR_SIZE;
} else if (splitAfterSet) {
settings.splitStrategy = TIME;
} else if (splitBiggerThanSet) {
settings.splitStrategy = SIZE;
} else {
settings.splitStrategy = DONT;
}
saveConfig();
} }
private Button createHelpButton(String text, String url) { private Button createHelpButton(String text, String url) {
@ -288,7 +310,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<SplitAfterOption> getSplitOptions() { private List<SplitAfterOption> getSplitAfterSecsOptions() {
List<SplitAfterOption> splitOptions = new ArrayList<>(); List<SplitAfterOption> splitOptions = new ArrayList<>();
splitOptions.add(new SplitAfterOption("disabled", 0)); splitOptions.add(new SplitAfterOption("disabled", 0));
if (Config.isDevMode()) { if (Config.isDevMode()) {
@ -304,6 +326,29 @@ public class SettingsTab extends Tab implements TabSelectionListener {
return splitOptions; return splitOptions;
} }
private List<SplitBiggerThanOption> getSplitBiggerThanOptions() {
List<SplitBiggerThanOption> splitOptions = new ArrayList<>();
splitOptions.add(new SplitBiggerThanOption("disabled", 0));
if (Config.isDevMode()) {
splitOptions.add(new SplitBiggerThanOption("10 MiB", 10 * MiB));
splitOptions.add(new SplitBiggerThanOption("20 MiB", 20 * MiB));
}
splitOptions.add(new SplitBiggerThanOption("100 MiB", 100 * MiB));
splitOptions.add(new SplitBiggerThanOption("250 MiB", 250 * MiB));
splitOptions.add(new SplitBiggerThanOption("500 MiB", 500 * MiB));
splitOptions.add(new SplitBiggerThanOption("1 GiB", 1 * GiB));
splitOptions.add(new SplitBiggerThanOption("2 GiB", 2 * GiB));
splitOptions.add(new SplitBiggerThanOption("3 GiB", 3 * GiB));
splitOptions.add(new SplitBiggerThanOption("4 GiB", 4 * GiB));
splitOptions.add(new SplitBiggerThanOption("5 GiB", 5 * GiB));
splitOptions.add(new SplitBiggerThanOption("6 GiB", 6 * GiB));
splitOptions.add(new SplitBiggerThanOption("7 GiB", 7 * GiB));
splitOptions.add(new SplitBiggerThanOption("8 GiB", 8 * GiB));
splitOptions.add(new SplitBiggerThanOption("9 GiB", 9 * GiB));
splitOptions.add(new SplitBiggerThanOption("10 GiB", 10 * GiB));
return splitOptions;
}
private void requireAuthenticationChanged(ObservableValue<?> obs, Boolean oldV, Boolean newV) { // NOSONAR private void requireAuthenticationChanged(ObservableValue<?> obs, Boolean oldV, Boolean newV) { // NOSONAR
boolean requiresAuthentication = newV; boolean requiresAuthentication = newV;
Config.getInstance().getSettings().requireAuthentication = requiresAuthentication; Config.getInstance().getSettings().requireAuthentication = requiresAuthentication;
@ -415,4 +460,60 @@ public class SettingsTab extends Tab implements TabSelectionListener {
}; };
} }
} }
public static class SplitBiggerThanOption {
private String label;
private long value;
public SplitBiggerThanOption(String label, long value) {
super();
this.label = label;
this.value = value;
}
public long getValue() {
return value;
}
@Override
public String toString() {
return label;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (value ^ (value >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SplitBiggerThanOption other = (SplitBiggerThanOption) obj;
if (value != other.value)
return false;
return true;
}
public static ValueConverter converter() {
return new ValueConverter() {
@Override
public Long convertFrom(Object splitBiggerThanOption) {
return ((SplitBiggerThanOption) splitBiggerThanOption).getValue();
}
@Override
public SplitBiggerThanOption convertTo(Object value) {
return new SplitBiggerThanOption(value.toString(), (Long) value);
}
};
}
}
} }

View File

@ -4,6 +4,7 @@ import static java.util.Optional.*;
import ctbrec.StringUtil; import ctbrec.StringUtil;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Control; import javafx.scene.control.Control;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
@ -17,6 +18,7 @@ public class Setting {
private PreferencesStorage preferencesStorage; private PreferencesStorage preferencesStorage;
private boolean needsRestart = false; private boolean needsRestart = false;
private ValueConverter converter; private ValueConverter converter;
private ChangeListener<?> changeListener;
protected Setting(String name, Property<?> property) { protected Setting(String name, Property<?> property) {
this.name = name; this.name = name;
@ -107,4 +109,13 @@ public class Setting {
public ValueConverter getConverter() { public ValueConverter getConverter() {
return converter; return converter;
} }
public Setting onChange(ChangeListener<?> changeListener) {
this.changeListener = changeListener;
return this;
}
public ChangeListener<?> getChangeListener() {
return changeListener;
}
} }