Fix cherry.tv overview pages
This commit is contained in:
parent
ea2c46144b
commit
a6f0777fef
|
@ -1,3 +1,7 @@
|
|||
4.7.7
|
||||
========================
|
||||
* Fix cherry.tv overview pages
|
||||
|
||||
4.7.6
|
||||
========================
|
||||
* Save config in a sub-directory for each version.
|
||||
|
|
|
@ -21,12 +21,14 @@ public class CherryTvFollowedUpdateService extends CherryTvUpdateService {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(CherryTvFollowedUpdateService.class);
|
||||
|
||||
public CherryTvFollowedUpdateService(CherryTv site) {
|
||||
super(site.getBaseUrl() + "/graphql?operationName=FindFollowings&variables={\"cursor\":${offset},\"limit\":${limit}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"7d2cf16b113dc1d57af02685e249e28df9649ea598717dc2c877294529ae0cb3\"}}",
|
||||
site,true);
|
||||
super("following", site, true);
|
||||
url = "https://api.cherry.tv/graphql?operationName=findFollowingBroadcastsByPage&variables={\"limit\":1000}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"241ae6ae3c2bd62e78432b4d51a92a1baa59d9e94d173867a2a45586704465d1\"}}";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Model> parseModels(String body) throws IOException {
|
||||
var json = new JSONObject(body);
|
||||
//LOG.debug(json.toString(2));
|
||||
if (json.has("errors")) {
|
||||
JSONArray errors = json.getJSONArray("errors");
|
||||
JSONObject first = errors.getJSONObject(0);
|
||||
|
@ -34,13 +36,13 @@ public class CherryTvFollowedUpdateService extends CherryTvUpdateService {
|
|||
}
|
||||
List<Model> models = new ArrayList<>();
|
||||
try {
|
||||
JSONArray followings = json.getJSONObject("data").getJSONObject("followinglist").getJSONArray("followings");
|
||||
JSONArray followings = json.getJSONObject("data").getJSONObject("broadcasts").getJSONArray("broadcasts");
|
||||
for (int i = 0; i < followings.length(); i++) {
|
||||
JSONObject following = followings.getJSONObject(i);
|
||||
CherryTvModel model = site.createModel(following.optString("username"));
|
||||
model.setId(following.getString("id"));
|
||||
model.setPreview(following.optString("img"));
|
||||
var online = following.optString("status").equalsIgnoreCase("Live");
|
||||
model.setPreview(following.optString("imageUrl"));
|
||||
var online = following.optString("broadcastStatus").equalsIgnoreCase("Live");
|
||||
model.setOnline(online);
|
||||
model.setOnlineState(online ? ONLINE : OFFLINE);
|
||||
models.add(model);
|
||||
|
|
|
@ -26,9 +26,9 @@ public class CherryTvTabProvider extends AbstractTabProvider {
|
|||
protected List<Tab> getSiteTabs(Scene scene) {
|
||||
List<Tab> tabs = new ArrayList<>();
|
||||
|
||||
tabs.add(createTab("Female", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"girls\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
|
||||
tabs.add(createTab("Trans", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"trans\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
|
||||
tabs.add(createTab("Group Show", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"groupshow\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
|
||||
tabs.add(createTab("Female", "girls"));
|
||||
tabs.add(createTab("Trans", "trans"));
|
||||
tabs.add(createTab("Group Show", "groupshow"));
|
||||
tabs.add(followedTab);
|
||||
return tabs;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -29,20 +30,23 @@ import static ctbrec.Model.State.OFFLINE;
|
|||
import static ctbrec.Model.State.ONLINE;
|
||||
import static ctbrec.io.HttpConstants.ACCEPT_LANGUAGE;
|
||||
import static ctbrec.io.HttpConstants.USER_AGENT;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class CherryTvUpdateService extends PaginatedScheduledService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CherryTvUpdateService.class);
|
||||
private static final int MODELS_PER_PAGE = 100;
|
||||
protected static final long MODELS_PER_PAGE = 50;
|
||||
|
||||
private final String url;
|
||||
protected String url;
|
||||
private final boolean loginRequired;
|
||||
protected final CherryTv site;
|
||||
private Predicate<Model> filter;
|
||||
|
||||
public CherryTvUpdateService(String url, CherryTv site, boolean loginRequired) {
|
||||
public CherryTvUpdateService(String slug, CherryTv site, boolean loginRequired) {
|
||||
this.site = site;
|
||||
this.url = url;
|
||||
this.url = "https://api.cherry.tv/graphql?query=" + URLEncoder.encode(BROADCASTS_QUERY
|
||||
.replace(" ", "")
|
||||
.replace("${slug}", slug), UTF_8);
|
||||
this.loginRequired = loginRequired;
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor(r -> {
|
||||
|
@ -63,13 +67,10 @@ public class CherryTvUpdateService extends PaginatedScheduledService {
|
|||
throw new IOException("Login failed");
|
||||
}
|
||||
|
||||
String pageUrl = CherryTvUpdateService.this.url;
|
||||
pageUrl = pageUrl.replace("${limit}", String.valueOf(MODELS_PER_PAGE));
|
||||
pageUrl = pageUrl.replace("${offset}", String.valueOf((page - 1) * MODELS_PER_PAGE));
|
||||
LOG.debug("Fetching page {}", pageUrl);
|
||||
LOG.debug("Fetching page {}", url);
|
||||
|
||||
var request = new Request.Builder()
|
||||
.url(pageUrl)
|
||||
.url(url)
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.build();
|
||||
|
@ -80,8 +81,11 @@ public class CherryTvUpdateService extends PaginatedScheduledService {
|
|||
if (filter != null) {
|
||||
stream = stream.filter(filter);
|
||||
}
|
||||
return stream.collect(Collectors.toList());
|
||||
return stream.skip((page - 1) * MODELS_PER_PAGE)
|
||||
.limit(MODELS_PER_PAGE)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
LOG.debug(Objects.requireNonNull(response.body()).string());
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +102,7 @@ public class CherryTvUpdateService extends PaginatedScheduledService {
|
|||
}
|
||||
List<Model> models = new ArrayList<>();
|
||||
try {
|
||||
JSONArray broadcasts = json.getJSONObject("data").getJSONObject("broadcasts").getJSONArray("broadcasts");
|
||||
JSONArray broadcasts = json.getJSONObject("data").getJSONObject("broadcastsPaged").getJSONArray("broadcasts");
|
||||
for (int i = 0; i < broadcasts.length(); i++) {
|
||||
JSONObject broadcast = broadcasts.getJSONObject(i);
|
||||
CherryTvModel model = site.createModel(broadcast.optString("username"));
|
||||
|
@ -126,4 +130,22 @@ public class CherryTvUpdateService extends PaginatedScheduledService {
|
|||
public void setFilter(Predicate<Model> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
private static final String BROADCASTS_QUERY = """
|
||||
{
|
||||
broadcastsPaged(query: {limit:1000,slug:"${slug}"}) {
|
||||
broadcasts {
|
||||
id
|
||||
title
|
||||
username
|
||||
description
|
||||
thumbnailUrl
|
||||
tags
|
||||
broadcastStatus
|
||||
showStatus
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
|
|
@ -40,13 +40,14 @@ public class CherryTvHttpClient extends HttpClient {
|
|||
JSONObject body = new JSONObject()
|
||||
.put("operationName", "authenticateUser")
|
||||
.put("variables", new JSONObject()
|
||||
.put("username", config.getSettings().cherryTvUsername)
|
||||
.put("accountName", config.getSettings().cherryTvUsername)
|
||||
.put("password", config.getSettings().cherryTvPassword)
|
||||
.put("sourceDomain", "cherry.tv")
|
||||
)
|
||||
.put("extensions", new JSONObject()
|
||||
.put("persistedQuery", new JSONObject()
|
||||
.put("version", 1)
|
||||
.put("sha256Hash", "9c105878022f9a7d511c12527c70f125606dc25367a4dd56aa63a6af73579087")
|
||||
.put("sha256Hash", "dc7c4f9040e6bbbd9168e3e10867115117c52689beac68c2066c6e695759911a")
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -98,7 +99,7 @@ public class CherryTvHttpClient extends HttpClient {
|
|||
}
|
||||
|
||||
private boolean checkLoginSuccess() {
|
||||
String url = CherryTv.BASE_URL + "/graphql?operationName=FindFollowings&variables={\"cursor\":\"0\",\"limit\":20}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"7d2cf16b113dc1d57af02685e249e28df9649ea598717dc2c877294529ae0cb3\"}}";
|
||||
String url = CherryTv.BASE_URL + "/graphql?operationName=FindFollowings&variables={\"cursor\":\"0\",\"limit\":20}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"b4e8b260e7ab5958011b7a242ecbc13158f05b90380c0dbcafd6a8e3b4c96414\"}}";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(REFERER, CherryTv.BASE_URL)
|
||||
|
|
Loading…
Reference in New Issue