Add button to check model URLs

Add button and action, which goes over all model URLs and checks, if the
account still exists.
This commit is contained in:
0xb00bface 2020-12-13 16:59:10 +01:00
parent d50ca02374
commit 43d93e3590
3 changed files with 94 additions and 1 deletions

View File

@ -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,

View File

@ -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<Model> deletedAccounts = new ArrayList<>();
try {
List<Model> 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();
}
}

View File

@ -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<Site> 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);