From 8fbbbb3dbe5f03591a1731a8db74831fe49caca9 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Mon, 23 Oct 2023 19:46:11 +0200 Subject: [PATCH] Fix Chaturbate overview pages --- .../chaturbate/ChaturbateFollowedTab.java | 14 +++---- .../chaturbate/ChaturbateTabProvider.java | 14 +++---- .../chaturbate/ChaturbateUpdateService.java | 24 +++++++++-- .../chaturbate/ChaturbateModelParser.java | 40 ------------------- 4 files changed, 35 insertions(+), 57 deletions(-) delete mode 100644 common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModelParser.java diff --git a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateFollowedTab.java b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateFollowedTab.java index 212aa601..a84eaebe 100644 --- a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateFollowedTab.java +++ b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateFollowedTab.java @@ -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(); diff --git a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateTabProvider.java b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateTabProvider.java index 116c3990..8c08ca65 100644 --- a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateTabProvider.java +++ b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateTabProvider.java @@ -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 getSiteTabs(Scene scene) { List 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); diff --git a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateUpdateService.java b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateUpdateService.java index ea8ad4f3..29974a50 100644 --- a/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateUpdateService.java +++ b/client/src/main/java/ctbrec/ui/sites/chaturbate/ChaturbateUpdateService.java @@ -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 models = ChaturbateModelParser.parseModels(chaturbate, response.body().string()); + List 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(); diff --git a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModelParser.java b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModelParser.java deleted file mode 100644 index 89dafc83..00000000 --- a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModelParser.java +++ /dev/null @@ -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 parseModels(Chaturbate chaturbate, String html) { - List 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; - } -}