Add Model.exists to check, if a model account exists
This commit is contained in:
parent
fb58be47bb
commit
c9cd6e825d
|
@ -307,4 +307,9 @@ public class JavaFxModel implements Model {
|
|||
public void setRecordUntilSubsequentAction(SubsequentAction action) {
|
||||
delegate.setRecordUntilSubsequentAction(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
return delegate.exists();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ctbrec.ui.action;
|
||||
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -9,14 +7,11 @@ 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);
|
||||
|
@ -43,12 +38,8 @@ public class CheckModelAccountAction {
|
|||
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) {
|
||||
try {
|
||||
if (!modelToCheck.exists()) {
|
||||
deletedAccounts.add(modelToCheck);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ctbrec;
|
||||
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
@ -17,6 +19,8 @@ import ctbrec.recorder.download.HttpHeaderFactoryImpl;
|
|||
import ctbrec.recorder.download.hls.HlsDownload;
|
||||
import ctbrec.recorder.download.hls.MergedFfmpegHlsDownload;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public abstract class AbstractModel implements Model {
|
||||
|
||||
|
@ -270,4 +274,18 @@ public abstract class AbstractModel implements Model {
|
|||
fac.setSegmentHeaders(new HashMap<>());
|
||||
return fac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
Request req = new Request.Builder() // @formatter:off
|
||||
.url(getUrl())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.build(); // @formatter:on
|
||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||
if (!response.isSuccessful() && response.code() == 404) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,4 +136,11 @@ public interface Model extends Comparable<Model>, Serializable {
|
|||
public SubsequentAction getRecordUntilSubsequentAction();
|
||||
public void setRecordUntilSubsequentAction(SubsequentAction action);
|
||||
|
||||
/**
|
||||
* Check, if this model account exists
|
||||
* @return true, if it exists, false otherwise
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean exists() throws IOException;
|
||||
|
||||
}
|
Loading…
Reference in New Issue