forked from j62/ctbrec
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 {
|
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) {
|
public FollowAction(Node source, List<? extends Model> models) {
|
||||||
super(source, models);
|
super(source, models);
|
||||||
action = (m) -> {
|
action = m -> {
|
||||||
try {
|
try {
|
||||||
|
m.getSite().login();
|
||||||
m.follow();
|
m.follow();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
LOG.error("Couldn't follow model {}", m, 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.
|
* Popover page that displays a list of samples and sample categories for a given SampleCategory.
|
||||||
*/
|
*/
|
||||||
public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Popover.Page {
|
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 Popover popover;
|
||||||
|
|
||||||
private Recorder recorder;
|
private Recorder recorder;
|
||||||
|
|
||||||
public SearchPopoverTreeList() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListCell<Model> call(ListView<Model> p) {
|
public ListCell<Model> call(ListView<Model> p) {
|
||||||
return new SearchItemListCell();
|
return new SearchItemListCell();
|
||||||
|
@ -112,6 +108,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleLeftButton() {
|
public void handleLeftButton() {
|
||||||
|
// not used
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,10 +123,12 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleShown() {
|
public void handleShown() {
|
||||||
|
// not used
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleHidden() {
|
public void handleHidden() {
|
||||||
|
// not used
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SearchItemListCell extends ListCell<Model> implements Skin<SearchItemListCell>, EventHandler<MouseEvent> {
|
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() {
|
private SearchItemListCell() {
|
||||||
super();
|
super();
|
||||||
|
String highlightClass = "highlight";
|
||||||
setSkin(this);
|
setSkin(this);
|
||||||
getStyleClass().setAll("search-tree-list-cell");
|
getStyleClass().setAll("search-tree-list-cell");
|
||||||
setOnMouseClicked(this);
|
setOnMouseClicked(this);
|
||||||
setOnMouseEntered(evt -> {
|
setOnMouseEntered(evt -> {
|
||||||
getStyleClass().add("highlight");
|
getStyleClass().add(highlightClass);
|
||||||
title.getStyleClass().add("highlight");
|
title.getStyleClass().add(highlightClass);
|
||||||
});
|
});
|
||||||
setOnMouseExited(evt -> {
|
setOnMouseExited(evt -> {
|
||||||
getStyleClass().remove("highlight");
|
getStyleClass().remove(highlightClass);
|
||||||
title.getStyleClass().remove("highlight");
|
title.getStyleClass().remove(highlightClass);
|
||||||
});
|
});
|
||||||
|
|
||||||
Rectangle clip = new Rectangle(thumbSize, thumbSize);
|
Rectangle clip = new Rectangle(thumbSize, thumbSize);
|
||||||
|
@ -165,11 +165,12 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
||||||
thumb.setSmooth(true);
|
thumb.setSmooth(true);
|
||||||
|
|
||||||
follow = new Button("Follow");
|
follow = new Button("Follow");
|
||||||
follow.setOnAction((evt) -> {
|
follow.setOnAction(evt -> {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
new Thread(new Task<Boolean>() {
|
new Thread(new Task<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean call() throws Exception {
|
protected Boolean call() throws Exception {
|
||||||
|
model.getSite().login();
|
||||||
return model.follow();
|
return model.follow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
||||||
}).start();
|
}).start();
|
||||||
});
|
});
|
||||||
record = new Button("Record");
|
record = new Button("Record");
|
||||||
record.setOnAction((evt) -> {
|
record.setOnAction(evt -> {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
new Thread(new Task<Void>() {
|
new Thread(new Task<Void>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -269,21 +270,21 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
|
||||||
@Override
|
@Override
|
||||||
protected double computeMinWidth(double height) {
|
protected double computeMinWidth(double height) {
|
||||||
final Insets insets = getInsets();
|
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);
|
return (int) ((insets.getLeft() + tallest.minWidth(h) + tallest.minWidth(h) + insets.getRight()) + 0.5d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double computePrefWidth(double height) {
|
protected double computePrefWidth(double height) {
|
||||||
final Insets insets = getInsets();
|
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);
|
return (int) ((insets.getLeft() + tallest.prefWidth(h) + tallest.prefWidth(h) + insets.getRight()) + 0.5d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double computeMaxWidth(double height) {
|
protected double computeMaxWidth(double height) {
|
||||||
final Insets insets = getInsets();
|
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);
|
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
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
// nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
@ -25,7 +23,6 @@ import okhttp3.Response;
|
||||||
|
|
||||||
public class Stripchat extends AbstractSite {
|
public class Stripchat extends AbstractSite {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Stripchat.class);
|
|
||||||
public static final String BASE_URI = "https://stripchat.com";
|
public static final String BASE_URI = "https://stripchat.com";
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
|
@ -120,37 +117,30 @@ public class Stripchat extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsSearch() {
|
public boolean supportsSearch() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> search(String q) throws IOException, InterruptedException {
|
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()
|
Request req = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.build();
|
.build();
|
||||||
try(Response response = getHttpClient().execute(req)) {
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
if(response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(response.body().string());
|
||||||
if(json.optBoolean("status")) {
|
if (json.optInt("totalCount") > 0) {
|
||||||
List<Model> models = new ArrayList<>();
|
List<Model> models = new ArrayList<>();
|
||||||
JSONArray results = json.getJSONArray("results");
|
JSONArray results = json.getJSONArray("models");
|
||||||
for (int i = 0; i < results.length(); i++) {
|
for (int i = 0; i < results.length(); i++) {
|
||||||
JSONObject result = results.getJSONObject(i);
|
JSONObject result = results.getJSONObject(i);
|
||||||
StripchatModel model = createModel(result.getString("username"));
|
StripchatModel model = createModel(result.getString("username"));
|
||||||
String thumb = result.getString("thumb");
|
model.setPreview(result.optString("previewUrlThumbBig"));
|
||||||
if(thumb != null) {
|
|
||||||
model.setPreview("https:" + thumb);
|
|
||||||
}
|
|
||||||
if(result.has("display_name")) {
|
|
||||||
model.setDisplayName(result.getString("display_name"));
|
|
||||||
}
|
|
||||||
models.add(model);
|
models.add(model);
|
||||||
}
|
}
|
||||||
return models;
|
return models;
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Search result: {}", json.toString(2));
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue