Fix Cherry TV search

This commit is contained in:
0xb00bface 2023-11-04 21:20:15 +01:00
parent 02dc6d6fdb
commit 541fcf5bc7
1 changed files with 7 additions and 13 deletions

View File

@ -23,6 +23,7 @@ import java.util.regex.Pattern;
import static ctbrec.Model.State.OFFLINE;
import static ctbrec.Model.State.ONLINE;
import static ctbrec.io.HttpConstants.*;
import static java.nio.charset.StandardCharsets.UTF_8;
public class CherryTv extends AbstractSite {
@ -107,15 +108,10 @@ public class CherryTv extends AbstractSite {
return true;
}
@Override
public boolean searchRequiresLogin() {
return false;
}
@Override
public List<Model> search(String q) throws IOException, InterruptedException {
String url = "https://cherry.tv/graphql?operationName=findStreamersBySearch&variables="
+ "{\"limit\":6,\"slug\":\"" + URLEncoder.encode(q, "utf-8") + "\"}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"03d2f017fee32e1b6a1d3f816ce226c464a78d8dab28895c321980fbadffc1ef\"}}";
String url = "https://api.cherry.tv/graphql?operationName=Search&variables="
+ "{\"limit\":6,\"slug\":\"" + URLEncoder.encode(q, UTF_8) + "\"}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b6b001b46111c5634b5d3f48caa5ad38e747d74a5c841f447f0094e7f2bc2fb1\"}}";
Request req = new Request.Builder()
.url(url)
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
@ -131,18 +127,16 @@ public class CherryTv extends AbstractSite {
JSONObject json = new JSONObject(Objects.requireNonNull(response.body()).string());
LOG.trace(json.toString(2));
JSONObject data = json.getJSONObject("data");
JSONObject searchResult = data.getJSONObject("searchResult");
JSONArray streamers = searchResult.getJSONArray("streamers");
JSONArray streamers = data.getJSONArray("search");
for (int i = 0; i < streamers.length(); i++) {
JSONObject hit = streamers.getJSONObject(i);
CherryTvModel model = createModel(hit.getString("username"));
CherryTvModel model = createModel(hit.getString("id"));
model.setId(hit.getString("id"));
boolean online = hit.optString("showStatus").equalsIgnoreCase("Public")
&& hit.optString("broadcastStatus").equalsIgnoreCase("Live");
boolean online = hit.optString("broadcastStatus").equalsIgnoreCase("Live");
model.setOnline(online);
model.setOnlineState(online ? ONLINE : OFFLINE);
model.setDescription(hit.getString("description"));
model.setPreview(hit.getString("imageUrl"));
model.setPreview(hit.getString("image"));
result.add(model);
}
} else {