From ff9ff8f40f08ce9eacb18002668c9ba401154788 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Mon, 16 Mar 2020 20:51:09 +0100 Subject: [PATCH] Add dialog to specify media player params in the settings --- CHANGELOG.md | 2 ++ client/src/main/java/ctbrec/ui/Player.java | 17 +++++++++-- .../ui/controls/AbstractFileSelectionBox.java | 30 ++++++------------- .../main/java/ctbrec/ui/controls/Dialogs.java | 4 ++- .../ctbrec/ui/settings/ColorSettingsPane.java | 18 ++++------- .../java/ctbrec/ui/settings/SettingsTab.java | 24 +++++++++++---- common/src/main/java/ctbrec/Settings.java | 5 ++-- 7 files changed, 56 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc4bf0af..3cc3c753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ 3.4.1 ======================== * Filter terms can now be negated by prepending them with a "!" +* Added pinning for recordings. Pinned recordings cannot be deleted +* Added possibility to specify media player parameters 3.4.0 ======================== diff --git a/client/src/main/java/ctbrec/ui/Player.java b/client/src/main/java/ctbrec/ui/Player.java index 47c1accc..a732dc72 100644 --- a/client/src/main/java/ctbrec/ui/Player.java +++ b/client/src/main/java/ctbrec/ui/Player.java @@ -127,14 +127,15 @@ public class Player { try { if (cfg.getSettings().localRecording && rec != null) { File file = new File(cfg.getSettings().recordingsDir, rec.getPath()); - String[] args = new String[] { cfg.getSettings().mediaPlayer, file.getName() }; - playerProcess = rt.exec(args, OS.getEnvironment(), file.getParentFile()); + String[] cmdline = createCmdline(file.getName()); + playerProcess = rt.exec(cmdline, OS.getEnvironment(), file.getParentFile()); } else { if (rec != null) { url = getRemoteRecordingUrl(rec, cfg); } LOG.debug("Playing {}", url); - playerProcess = rt.exec(cfg.getSettings().mediaPlayer + " " + url); + String[] cmdline = createCmdline(url); + playerProcess = rt.exec(cmdline); } // create threads, which read stdout and stderr of the player process. these are needed, @@ -159,6 +160,16 @@ public class Player { running = false; } + private String[] createCmdline(String mediaSource) { + Config cfg = Config.getInstance(); + String[] playerArgs = cfg.getSettings().mediaPlayerParams.trim().split(" "); + String[] cmdline = new String[playerArgs.length + 2]; + cmdline[0] = cfg.getSettings().mediaPlayer; + cmdline[cmdline.length - 1] = mediaSource; + System.arraycopy(playerArgs, 0, cmdline, 1, playerArgs.length); + return cmdline; + } + private String getRemoteRecordingUrl(Recording rec, Config cfg) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { String hlsBase = Config.getInstance().getServerUrl() + "/hls"; diff --git a/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java b/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java index b76e34d6..5fc0ce2c 100644 --- a/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java +++ b/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java @@ -28,19 +28,9 @@ import javafx.scene.paint.Color; import javafx.stage.FileChooser; public abstract class AbstractFileSelectionBox extends HBox { - private static final transient Logger LOG = LoggerFactory.getLogger(AbstractFileSelectionBox.class); - // private ObjectProperty fileProperty = new ObjectPropertyBase() { - // @Override - // public Object getBean() { - // return null; - // } - // - // @Override - // public String getName() { - // return "file"; - // } - // }; + private static final Logger LOG = LoggerFactory.getLogger(AbstractFileSelectionBox.class); + private StringProperty fileProperty = new SimpleStringProperty(); protected TextField fileInput; protected boolean allowEmptyValue = false; @@ -51,7 +41,7 @@ public abstract class AbstractFileSelectionBox extends HBox { fileInput = new TextField(); fileInput.textProperty().addListener(textListener()); fileInput.focusedProperty().addListener((obs, o, n) -> { - if(!n) { + if (!n.booleanValue()) { validationError.hide(); } }); @@ -62,7 +52,7 @@ public abstract class AbstractFileSelectionBox extends HBox { HBox.setHgrow(fileInput, Priority.ALWAYS); disabledProperty().addListener((obs, oldV, newV) -> { - if (newV) { + if (newV.booleanValue()) { hideValidationHints(); } else { if (StringUtil.isNotBlank(fileInput.getText())) { @@ -80,7 +70,7 @@ public abstract class AbstractFileSelectionBox extends HBox { private ChangeListener textListener() { return (obs, o, n) -> { String input = fileInput.getText(); - if(StringUtil.isBlank(input) && allowEmptyValue) { + if (StringUtil.isBlank(input) && allowEmptyValue) { fileProperty.set(""); hideValidationHints(); return; @@ -98,7 +88,7 @@ public abstract class AbstractFileSelectionBox extends HBox { validationError.setText(msg); fileInput.setTooltip(validationError); Point2D p = fileInput.localToScreen(fileInput.getTranslateY(), fileInput.getTranslateY()); - if(!validationError.isShowing() && getScene() != null) { + if (!validationError.isShowing() && getScene() != null) { validationError.show(getScene().getWindow(), p.getX(), p.getY() + fileInput.getHeight() + 4); } } else { @@ -114,7 +104,7 @@ public abstract class AbstractFileSelectionBox extends HBox { } protected String validate(File file) { - if(isDisabled()) { + if (isDisabled()) { return null; } @@ -131,16 +121,14 @@ public abstract class AbstractFileSelectionBox extends HBox { private Button createBrowseButton() { Button button = new Button("Select"); - button.setOnAction((e) -> { - choose(); - }); + button.setOnAction(e -> choose()); return button; } protected void choose() { FileChooser chooser = new FileChooser(); File program = chooser.showOpenDialog(null); - if(program != null) { + if (program != null) { try { fileInput.setText(program.getCanonicalPath()); } catch (IOException e1) { diff --git a/client/src/main/java/ctbrec/ui/controls/Dialogs.java b/client/src/main/java/ctbrec/ui/controls/Dialogs.java index dbeea56e..c96ae2c1 100644 --- a/client/src/main/java/ctbrec/ui/controls/Dialogs.java +++ b/client/src/main/java/ctbrec/ui/controls/Dialogs.java @@ -20,6 +20,8 @@ import javafx.stage.Modality; import javafx.stage.Stage; public class Dialogs { + + private Dialogs() {} // TODO reduce calls to this method and use Dialogs.showError(Scene parent, String header, String text, Throwable t) instead public static void showError(String header, String text, Throwable t) { showError(null, header, text, t); @@ -73,7 +75,7 @@ public class Dialogs { grid.add(notes, 0, 0); dialog.getDialogPane().setContent(grid); - Platform.runLater(() -> notes.requestFocus()); + Platform.runLater(notes::requestFocus); dialog.setResultConverter(dialogButton -> { if (dialogButton == ButtonType.OK) { diff --git a/client/src/main/java/ctbrec/ui/settings/ColorSettingsPane.java b/client/src/main/java/ctbrec/ui/settings/ColorSettingsPane.java index 3cb22604..b91765d1 100644 --- a/client/src/main/java/ctbrec/ui/settings/ColorSettingsPane.java +++ b/client/src/main/java/ctbrec/ui/settings/ColorSettingsPane.java @@ -4,10 +4,11 @@ import ctbrec.Config; import javafx.scene.control.Button; import javafx.scene.control.ColorPicker; import javafx.scene.control.Tooltip; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; -public class ColorSettingsPane extends Pane { +public class ColorSettingsPane extends HBox { ColorPicker baseColor = new ColorPicker(); ColorPicker accentColor = new ColorPicker(); @@ -15,14 +16,18 @@ public class ColorSettingsPane extends Pane { Pane foobar = new Pane(); public ColorSettingsPane(SettingsTab settingsTab) { + super(5); getChildren().add(baseColor); getChildren().add(accentColor); getChildren().add(reset); baseColor.setValue(Color.web(Config.getInstance().getSettings().colorBase)); baseColor.setTooltip(new Tooltip("Base Color")); + baseColor.setMaxSize(44, 25); accentColor.setValue(Color.web(Config.getInstance().getSettings().colorAccent)); accentColor.setTooltip(new Tooltip("Accent Color")); + accentColor.setMaxSize(44, 25); + reset.setMaxSize(60, 25); baseColor.setOnAction(evt -> { Config.getInstance().getSettings().colorBase = toWeb(baseColor.getValue()); @@ -63,15 +68,4 @@ public class ColorSettingsPane extends Pane { sb.append(Integer.toHexString(v)); return sb; } - - @Override - protected void layoutChildren() { - baseColor.resize(44, 25); - accentColor.resize(44, 25); - reset.resize(60, 25); - - baseColor.setTranslateX(0); - accentColor.setTranslateX(baseColor.getTranslateX() + baseColor.getWidth() + 10); - reset.setTranslateX(accentColor.getTranslateX() + accentColor.getWidth() + 10); - } } diff --git a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java index 2cb5d97b..7aa8ba94 100644 --- a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +25,7 @@ import com.squareup.moshi.Types; import ctbrec.Config; import ctbrec.Hmac; import ctbrec.Model; +import ctbrec.Settings; import ctbrec.Settings.DirectoryStructure; import ctbrec.StringUtil; import ctbrec.io.ModelJsonAdapter; @@ -554,23 +556,34 @@ public class SettingsTab extends Tab implements TabSelectionListener { } private Node createGeneralPanel() { + Settings settings = Config.getInstance().getSettings(); GridPane layout = createGridLayout(); int row = 0; layout.add(new Label("Player"), 0, row); - ProgramSelectionBox mediaPlayer = new ProgramSelectionBox(Config.getInstance().getSettings().mediaPlayer); + ProgramSelectionBox mediaPlayer = new ProgramSelectionBox(settings.mediaPlayer); mediaPlayer.fileProperty().addListener((obs, o, n) -> { String path = n; - if (!Objects.equals(path, Config.getInstance().getSettings().mediaPlayer)) { - Config.getInstance().getSettings().mediaPlayer = path; + if (!Objects.equals(path, settings.mediaPlayer)) { + settings.mediaPlayer = path; saveConfig(); } }); GridPane.setFillWidth(mediaPlayer, true); GridPane.setHgrow(mediaPlayer, Priority.ALWAYS); GridPane.setMargin(mediaPlayer, new Insets(0, 0, 0, CHECKBOX_MARGIN)); - GridPane.setColumnSpan(mediaPlayer, 3); - layout.add(mediaPlayer, 1, row++); + GridPane.setColumnSpan(mediaPlayer, 2); + layout.add(mediaPlayer, 1, row); + Button mediaPlayerParamsButton = new Button("⚙"); + mediaPlayerParamsButton.setOnAction(e -> { + Optional playerParams = Dialogs.showTextInput(mediaPlayerParamsButton.getScene(), "Media Player Parameters", + "Media Player Start Parameters", settings.mediaPlayerParams); + playerParams.ifPresent(p -> { + settings.mediaPlayerParams = p; + saveConfig(); + }); + }); + layout.add(mediaPlayerParamsButton, 3, row++); Label l = new Label("Allow multiple players"); layout.add(l, 0, row); @@ -581,6 +594,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { }); GridPane.setMargin(l, new Insets(3, 0, 0, 0)); GridPane.setMargin(multiplePlayers, new Insets(CHECKBOX_MARGIN, 0, 0, CHECKBOX_MARGIN)); + GridPane.setHgrow(multiplePlayers, Priority.ALWAYS); layout.add(multiplePlayers, 1, row); l = new Label("Show \"Player Starting\" Message"); diff --git a/common/src/main/java/ctbrec/Settings.java b/common/src/main/java/ctbrec/Settings.java index 2d46c130..50905c68 100644 --- a/common/src/main/java/ctbrec/Settings.java +++ b/common/src/main/java/ctbrec/Settings.java @@ -59,8 +59,8 @@ public class Settings { public int httpSecurePort = 8443; public String httpServer = "localhost"; public int httpTimeout = 10000; - public String httpUserAgent = "Mozilla/5.0 Gecko/20100101 Firefox/62.0"; - public String httpUserAgentMobile = "Mozilla/5.0 (Android 9.0; Mobile; rv:63.0) Gecko/63.0 Firefox/63.0"; + public String httpUserAgent = "Mozilla/5.0 Gecko/20100101 Firefox/73.0"; + public String httpUserAgentMobile = "Mozilla/5.0 (Android 9.0; Mobile; rv:73.0) Gecko/63.0 Firefox/73.0"; public byte[] key = null; public String lastDownloadDir = ""; public String livejasminBaseUrl = "https://www.livejasmin.com"; @@ -71,6 +71,7 @@ public class Settings { public boolean localRecording = true; public int maximumResolution = 0; public String mediaPlayer = "/usr/bin/mpv"; + public String mediaPlayerParams = ""; public String mfcBaseUrl = "https://www.myfreecams.com"; public List mfcDisabledModelsTableColumns = new ArrayList<>(); public boolean mfcIgnoreUpscaled = false;