forked from j62/ctbrec
1
0
Fork 0

Improve account existance check for chaturbate

This commit is contained in:
0xb00bface 2021-08-08 18:58:42 +02:00
parent a8f4f65e30
commit e3f42ffc1c
1 changed files with 21 additions and 0 deletions

View File

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