Handle empty model details more gracefully
The model details request might just return an empty array. Instead of printing out a stacktrace for each online check, we just assume, that the model is offline.
This commit is contained in:
parent
eb3c878b03
commit
e9e6d73e97
|
@ -48,20 +48,24 @@ public class Cam4Model extends AbstractModel {
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
if(ignoreCache || onlineState == null) {
|
if(ignoreCache || onlineState == null) {
|
||||||
loadModelDetails();
|
try {
|
||||||
|
loadModelDetails();
|
||||||
|
} catch (ModelDetailsEmptyException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Objects.equals("NORMAL", onlineState);
|
return Objects.equals("NORMAL", onlineState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadModelDetails() throws IOException {
|
private void loadModelDetails() throws IOException, ModelDetailsEmptyException {
|
||||||
String url = "https://www.cam4.de.com/getBroadcasting?usernames=" + getName();
|
String url = site.getBaseUrl() + "/getBroadcasting?usernames=" + getName();
|
||||||
LOG.debug("Loading model details {}", url);
|
LOG.debug("Loading model details {}", url);
|
||||||
Request req = new Request.Builder().url(url).build();
|
Request req = new Request.Builder().url(url).build();
|
||||||
Response response = site.getHttpClient().execute(req);
|
Response response = site.getHttpClient().execute(req);
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
JSONArray json = new JSONArray(response.body().string());
|
JSONArray json = new JSONArray(response.body().string());
|
||||||
if(json.length() == 0) {
|
if(json.length() == 0) {
|
||||||
throw new IOException("Couldn't fetch model details");
|
throw new ModelDetailsEmptyException("Model details are empty");
|
||||||
}
|
}
|
||||||
JSONObject details = json.getJSONObject(0);
|
JSONObject details = json.getJSONObject(0);
|
||||||
onlineState = details.getString("showType");
|
onlineState = details.getString("showType");
|
||||||
|
@ -85,7 +89,11 @@ public class Cam4Model extends AbstractModel {
|
||||||
|
|
||||||
private String getPlaylistUrl() throws IOException {
|
private String getPlaylistUrl() throws IOException {
|
||||||
if(playlistUrl == null) {
|
if(playlistUrl == null) {
|
||||||
loadModelDetails();
|
try {
|
||||||
|
loadModelDetails();
|
||||||
|
} catch (ModelDetailsEmptyException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return playlistUrl;
|
return playlistUrl;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +152,7 @@ public class Cam4Model extends AbstractModel {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
loadModelDetails();
|
loadModelDetails();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
throw new ExecutionException(e);
|
throw new ExecutionException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,4 +236,10 @@ public class Cam4Model extends AbstractModel {
|
||||||
public void setOnlineState(String onlineState) {
|
public void setOnlineState(String onlineState) {
|
||||||
this.onlineState = onlineState;
|
this.onlineState = onlineState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ModelDetailsEmptyException extends Exception {
|
||||||
|
public ModelDetailsEmptyException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue