Add new tabs to Chaturbate
This commit is contained in:
parent
db8ed3396a
commit
4bec3f0fc8
|
@ -0,0 +1,70 @@
|
||||||
|
package ctbrec.ui.sites.chaturbate;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
|
import ctbrec.Model;
|
||||||
|
import ctbrec.StringUtil;
|
||||||
|
import ctbrec.io.HtmlParser;
|
||||||
|
import ctbrec.io.HttpException;
|
||||||
|
import ctbrec.sites.chaturbate.Chaturbate;
|
||||||
|
import ctbrec.sites.chaturbate.ChaturbateModel;
|
||||||
|
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ChaturbateApiUpdateService extends PaginatedScheduledService {
|
||||||
|
|
||||||
|
private final String url;
|
||||||
|
private final Chaturbate chaturbate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<List<Model>> createTask() {
|
||||||
|
return new Task<>() {
|
||||||
|
@Override
|
||||||
|
protected List<Model> call() throws Exception {
|
||||||
|
var request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
|
.build();
|
||||||
|
try (var response = chaturbate.getHttpClient().execute(request)) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
String body = response.body().string();
|
||||||
|
log.trace(body);
|
||||||
|
var models = new ArrayList<Model>();
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
JSONArray rooms = json.optJSONArray("rooms");
|
||||||
|
for (int i = 0; rooms != null && i < rooms.length(); i++) {
|
||||||
|
JSONObject room = rooms.getJSONObject(i);
|
||||||
|
String name = room.getString("room");
|
||||||
|
ChaturbateModel model = (ChaturbateModel) chaturbate.createModel(name);
|
||||||
|
model.setDescription(toText(room.optString("subject")) + " #gender:" + room.optString("gender"));
|
||||||
|
if (StringUtil.isNotBlank(room.optString("display_age"))) {
|
||||||
|
model.setDescription(model.getDescription() + " #age:" + room.optString("display_age"));
|
||||||
|
}
|
||||||
|
models.add(model);
|
||||||
|
}
|
||||||
|
return models;
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String toText(String html) {
|
||||||
|
return HtmlParser.getText(html, "*");
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,9 +14,9 @@ import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
public class ChaturbateFollowedTab extends ThumbOverviewTab implements FollowedTab {
|
public class ChaturbateFollowedTab extends ThumbOverviewTab implements FollowedTab {
|
||||||
private Label status;
|
private final Label status;
|
||||||
private String onlineUrl;
|
private final String onlineUrl;
|
||||||
private String offlineUrl;
|
private final String offlineUrl;
|
||||||
|
|
||||||
public ChaturbateFollowedTab(String title, String url, Chaturbate chaturbate) {
|
public ChaturbateFollowedTab(String title, String url, Chaturbate chaturbate) {
|
||||||
super(title, new ChaturbateUpdateService(url, true, chaturbate), chaturbate);
|
super(title, new ChaturbateUpdateService(url, true, chaturbate), chaturbate);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ctbrec.ui.sites.chaturbate;
|
||||||
|
|
||||||
import ctbrec.sites.chaturbate.Chaturbate;
|
import ctbrec.sites.chaturbate.Chaturbate;
|
||||||
import ctbrec.ui.sites.AbstractTabProvider;
|
import ctbrec.ui.sites.AbstractTabProvider;
|
||||||
|
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||||
import ctbrec.ui.tabs.ThumbOverviewTab;
|
import ctbrec.ui.tabs.ThumbOverviewTab;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
|
@ -31,9 +32,13 @@ public class ChaturbateTabProvider extends AbstractTabProvider {
|
||||||
followedTab.setRecorder(recorder);
|
followedTab.setRecorder(recorder);
|
||||||
followedTab.setImageAspectRatio(9.0 / 16.0);
|
followedTab.setImageAspectRatio(9.0 / 16.0);
|
||||||
tabs.add(followedTab);
|
tabs.add(followedTab);
|
||||||
|
tabs.add(createApiTab("Top Rated", site.getBaseUrl() + "/api/ts/discover/carousels/top-rated/"));
|
||||||
|
tabs.add(createApiTab("Trending", site.getBaseUrl() + "/api/ts/discover/carousels/trending/"));
|
||||||
|
tabs.add(createApiTab("Recommended", site.getBaseUrl() + "/api/ts/discover/carousels/recommended/"));
|
||||||
return tabs;
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tab getFollowedTab() {
|
public Tab getFollowedTab() {
|
||||||
return followedTab;
|
return followedTab;
|
||||||
|
@ -41,9 +46,18 @@ public class ChaturbateTabProvider extends AbstractTabProvider {
|
||||||
|
|
||||||
private Tab createTab(String title, String url) {
|
private Tab createTab(String title, String url) {
|
||||||
var updateService = new ChaturbateUpdateService(url, false, (Chaturbate) site);
|
var updateService = new ChaturbateUpdateService(url, false, (Chaturbate) site);
|
||||||
|
return createTab(title, updateService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tab createTab(String title, PaginatedScheduledService updateService) {
|
||||||
var tab = new ThumbOverviewTab(title, updateService, site);
|
var tab = new ThumbOverviewTab(title, updateService, site);
|
||||||
tab.setRecorder(recorder);
|
tab.setRecorder(recorder);
|
||||||
tab.setImageAspectRatio(9.0 / 16.0);
|
tab.setImageAspectRatio(9.0 / 16.0);
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tab createApiTab(String title, String apiUrl) {
|
||||||
|
var updateService = new ChaturbateApiUpdateService(apiUrl, (Chaturbate) site);
|
||||||
|
return createTab(title, updateService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue