diff --git a/CHANGELOG.md b/CHANGELOG.md index c77574fa..af417890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +3.10.9 +======================== +* Added button to the "Recording" tab to go over all model URLs and check, if + the account still exists + 3.10.8 ======================== * Fixed Stripchat recordings. For some models the recording didn't start, diff --git a/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java b/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java new file mode 100644 index 00000000..6dfd9c4b --- /dev/null +++ b/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java @@ -0,0 +1,82 @@ +package ctbrec.ui.action; + +import static ctbrec.io.HttpConstants.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ctbrec.Config; +import ctbrec.Model; +import ctbrec.recorder.Recorder; +import ctbrec.ui.controls.Dialogs; +import javafx.application.Platform; +import javafx.scene.control.Button; +import okhttp3.Request; +import okhttp3.Response; + +public class CheckModelAccountAction { + private static final Logger LOG = LoggerFactory.getLogger(CheckModelAccountAction.class); + + private Button b; + + private Recorder recorder; + + public CheckModelAccountAction(Button b, Recorder recorder) { + this.b = b; + this.recorder = recorder; + + } + + public void execute() { + String buttonText = b.getText(); + b.setDisable(true); + Runnable checker = (() -> { + List deletedAccounts = new ArrayList<>(); + try { + List models = recorder.getModels(); + int total = models.size(); + for (int i = 0; i < total; i++) { + final int counter = i+1; + Platform.runLater(() -> b.setText(buttonText + ' ' + counter + '/' + total)); + Model modelToCheck = models.get(i); + Request req = new Request.Builder() + .url(modelToCheck.getUrl()) + .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) + .build(); + try(Response response = modelToCheck.getSite().getHttpClient().execute(req)) { + if(!response.isSuccessful() && response.code() == 404) { + deletedAccounts.add(modelToCheck); + } + } catch (IOException e) { + LOG.warn("Couldn't check, if model account still exists", e); + } + } + } finally { + Platform.runLater(() -> { + b.setDisable(false); + b.setText(buttonText); + StringBuilder sb = new StringBuilder(); + for (Model deletedModel : deletedAccounts) { + String name = deletedModel.getDisplayName() + " ".repeat(30); + name = name.substring(0, 30); + sb.append(name) + .append(' ').append('(') + .append(deletedModel.getUrl()) + .append(')').append('\n'); + } + + boolean remove = Dialogs.showConfirmDialog("Deleted Accounts", sb.toString(), + "The following accounts seem to have been deleted. Do you want to remove them?", b.getScene()); + if (remove) { + new StopRecordingAction(b, deletedAccounts, recorder).execute(); + } + }); + } + }); + new Thread(checker).start(); + } +} diff --git a/client/src/main/java/ctbrec/ui/tabs/RecordedModelsTab.java b/client/src/main/java/ctbrec/ui/tabs/RecordedModelsTab.java index c432ea3a..90eba303 100644 --- a/client/src/main/java/ctbrec/ui/tabs/RecordedModelsTab.java +++ b/client/src/main/java/ctbrec/ui/tabs/RecordedModelsTab.java @@ -38,6 +38,7 @@ import ctbrec.ui.DesktopIntegration; import ctbrec.ui.JavaFxModel; import ctbrec.ui.PreviewPopupHandler; import ctbrec.ui.StreamSourceSelectionDialog; +import ctbrec.ui.action.CheckModelAccountAction; import ctbrec.ui.action.EditNotesAction; import ctbrec.ui.action.FollowAction; import ctbrec.ui.action.OpenRecordingsDir; @@ -125,6 +126,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { Button pauseAll = new Button("Pause All"); Button resumeAll = new Button("Resume All"); ToggleButton toggleRecording = new ToggleButton("Pause Recording"); + Button checkModelAccountExistance = new Button("Check URLs"); TextField filter; public RecordedModelsTab(String title, Recorder recorder, List sites) { @@ -279,7 +281,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { BorderPane.setMargin(addModelBox, new Insets(5)); addModelButton.setOnAction(this::addModel); addModelButton.setPadding(new Insets(5)); - addModelBox.getChildren().addAll(modelLabel, model, addModelButton, pauseAll, resumeAll, toggleRecording); + addModelBox.getChildren().addAll(modelLabel, model, addModelButton, pauseAll, resumeAll, toggleRecording, checkModelAccountExistance); HBox.setMargin(pauseAll, new Insets(0, 0, 0, 20)); pauseAll.setOnAction(this::pauseAll); resumeAll.setOnAction(this::resumeAll); @@ -288,6 +290,10 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { toggleRecording.setPadding(new Insets(5)); toggleRecording.setOnAction(this::toggleRecording); HBox.setMargin(toggleRecording, new Insets(0, 0, 0, 20)); + checkModelAccountExistance.setPadding(new Insets(5)); + checkModelAccountExistance.setTooltip(new Tooltip("Go over all model URLs and check, if the account still exists")); + HBox.setMargin(checkModelAccountExistance, new Insets(0, 0, 0, 20)); + checkModelAccountExistance.setOnAction(evt -> new CheckModelAccountAction(checkModelAccountExistance, recorder).execute()); HBox filterContainer = new HBox(); filterContainer.setSpacing(0);