Fix Chaturbate overview pages

This commit is contained in:
0xb00bface 2023-10-23 19:46:11 +02:00
parent 619d888bfa
commit 8fbbbb3dbe
4 changed files with 35 additions and 57 deletions

View File

@ -20,8 +20,8 @@ public class ChaturbateFollowedTab extends ThumbOverviewTab implements FollowedT
public ChaturbateFollowedTab(String title, String url, Chaturbate chaturbate) {
super(title, new ChaturbateUpdateService(url, true, chaturbate), chaturbate);
onlineUrl = url;
offlineUrl = url + "offline/";
onlineUrl = url + "&offline=false";
offlineUrl = url + "&offline=true";
status = new Label("Logging in...");
grid.getChildren().add(status);
@ -41,14 +41,14 @@ public class ChaturbateFollowedTab extends ThumbOverviewTab implements FollowedT
offline.setToggleGroup(group);
pagination.getChildren().add(online);
pagination.getChildren().add(offline);
HBox.setMargin(online, new Insets(5,5,5,40));
HBox.setMargin(offline, new Insets(5,5,5,5));
HBox.setMargin(online, new Insets(5, 5, 5, 40));
HBox.setMargin(offline, new Insets(5, 5, 5, 5));
online.setSelected(true);
group.selectedToggleProperty().addListener(e -> {
if(online.isSelected()) {
((ChaturbateUpdateService)updateService).setUrl(onlineUrl);
if (online.isSelected()) {
((ChaturbateUpdateService) updateService).setUrl(onlineUrl);
} else {
((ChaturbateUpdateService)updateService).setUrl(offlineUrl);
((ChaturbateUpdateService) updateService).setUrl(offlineUrl);
}
queue.clear();
updateService.restart();

View File

@ -16,18 +16,18 @@ public class ChaturbateTabProvider extends AbstractTabProvider {
public ChaturbateTabProvider(Chaturbate chaturbate) {
super(chaturbate);
this.followedTab = new ChaturbateFollowedTab("Followed", chaturbate.getBaseUrl() + "/followed-cams/", chaturbate);
this.followedTab = new ChaturbateFollowedTab("Followed", chaturbate.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&follow=true", chaturbate);
}
@Override
protected List<Tab> getSiteTabs(Scene scene) {
List<Tab> tabs = new ArrayList<>();
tabs.add(createTab("Featured", site.getBaseUrl() + "/"));
tabs.add(createTab("Female", site.getBaseUrl() + "/female-cams/"));
tabs.add(createTab("New Female", site.getBaseUrl() + "/new-cams/female/"));
tabs.add(createTab("Male", site.getBaseUrl() + "/male-cams/"));
tabs.add(createTab("Couples", site.getBaseUrl() + "/couple-cams/"));
tabs.add(createTab("Trans", site.getBaseUrl() + "/trans-cams/"));
tabs.add(createTab("Featured", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false"));
tabs.add(createTab("Female", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=f"));
tabs.add(createTab("New Female", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=f&new_cams=true"));
tabs.add(createTab("Male", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=m"));
tabs.add(createTab("Couples", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=c"));
tabs.add(createTab("Trans", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=s"));
followedTab.setScene(scene);
followedTab.setRecorder(recorder);
followedTab.setImageAspectRatio(9.0 / 16.0);

View File

@ -3,15 +3,19 @@ package ctbrec.ui.sites.chaturbate;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.sites.chaturbate.Chaturbate;
import ctbrec.sites.chaturbate.ChaturbateModelParser;
import ctbrec.sites.chaturbate.ChaturbateModel;
import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.tabs.PaginatedScheduledService;
import javafx.concurrent.Task;
import okhttp3.Request;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
@ -26,6 +30,8 @@ public class ChaturbateUpdateService extends PaginatedScheduledService {
private final boolean loginRequired;
private final Chaturbate chaturbate;
private static final int PAGE_SIZE = 90;
public ChaturbateUpdateService(String url, boolean loginRequired, Chaturbate chaturbate) {
this.url = url;
this.loginRequired = loginRequired;
@ -48,7 +54,7 @@ public class ChaturbateUpdateService extends PaginatedScheduledService {
if (loginRequired && !chaturbate.credentialsAvailable()) {
return Collections.emptyList();
} else {
String pageUrl = ChaturbateUpdateService.this.url + "?page=" + page + "&keywords=&_=" + System.currentTimeMillis();
String pageUrl = ChaturbateUpdateService.this.url + "&limit=" + PAGE_SIZE + "&offset=" + (page - 1) * PAGE_SIZE;
LOG.debug("Fetching page {}", pageUrl);
if (loginRequired) {
SiteUiFactory.getUi(chaturbate).login();
@ -60,7 +66,19 @@ public class ChaturbateUpdateService extends PaginatedScheduledService {
.build();
try (var response = chaturbate.getHttpClient().execute(request)) {
if (response.isSuccessful()) {
List<Model> models = ChaturbateModelParser.parseModels(chaturbate, response.body().string());
List<Model> models = new ArrayList<>();
JSONObject json = new JSONObject(response.body().string());
if (json.has("rooms")) {
JSONArray rooms = json.optJSONArray("rooms");
for (int i = 0; i < rooms.length(); i++) {
JSONObject room = rooms.getJSONObject(i);
ChaturbateModel model = (ChaturbateModel) chaturbate.createModel(room.getString("username"));
if (room.has("subject")) {
model.setDescription(Jsoup.parse(room.getString("subject")).text());
}
models.add(model);
}
}
return models;
} else {
int code = response.code();

View File

@ -1,40 +0,0 @@
package ctbrec.sites.chaturbate;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Model;
import ctbrec.io.HtmlParser;
public class ChaturbateModelParser {
private static final transient Logger LOG = LoggerFactory.getLogger(ChaturbateModelParser.class);
public static List<Model> parseModels(Chaturbate chaturbate, String html) {
List<Model> models = new ArrayList<>();
Elements cells = HtmlParser.getTags(html, "ul.list > li");
for (Element cell : cells) {
String cellHtml = cell.html();
try {
Model model = chaturbate.createModel(HtmlParser.getText(cellHtml, "div.title > a").trim());
model.setName(HtmlParser.getText(cellHtml, "div.title > a").trim());
model.setPreview(HtmlParser.getTag(cellHtml, "a img").attr("src"));
model.setDescription(HtmlParser.getText(cellHtml, "div.details ul.subject"));
Elements tags = HtmlParser.getTags(cellHtml, "div.details ul.subject li a");
if(tags != null) {
for (Element tag : tags) {
model.getTags().add(tag.text());
}
}
models.add(model);
} catch (Exception e) {
LOG.error("Parsing of model details failed: {}", cellHtml, e);
}
}
return models;
}
}