From 8cafc7124f35d3d462acda8ccf63f3b979e43771 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Sun, 23 Feb 2020 19:36:14 +0100 Subject: [PATCH] Add search for Stripchat --- .../java/ctbrec/ui/action/FollowAction.java | 5 ++-- .../ui/controls/SearchPopoverTreeList.java | 30 ++++++++++--------- .../ctbrec/sites/stripchat/Stripchat.java | 26 +++++----------- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/action/FollowAction.java b/client/src/main/java/ctbrec/ui/action/FollowAction.java index d5bec925..4df34ccb 100644 --- a/client/src/main/java/ctbrec/ui/action/FollowAction.java +++ b/client/src/main/java/ctbrec/ui/action/FollowAction.java @@ -12,12 +12,13 @@ import javafx.scene.Node; public class FollowAction extends ModelMassEditAction { - private static final transient Logger LOG = LoggerFactory.getLogger(FollowAction.class); + private static final Logger LOG = LoggerFactory.getLogger(FollowAction.class); public FollowAction(Node source, List models) { super(source, models); - action = (m) -> { + action = m -> { try { + m.getSite().login(); m.follow(); } catch(Exception e) { LOG.error("Couldn't follow model {}", m, e); diff --git a/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java b/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java index 6cda44a6..1e3fb025 100644 --- a/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java +++ b/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java @@ -61,16 +61,12 @@ import javafx.scene.shape.Rectangle; * Popover page that displays a list of samples and sample categories for a given SampleCategory. */ public class SearchPopoverTreeList extends PopoverTreeList implements Popover.Page { - private static final transient Logger LOG = LoggerFactory.getLogger(SearchPopoverTreeList.class); + private static final Logger LOG = LoggerFactory.getLogger(SearchPopoverTreeList.class); private Popover popover; private Recorder recorder; - public SearchPopoverTreeList() { - - } - @Override public ListCell call(ListView p) { return new SearchItemListCell(); @@ -112,6 +108,7 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop @Override public void handleLeftButton() { + // not used } @Override @@ -126,10 +123,12 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop @Override public void handleShown() { + // not used } @Override public void handleHidden() { + // not used } private class SearchItemListCell extends ListCell implements Skin, EventHandler { @@ -144,16 +143,17 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop private SearchItemListCell() { super(); + String highlightClass = "highlight"; setSkin(this); getStyleClass().setAll("search-tree-list-cell"); setOnMouseClicked(this); setOnMouseEntered(evt -> { - getStyleClass().add("highlight"); - title.getStyleClass().add("highlight"); + getStyleClass().add(highlightClass); + title.getStyleClass().add(highlightClass); }); setOnMouseExited(evt -> { - getStyleClass().remove("highlight"); - title.getStyleClass().remove("highlight"); + getStyleClass().remove(highlightClass); + title.getStyleClass().remove(highlightClass); }); Rectangle clip = new Rectangle(thumbSize, thumbSize); @@ -165,11 +165,12 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop thumb.setSmooth(true); follow = new Button("Follow"); - follow.setOnAction((evt) -> { + follow.setOnAction(evt -> { setCursor(Cursor.WAIT); new Thread(new Task() { @Override protected Boolean call() throws Exception { + model.getSite().login(); return model.follow(); } @@ -185,7 +186,7 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop }).start(); }); record = new Button("Record"); - record.setOnAction((evt) -> { + record.setOnAction(evt -> { setCursor(Cursor.WAIT); new Thread(new Task() { @Override @@ -269,21 +270,21 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop @Override protected double computeMinWidth(double height) { final Insets insets = getInsets(); - final double h = height = insets.getBottom() - insets.getTop(); + final double h = insets.getBottom() - insets.getTop(); return (int) ((insets.getLeft() + tallest.minWidth(h) + tallest.minWidth(h) + insets.getRight()) + 0.5d); } @Override protected double computePrefWidth(double height) { final Insets insets = getInsets(); - final double h = height = insets.getBottom() - insets.getTop(); + final double h = insets.getBottom() - insets.getTop(); return (int) ((insets.getLeft() + tallest.prefWidth(h) + tallest.prefWidth(h) + insets.getRight()) + 0.5d); } @Override protected double computeMaxWidth(double height) { final Insets insets = getInsets(); - final double h = height = insets.getBottom() - insets.getTop(); + final double h = insets.getBottom() - insets.getTop(); return (int) ((insets.getLeft() + tallest.maxWidth(h) + tallest.maxWidth(h) + insets.getRight()) + 0.5d); } @@ -314,6 +315,7 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop @Override public void dispose() { + // nothing to do } } diff --git a/common/src/main/java/ctbrec/sites/stripchat/Stripchat.java b/common/src/main/java/ctbrec/sites/stripchat/Stripchat.java index 143837d9..07974847 100644 --- a/common/src/main/java/ctbrec/sites/stripchat/Stripchat.java +++ b/common/src/main/java/ctbrec/sites/stripchat/Stripchat.java @@ -12,8 +12,6 @@ import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ctbrec.Config; import ctbrec.Model; @@ -25,7 +23,6 @@ import okhttp3.Response; public class Stripchat extends AbstractSite { - private static final Logger LOG = LoggerFactory.getLogger(Stripchat.class); public static final String BASE_URI = "https://stripchat.com"; private HttpClient httpClient; @@ -120,37 +117,30 @@ public class Stripchat extends AbstractSite { @Override public boolean supportsSearch() { - return false; + return true; } @Override public List search(String q) throws IOException, InterruptedException { - String url = BASE_URI + "/api/v1/browse/autocomplete?s=" + URLEncoder.encode(q, "utf-8"); + String url = BASE_URI + "/api/front/v2/models/search?limit=20&query=" + URLEncoder.encode(q, "utf-8"); Request req = new Request.Builder() .url(url) - .addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) + .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) .build(); - try(Response response = getHttpClient().execute(req)) { - if(response.isSuccessful()) { + try (Response response = getHttpClient().execute(req)) { + if (response.isSuccessful()) { JSONObject json = new JSONObject(response.body().string()); - if(json.optBoolean("status")) { + if (json.optInt("totalCount") > 0) { List models = new ArrayList<>(); - JSONArray results = json.getJSONArray("results"); + JSONArray results = json.getJSONArray("models"); for (int i = 0; i < results.length(); i++) { JSONObject result = results.getJSONObject(i); StripchatModel model = createModel(result.getString("username")); - String thumb = result.getString("thumb"); - if(thumb != null) { - model.setPreview("https:" + thumb); - } - if(result.has("display_name")) { - model.setDisplayName(result.getString("display_name")); - } + model.setPreview(result.optString("previewUrlThumbBig")); models.add(model); } return models; } else { - LOG.warn("Search result: {}", json.toString(2)); return Collections.emptyList(); } } else {