forked from j62/ctbrec
1
0
Fork 0

Fix: Adjust Streamate search code to new JSON format

Streamate has changed the JSON response for the search. This change
adjusts our code to handle that new format.
This commit is contained in:
0xboobface 2019-02-22 13:42:44 +01:00
parent 37fc341767
commit a249be01c7
1 changed files with 6 additions and 7 deletions

View File

@ -151,19 +151,18 @@ public class Streamate extends AbstractSite {
if (response.isSuccessful()) { if (response.isSuccessful()) {
String body = response.body().string(); String body = response.body().string();
JSONObject json = new JSONObject(body); JSONObject json = new JSONObject(body);
if (json.optString("status").equals("SM_OK")) { if (json.has("performers")) {
List<Model> models = new ArrayList<>(); List<Model> models = new ArrayList<>();
JSONObject results = json.getJSONObject("results"); JSONArray performers = json.getJSONArray("performers");
JSONArray nickname = results.getJSONArray("nickname"); for (int i = 0; i < performers.length(); i++) {
for (int i = 0; i < nickname.length(); i++) { JSONObject result = performers.getJSONObject(i);
JSONObject result = nickname.getJSONObject(i);
StreamateModel model = (StreamateModel) createModel(result.getString("nickname")); StreamateModel model = (StreamateModel) createModel(result.getString("nickname"));
model.setId(Long.parseLong(result.getString("performerId"))); model.setId(result.getLong("id"));
String thumb = result.getString("thumbnail"); String thumb = result.getString("thumbnail");
if (thumb != null) { if (thumb != null) {
model.setPreview(thumb); model.setPreview(thumb);
} }
model.setOnline(result.optString("liveStatus").equals("live")); model.setOnline(result.optBoolean("online"));
models.add(model); models.add(model);
} }
return models; return models;