Add search for Stripchat
This commit is contained in:
parent
e4b9da7685
commit
8cafc7124f
|
@ -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<? extends Model> 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);
|
||||
|
|
|
@ -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<Model> 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<Model> call(ListView<Model> p) {
|
||||
return new SearchItemListCell();
|
||||
|
@ -112,6 +108,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
|||
|
||||
@Override
|
||||
public void handleLeftButton() {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,10 +123,12 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
|||
|
||||
@Override
|
||||
public void handleShown() {
|
||||
// not used
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleHidden() {
|
||||
// not used
|
||||
}
|
||||
|
||||
private class SearchItemListCell extends ListCell<Model> implements Skin<SearchItemListCell>, EventHandler<MouseEvent> {
|
||||
|
@ -144,16 +143,17 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> 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<Model> implements Pop
|
|||
thumb.setSmooth(true);
|
||||
|
||||
follow = new Button("Follow");
|
||||
follow.setOnAction((evt) -> {
|
||||
follow.setOnAction(evt -> {
|
||||
setCursor(Cursor.WAIT);
|
||||
new Thread(new Task<Boolean>() {
|
||||
@Override
|
||||
protected Boolean call() throws Exception {
|
||||
model.getSite().login();
|
||||
return model.follow();
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
|||
}).start();
|
||||
});
|
||||
record = new Button("Record");
|
||||
record.setOnAction((evt) -> {
|
||||
record.setOnAction(evt -> {
|
||||
setCursor(Cursor.WAIT);
|
||||
new Thread(new Task<Void>() {
|
||||
@Override
|
||||
|
@ -269,21 +270,21 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> 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<Model> implements Pop
|
|||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Model> 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()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
if(json.optBoolean("status")) {
|
||||
if (json.optInt("totalCount") > 0) {
|
||||
List<Model> 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 {
|
||||
|
|
Loading…
Reference in New Issue