Merge branch 'master' into mpegts-streamer
This commit is contained in:
commit
1d7dd0d0e8
|
@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Settings.ProxyType;
|
import ctbrec.Settings.ProxyType;
|
||||||
import ctbrec.ui.CookieJarImpl;
|
import ctbrec.ui.CookieJarImpl;
|
||||||
|
import ctbrec.ui.CtbrecApplication;
|
||||||
import ctbrec.ui.HtmlParser;
|
import ctbrec.ui.HtmlParser;
|
||||||
import ctbrec.ui.Launcher;
|
|
||||||
import okhttp3.ConnectionPool;
|
import okhttp3.ConnectionPool;
|
||||||
import okhttp3.Cookie;
|
import okhttp3.Cookie;
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
|
@ -121,7 +121,7 @@ public class HttpClient {
|
||||||
public boolean login() throws IOException {
|
public boolean login() throws IOException {
|
||||||
try {
|
try {
|
||||||
Request login = new Request.Builder()
|
Request login = new Request.Builder()
|
||||||
.url(Launcher.BASE_URI + "/auth/login/")
|
.url(CtbrecApplication.BASE_URI + "/auth/login/")
|
||||||
.build();
|
.build();
|
||||||
Response response = client.newCall(login).execute();
|
Response response = client.newCall(login).execute();
|
||||||
String content = response.body().string();
|
String content = response.body().string();
|
||||||
|
@ -135,8 +135,8 @@ public class HttpClient {
|
||||||
.add("csrfmiddlewaretoken", token)
|
.add("csrfmiddlewaretoken", token)
|
||||||
.build();
|
.build();
|
||||||
login = new Request.Builder()
|
login = new Request.Builder()
|
||||||
.url(Launcher.BASE_URI + "/auth/login/")
|
.url(CtbrecApplication.BASE_URI + "/auth/login/")
|
||||||
.header("Referer", Launcher.BASE_URI + "/auth/login/")
|
.header("Referer", CtbrecApplication.BASE_URI + "/auth/login/")
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ctbrec;
|
package ctbrec;
|
||||||
|
|
||||||
import static ctbrec.ui.Launcher.BASE_URI;
|
import static ctbrec.ui.CtbrecApplication.BASE_URI;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -0,0 +1,268 @@
|
||||||
|
package ctbrec.ui;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.squareup.moshi.JsonAdapter;
|
||||||
|
import com.squareup.moshi.Moshi;
|
||||||
|
import com.squareup.moshi.Types;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
|
import ctbrec.HttpClient;
|
||||||
|
import ctbrec.Version;
|
||||||
|
import ctbrec.recorder.LocalRecorder;
|
||||||
|
import ctbrec.recorder.Recorder;
|
||||||
|
import ctbrec.recorder.RemoteRecorder;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.application.HostServices;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Tab;
|
||||||
|
import javafx.scene.control.TabPane;
|
||||||
|
import javafx.scene.control.TabPane.TabClosingPolicy;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class CtbrecApplication extends Application {
|
||||||
|
|
||||||
|
static final transient Logger LOG = LoggerFactory.getLogger(CtbrecApplication.class);
|
||||||
|
public static final String BASE_URI = "https://chaturbate.com";
|
||||||
|
|
||||||
|
private Config config;
|
||||||
|
private Recorder recorder;
|
||||||
|
private HttpClient client;
|
||||||
|
static HostServices hostServices;
|
||||||
|
private SettingsTab settingsTab;
|
||||||
|
private TabPane tabPane = new TabPane();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
loadConfig();
|
||||||
|
hostServices = getHostServices();
|
||||||
|
client = HttpClient.getInstance();
|
||||||
|
createRecorder();
|
||||||
|
doInitialLogin();
|
||||||
|
createGui(primaryStage);
|
||||||
|
checkForUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createGui(Stage primaryStage) throws IOException {
|
||||||
|
LOG.debug("Creating GUI");
|
||||||
|
primaryStage.setTitle("CTB Recorder " + getVersion());
|
||||||
|
InputStream icon = getClass().getResourceAsStream("/icon.png");
|
||||||
|
primaryStage.getIcons().add(new Image(icon));
|
||||||
|
|
||||||
|
tabPane = new TabPane();
|
||||||
|
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Tab> ov, Tab from, Tab to) {
|
||||||
|
if(from != null && from instanceof TabSelectionListener) {
|
||||||
|
((TabSelectionListener) from).deselected();
|
||||||
|
}
|
||||||
|
if(to != null && to instanceof TabSelectionListener) {
|
||||||
|
((TabSelectionListener) to).selected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tabPane.setTabClosingPolicy(TabClosingPolicy.SELECTED_TAB);
|
||||||
|
tabPane.getTabs().add(createTab("Featured", BASE_URI + "/"));
|
||||||
|
tabPane.getTabs().add(createTab("Female", BASE_URI + "/female-cams/"));
|
||||||
|
tabPane.getTabs().add(createTab("Male", BASE_URI + "/male-cams/"));
|
||||||
|
tabPane.getTabs().add(createTab("Couples", BASE_URI + "/couple-cams/"));
|
||||||
|
tabPane.getTabs().add(createTab("Trans", BASE_URI + "/trans-cams/"));
|
||||||
|
FollowedTab tab = new FollowedTab("Followed", BASE_URI + "/followed-cams/");
|
||||||
|
tab.setRecorder(recorder);
|
||||||
|
tabPane.getTabs().add(tab);
|
||||||
|
RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder);
|
||||||
|
tabPane.getTabs().add(modelsTab);
|
||||||
|
RecordingsTab recordingsTab = new RecordingsTab("Recordings", recorder, config);
|
||||||
|
tabPane.getTabs().add(recordingsTab);
|
||||||
|
settingsTab = new SettingsTab();
|
||||||
|
tabPane.getTabs().add(settingsTab);
|
||||||
|
tabPane.getTabs().add(new DonateTabFx());
|
||||||
|
|
||||||
|
int windowWidth = Config.getInstance().getSettings().windowWidth;
|
||||||
|
int windowHeight = Config.getInstance().getSettings().windowHeight;
|
||||||
|
primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight));
|
||||||
|
primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue());
|
||||||
|
primaryStage.getScene().heightProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowHeight = newVal.intValue());
|
||||||
|
primaryStage.setMaximized(Config.getInstance().getSettings().windowMaximized);
|
||||||
|
primaryStage.maximizedProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowMaximized = newVal.booleanValue());
|
||||||
|
primaryStage.setX(Config.getInstance().getSettings().windowX);
|
||||||
|
primaryStage.setY(Config.getInstance().getSettings().windowY);
|
||||||
|
primaryStage.xProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowX = newVal.intValue());
|
||||||
|
primaryStage.yProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowY = newVal.intValue());
|
||||||
|
primaryStage.show();
|
||||||
|
primaryStage.setOnCloseRequest((e) -> {
|
||||||
|
e.consume();
|
||||||
|
Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION);
|
||||||
|
shutdownInfo.setTitle("Shutdown");
|
||||||
|
shutdownInfo.setContentText("Shutting down. Please wait a few seconds...");
|
||||||
|
shutdownInfo.show();
|
||||||
|
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
settingsTab.saveConfig();
|
||||||
|
recorder.shutdown();
|
||||||
|
client.shutdown();
|
||||||
|
try {
|
||||||
|
Config.getInstance().save();
|
||||||
|
LOG.info("Shutdown complete. Goodbye!");
|
||||||
|
Platform.exit();
|
||||||
|
// This is needed, because OkHttp?! seems to block the shutdown with its writer threads. They are not daemon threads :(
|
||||||
|
System.exit(0);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("Error saving settings");
|
||||||
|
alert.setContentText("Couldn't save settings: " + e1.getLocalizedMessage());
|
||||||
|
alert.showAndWait();
|
||||||
|
System.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doInitialLogin() {
|
||||||
|
if(config.getSettings().username != null && !config.getSettings().username.isEmpty()) {
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(!Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||||
|
try {
|
||||||
|
client.login();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
LOG.warn("Initial login failed" , e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createRecorder() {
|
||||||
|
if(config.getSettings().localRecording) {
|
||||||
|
recorder = new LocalRecorder(config);
|
||||||
|
} else {
|
||||||
|
recorder = new RemoteRecorder(config, client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
try {
|
||||||
|
Config.init();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("Whoopsie");
|
||||||
|
alert.setContentText("Couldn't load settings.");
|
||||||
|
alert.showAndWait();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
config = Config.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab createTab(String title, String url) {
|
||||||
|
ThumbOverviewTab tab = new ThumbOverviewTab(title, url, false);
|
||||||
|
tab.setRecorder(recorder);
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForUpdates() {
|
||||||
|
Thread updateCheck = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
String url = "https://api.github.com/repos/0xboobface/ctbrec/releases";
|
||||||
|
Request request = new Request.Builder().url(url).build();
|
||||||
|
Response response = client.execute(request);
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
Moshi moshi = new Moshi.Builder().build();
|
||||||
|
Type type = Types.newParameterizedType(List.class, Release.class);
|
||||||
|
JsonAdapter<List<Release>> adapter = moshi.adapter(type);
|
||||||
|
List<Release> releases = adapter.fromJson(response.body().source());
|
||||||
|
Release latest = releases.get(0);
|
||||||
|
Version latestVersion = latest.getVersion();
|
||||||
|
Version ctbrecVersion = getVersion();
|
||||||
|
if(latestVersion.compareTo(ctbrecVersion) > 0) {
|
||||||
|
LOG.debug("Update available {} < {}", ctbrecVersion, latestVersion);
|
||||||
|
Platform.runLater(() -> tabPane.getTabs().add(new UpdateTab(latest)));
|
||||||
|
} else {
|
||||||
|
LOG.debug("ctbrec is up-to-date {}", ctbrecVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("Update check failed {}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
updateCheck.setName("Update Check");
|
||||||
|
updateCheck.setDaemon(true);
|
||||||
|
updateCheck.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Version getVersion() throws IOException {
|
||||||
|
if(Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||||
|
return Version.of("0.0.0-DEV");
|
||||||
|
} else {
|
||||||
|
try(InputStream is = getClass().getClassLoader().getResourceAsStream("version")) {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
String versionString = reader.readLine();
|
||||||
|
Version version = Version.of(versionString);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Release {
|
||||||
|
private String name;
|
||||||
|
private String tag_name;
|
||||||
|
private String html_url;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTagName() {
|
||||||
|
return tag_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTagName(String tagName) {
|
||||||
|
this.tag_name = tagName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHtmlUrl() {
|
||||||
|
return html_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHtmlUrl(String htmlUrl) {
|
||||||
|
this.html_url = htmlUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version getVersion() {
|
||||||
|
return Version.of(tag_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package ctbrec.ui;
|
||||||
|
|
||||||
|
import java.awt.Desktop;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
|
||||||
|
public class DesktopIntergation {
|
||||||
|
|
||||||
|
private static final transient Logger LOG = LoggerFactory.getLogger(DesktopIntergation.class);
|
||||||
|
|
||||||
|
public static void open(String uri) {
|
||||||
|
try {
|
||||||
|
CtbrecApplication.hostServices.showDocument(uri);
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Couldn't open URL with host services {}", uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// opening with HostServices failed, now try Desktop
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().browse(new URI(uri));
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Couldn't open URL with Desktop {}", uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// try external helpers
|
||||||
|
String[] externalHelpers = {"kde-open5", "kde-open", "gnome-open", "xdg-open"};
|
||||||
|
Runtime rt = Runtime.getRuntime();
|
||||||
|
for (String helper : externalHelpers) {
|
||||||
|
try {
|
||||||
|
rt.exec(helper + " " + uri);
|
||||||
|
return;
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.debug("Couldn't open URL with {} {}", helper, uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// all attempts failed, show a dialog with URL at least
|
||||||
|
Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
|
shutdownInfo.setTitle("Open URL");
|
||||||
|
shutdownInfo.setContentText("Couldn't open URL");
|
||||||
|
BorderPane pane = new BorderPane();
|
||||||
|
pane.setTop(new Label());
|
||||||
|
TextField urlField = new TextField(uri);
|
||||||
|
urlField.setPadding(new Insets(10));
|
||||||
|
urlField.setEditable(false);
|
||||||
|
pane.setCenter(urlField);
|
||||||
|
shutdownInfo.getDialogPane().setExpandableContent(pane);
|
||||||
|
shutdownInfo.getDialogPane().setExpanded(true);
|
||||||
|
shutdownInfo.show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ public class DonateTabFx extends Tab {
|
||||||
|
|
||||||
ImageView coffeeImage = new ImageView(getClass().getResource("/html/buymeacoffee-fancy.png").toString());
|
ImageView coffeeImage = new ImageView(getClass().getResource("/html/buymeacoffee-fancy.png").toString());
|
||||||
Button coffeeButton = new Button("Buy me a coffee");
|
Button coffeeButton = new Button("Buy me a coffee");
|
||||||
coffeeButton.setOnMouseClicked((e) -> { Launcher.open("https://www.buymeacoffee.com/0xboobface"); });
|
coffeeButton.setOnMouseClicked((e) -> { DesktopIntergation.open("https://www.buymeacoffee.com/0xboobface"); });
|
||||||
VBox buyCoffeeBox = new VBox(5);
|
VBox buyCoffeeBox = new VBox(5);
|
||||||
buyCoffeeBox.setAlignment(Pos.TOP_CENTER);
|
buyCoffeeBox.setAlignment(Pos.TOP_CENTER);
|
||||||
buyCoffeeBox.getChildren().addAll(coffeeImage, coffeeButton);
|
buyCoffeeBox.getChildren().addAll(coffeeImage, coffeeButton);
|
||||||
|
|
|
@ -1,272 +1,27 @@
|
||||||
package ctbrec.ui;
|
package ctbrec.ui;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.squareup.moshi.JsonAdapter;
|
public class Launcher {
|
||||||
import com.squareup.moshi.Moshi;
|
|
||||||
import com.squareup.moshi.Types;
|
|
||||||
|
|
||||||
import ctbrec.Config;
|
|
||||||
import ctbrec.HttpClient;
|
|
||||||
import ctbrec.Version;
|
|
||||||
import ctbrec.recorder.LocalRecorder;
|
|
||||||
import ctbrec.recorder.Recorder;
|
|
||||||
import ctbrec.recorder.RemoteRecorder;
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.application.HostServices;
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import javafx.scene.control.Tab;
|
|
||||||
import javafx.scene.control.TabPane;
|
|
||||||
import javafx.scene.control.TabPane.TabClosingPolicy;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
|
|
||||||
public class Launcher extends Application {
|
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(Launcher.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(Launcher.class);
|
||||||
public static final String BASE_URI = "https://chaturbate.com";
|
|
||||||
|
|
||||||
private Config config;
|
|
||||||
private Recorder recorder;
|
|
||||||
private HttpClient client;
|
|
||||||
private static HostServices hostServices;
|
|
||||||
private SettingsTab settingsTab;
|
|
||||||
private TabPane tabPane = new TabPane();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) throws Exception {
|
|
||||||
loadConfig();
|
|
||||||
hostServices = getHostServices();
|
|
||||||
client = HttpClient.getInstance();
|
|
||||||
createRecorder();
|
|
||||||
doInitialLogin();
|
|
||||||
createGui(primaryStage);
|
|
||||||
checkForUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createGui(Stage primaryStage) throws IOException {
|
|
||||||
LOG.debug("Creating GUI");
|
|
||||||
primaryStage.setTitle("CTB Recorder " + getVersion());
|
|
||||||
InputStream icon = getClass().getResourceAsStream("/icon.png");
|
|
||||||
primaryStage.getIcons().add(new Image(icon));
|
|
||||||
|
|
||||||
tabPane = new TabPane();
|
|
||||||
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
|
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends Tab> ov, Tab from, Tab to) {
|
|
||||||
if(from != null && from instanceof TabSelectionListener) {
|
|
||||||
((TabSelectionListener) from).deselected();
|
|
||||||
}
|
|
||||||
if(to != null && to instanceof TabSelectionListener) {
|
|
||||||
((TabSelectionListener) to).selected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
tabPane.setTabClosingPolicy(TabClosingPolicy.SELECTED_TAB);
|
|
||||||
tabPane.getTabs().add(createTab("Featured", BASE_URI + "/"));
|
|
||||||
tabPane.getTabs().add(createTab("Female", BASE_URI + "/female-cams/"));
|
|
||||||
tabPane.getTabs().add(createTab("Male", BASE_URI + "/male-cams/"));
|
|
||||||
tabPane.getTabs().add(createTab("Couples", BASE_URI + "/couple-cams/"));
|
|
||||||
tabPane.getTabs().add(createTab("Trans", BASE_URI + "/trans-cams/"));
|
|
||||||
FollowedTab tab = new FollowedTab("Followed", BASE_URI + "/followed-cams/");
|
|
||||||
tab.setRecorder(recorder);
|
|
||||||
tabPane.getTabs().add(tab);
|
|
||||||
RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder);
|
|
||||||
tabPane.getTabs().add(modelsTab);
|
|
||||||
RecordingsTab recordingsTab = new RecordingsTab("Recordings", recorder, config);
|
|
||||||
tabPane.getTabs().add(recordingsTab);
|
|
||||||
settingsTab = new SettingsTab();
|
|
||||||
tabPane.getTabs().add(settingsTab);
|
|
||||||
tabPane.getTabs().add(new DonateTabFx());
|
|
||||||
|
|
||||||
int windowWidth = Config.getInstance().getSettings().windowWidth;
|
|
||||||
int windowHeight = Config.getInstance().getSettings().windowHeight;
|
|
||||||
primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight));
|
|
||||||
primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue());
|
|
||||||
primaryStage.getScene().heightProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowHeight = newVal.intValue());
|
|
||||||
primaryStage.setMaximized(Config.getInstance().getSettings().windowMaximized);
|
|
||||||
primaryStage.maximizedProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowMaximized = newVal.booleanValue());
|
|
||||||
primaryStage.setX(Config.getInstance().getSettings().windowX);
|
|
||||||
primaryStage.setY(Config.getInstance().getSettings().windowY);
|
|
||||||
primaryStage.xProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowX = newVal.intValue());
|
|
||||||
primaryStage.yProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowY = newVal.intValue());
|
|
||||||
primaryStage.show();
|
|
||||||
primaryStage.setOnCloseRequest((e) -> {
|
|
||||||
e.consume();
|
|
||||||
Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION);
|
|
||||||
shutdownInfo.setTitle("Shutdown");
|
|
||||||
shutdownInfo.setContentText("Shutting down. Please wait a few seconds...");
|
|
||||||
shutdownInfo.show();
|
|
||||||
|
|
||||||
new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
settingsTab.saveConfig();
|
|
||||||
recorder.shutdown();
|
|
||||||
client.shutdown();
|
|
||||||
try {
|
|
||||||
Config.getInstance().save();
|
|
||||||
LOG.info("Shutdown complete. Goodbye!");
|
|
||||||
Platform.exit();
|
|
||||||
// This is needed, because OkHttp?! seems to block the shutdown with its writer threads. They are not daemon threads :(
|
|
||||||
System.exit(0);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle("Error saving settings");
|
|
||||||
alert.setContentText("Couldn't save settings: " + e1.getLocalizedMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
System.exit(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doInitialLogin() {
|
|
||||||
if(config.getSettings().username != null && !config.getSettings().username.isEmpty()) {
|
|
||||||
new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(!Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
|
||||||
try {
|
|
||||||
client.login();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
LOG.warn("Initial login failed" , e1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createRecorder() {
|
|
||||||
if(config.getSettings().localRecording) {
|
|
||||||
recorder = new LocalRecorder(config);
|
|
||||||
} else {
|
|
||||||
recorder = new RemoteRecorder(config, client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadConfig() {
|
|
||||||
try {
|
|
||||||
Config.init();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle("Whoopsie");
|
|
||||||
alert.setContentText("Couldn't load settings.");
|
|
||||||
alert.showAndWait();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
config = Config.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tab createTab(String title, String url) {
|
|
||||||
ThumbOverviewTab tab = new ThumbOverviewTab(title, url, false);
|
|
||||||
tab.setRecorder(recorder);
|
|
||||||
return tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void open(String uri) {
|
|
||||||
hostServices.showDocument(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
String jvmName = System.getProperty("java.vm.name");
|
||||||
}
|
if (jvmName.startsWith("OpenJDK")) {
|
||||||
|
// check for OpenJFX
|
||||||
private void checkForUpdates() {
|
|
||||||
Thread updateCheck = new Thread(() -> {
|
|
||||||
try {
|
try {
|
||||||
String url = "https://api.github.com/repos/0xboobface/ctbrec/releases";
|
Class.forName("javafx.application.Application");
|
||||||
Request request = new Request.Builder().url(url).build();
|
CtbrecApplication.main(args);
|
||||||
Response response = client.execute(request);
|
} catch (ClassNotFoundException e) {
|
||||||
if(response.isSuccessful()) {
|
LOG.error("You are running ctbrec with OpenJDK, but OpenJFX can not be found.\n"
|
||||||
Moshi moshi = new Moshi.Builder().build();
|
+ "Please either install OpenJFX or use the Oracle JRE, which you can download at\n"
|
||||||
Type type = Types.newParameterizedType(List.class, Release.class);
|
+ "http://www.oracle.com/technetwork/java/javase/downloads/index.html");
|
||||||
JsonAdapter<List<Release>> adapter = moshi.adapter(type);
|
System.exit(1);
|
||||||
List<Release> releases = adapter.fromJson(response.body().source());
|
|
||||||
Release latest = releases.get(0);
|
|
||||||
Version latestVersion = latest.getVersion();
|
|
||||||
Version ctbrecVersion = getVersion();
|
|
||||||
if(latestVersion.compareTo(ctbrecVersion) > 0) {
|
|
||||||
LOG.debug("Update available {} < {}", ctbrecVersion, latestVersion);
|
|
||||||
Platform.runLater(() -> tabPane.getTabs().add(new UpdateTab(latest)));
|
|
||||||
} else {
|
|
||||||
LOG.debug("ctbrec is up-to-date {}", ctbrecVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
response.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.warn("Update check failed {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
updateCheck.setName("Update Check");
|
|
||||||
updateCheck.setDaemon(true);
|
|
||||||
updateCheck.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Version getVersion() throws IOException {
|
|
||||||
if(Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
|
||||||
return Version.of("0.0.0-DEV");
|
|
||||||
} else {
|
} else {
|
||||||
try(InputStream is = getClass().getClassLoader().getResourceAsStream("version")) {
|
CtbrecApplication.main(args);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
||||||
String versionString = reader.readLine();
|
|
||||||
Version version = Version.of(versionString);
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Release {
|
|
||||||
private String name;
|
|
||||||
private String tag_name;
|
|
||||||
private String html_url;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTagName() {
|
|
||||||
return tag_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTagName(String tagName) {
|
|
||||||
this.tag_name = tagName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHtmlUrl() {
|
|
||||||
return html_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHtmlUrl(String htmlUrl) {
|
|
||||||
this.html_url = htmlUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return Version.of(tag_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
||||||
});
|
});
|
||||||
|
|
||||||
MenuItem openInBrowser = new MenuItem("Open in Browser");
|
MenuItem openInBrowser = new MenuItem("Open in Browser");
|
||||||
openInBrowser.setOnAction((e) -> Launcher.open(table.getSelectionModel().getSelectedItem().getUrl()));
|
openInBrowser.setOnAction((e) -> DesktopIntergation.open(table.getSelectionModel().getSelectedItem().getUrl()));
|
||||||
MenuItem openInPlayer = new MenuItem("Open in Player");
|
MenuItem openInPlayer = new MenuItem("Open in Player");
|
||||||
openInPlayer.setOnAction((e) -> Player.play(table.getSelectionModel().getSelectedItem().getUrl()));
|
openInPlayer.setOnAction((e) -> Player.play(table.getSelectionModel().getSelectedItem().getUrl()));
|
||||||
MenuItem switchStreamSource = new MenuItem("Switch resolution");
|
MenuItem switchStreamSource = new MenuItem("Switch resolution");
|
||||||
|
|
|
@ -420,9 +420,9 @@ public class ThumbCell extends StackPane {
|
||||||
|
|
||||||
String url = null;
|
String url = null;
|
||||||
if(follow) {
|
if(follow) {
|
||||||
url = Launcher.BASE_URI + "/follow/follow/" + model.getName() + "/";
|
url = CtbrecApplication.BASE_URI + "/follow/follow/" + model.getName() + "/";
|
||||||
} else {
|
} else {
|
||||||
url = Launcher.BASE_URI + "/follow/unfollow/" + model.getName() + "/";
|
url = CtbrecApplication.BASE_URI + "/follow/unfollow/" + model.getName() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody body = RequestBody.create(null, new byte[0]);
|
RequestBody body = RequestBody.create(null, new byte[0]);
|
||||||
|
|
|
@ -3,7 +3,7 @@ package ctbrec.ui;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.ui.Launcher.Release;
|
import ctbrec.ui.CtbrecApplication.Release;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
@ -23,7 +23,7 @@ public class UpdateTab extends Tab {
|
||||||
VBox vbox = new VBox(10);
|
VBox vbox = new VBox(10);
|
||||||
vbox.getChildren().add(new Label("New Version available " + latest.getVersion()));
|
vbox.getChildren().add(new Label("New Version available " + latest.getVersion()));
|
||||||
Button button = new Button("Download");
|
Button button = new Button("Download");
|
||||||
button.setOnAction((e) -> Launcher.open(latest.getHtmlUrl()));
|
button.setOnAction((e) -> DesktopIntergation.open(latest.getHtmlUrl()));
|
||||||
vbox.getChildren().add(button);
|
vbox.getChildren().add(button);
|
||||||
vbox.setAlignment(Pos.CENTER);
|
vbox.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue