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()) {
String body = response.body().string();
JSONObject json = new JSONObject(body);
if (json.optString("status").equals("SM_OK")) {
if (json.has("performers")) {
List<Model> models = new ArrayList<>();
JSONObject results = json.getJSONObject("results");
JSONArray nickname = results.getJSONArray("nickname");
for (int i = 0; i < nickname.length(); i++) {
JSONObject result = nickname.getJSONObject(i);
JSONArray performers = json.getJSONArray("performers");
for (int i = 0; i < performers.length(); i++) {
JSONObject result = performers.getJSONObject(i);
StreamateModel model = (StreamateModel) createModel(result.getString("nickname"));
model.setId(Long.parseLong(result.getString("performerId")));
model.setId(result.getLong("id"));
String thumb = result.getString("thumbnail");
if (thumb != null) {
model.setPreview(thumb);
}
model.setOnline(result.optString("liveStatus").equals("live"));
model.setOnline(result.optBoolean("online"));
models.add(model);
}
return models;