Improve account existance check for chaturbate
This commit is contained in:
parent
a8f4f65e30
commit
e3f42ffc1c
|
@ -12,6 +12,7 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -339,4 +340,24 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
Request req = new Request.Builder() // @formatter:off
|
||||
.url(getUrl())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.build(); // @formatter:on
|
||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||
if (!response.isSuccessful() && response.code() == 404) {
|
||||
return false;
|
||||
} else {
|
||||
String body = response.body().string();
|
||||
boolean banned = body.contains("This room has been banned");
|
||||
boolean deleted = body.contains("This account has been deleted");
|
||||
boolean redirectedToRoot = Objects.equals("/", response.request().url().encodedPath());
|
||||
return !(banned || deleted || redirectedToRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue