forked from j62/ctbrec
Make sure, that the model id is always set
This commit is contained in:
parent
881e8afb4c
commit
0d47952d3d
|
@ -102,6 +102,7 @@ public class CherryTvUpdateService extends PaginatedScheduledService {
|
|||
for (int i = 0; i < broadcasts.length(); i++) {
|
||||
JSONObject broadcast = broadcasts.getJSONObject(i);
|
||||
CherryTvModel model = site.createModel(broadcast.optString("username"));
|
||||
model.setId(broadcast.getString("id"));
|
||||
model.setDisplayName(broadcast.optString("title"));
|
||||
model.setDescription(broadcast.optString("description"));
|
||||
model.setPreview(broadcast.optString("thumbnailUrl"));
|
||||
|
|
|
@ -13,10 +13,15 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static ctbrec.Model.State.OFFLINE;
|
||||
import static ctbrec.Model.State.ONLINE;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
public class CherryTv extends AbstractSite {
|
||||
|
@ -131,6 +136,11 @@ public class CherryTv extends AbstractSite {
|
|||
for (int i = 0; i < streamers.length(); i++) {
|
||||
JSONObject hit = streamers.getJSONObject(i);
|
||||
CherryTvModel model = createModel(hit.getString("username"));
|
||||
model.setId(hit.getString("id"));
|
||||
boolean online = hit.optString("showStatus").equalsIgnoreCase("Public")
|
||||
&& hit.optString("broadcastStatus").equalsIgnoreCase("Live");
|
||||
model.setOnline(online);
|
||||
model.setOnlineState(online ? ONLINE : OFFLINE);
|
||||
model.setDescription(hit.getString("description"));
|
||||
model.setPreview(hit.getString("imageUrl"));
|
||||
result.add(model);
|
||||
|
@ -157,7 +167,15 @@ public class CherryTv extends AbstractSite {
|
|||
Matcher m = Pattern.compile("https?://.*?cherry\\.tv/([^/]*?)/?").matcher(url);
|
||||
if (m.matches()) {
|
||||
String modelName = m.group(1);
|
||||
return createModel(modelName);
|
||||
CherryTvModel model = createModel(modelName);
|
||||
try {
|
||||
model.isOnline(true);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Couldn't determine model id. This could cause problems in the future", e);
|
||||
}
|
||||
return model;
|
||||
} else {
|
||||
return super.createModelFromUrl(url);
|
||||
}
|
||||
|
|
|
@ -67,8 +67,7 @@ public class CherryTvModel extends AbstractModel {
|
|||
if (key.startsWith("Broadcast:")) {
|
||||
JSONObject broadcast = apolloState.getJSONObject(key);
|
||||
setDisplayName(broadcast.optString("title"));
|
||||
// id = broadcast.getString("id");
|
||||
// roomId = broadcast.getString("roomId");
|
||||
id = broadcast.getString("id");
|
||||
online = broadcast.optString("showStatus").equalsIgnoreCase("Public")
|
||||
&& broadcast.optString("broadcastStatus").equalsIgnoreCase("Live");
|
||||
onlineState = online ? ONLINE : OFFLINE;
|
||||
|
|
Loading…
Reference in New Issue