Improve search for Stripchat
This commit is contained in:
parent
a033ffbd74
commit
0d5d1ba6cc
|
@ -24,6 +24,7 @@
|
|||
- Added "New Girls" tab and adjusted others. All same models on less tabs
|
||||
* Stripchat:
|
||||
- Added "Private" tab
|
||||
- Improved Search
|
||||
- CTBRec can record your Spy/Private/Ticket shows (login required)
|
||||
* Streamray:
|
||||
- Added models tags
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
package ctbrec.ui.sites.stripchat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.sites.stripchat.Stripchat;
|
||||
import ctbrec.ui.ExternalBrowser;
|
||||
|
@ -15,12 +7,19 @@ import okhttp3.Cookie;
|
|||
import okhttp3.Cookie.Builder;
|
||||
import okhttp3.CookieJar;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class StripchatElectronLoginDialog {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StripchatElectronLoginDialog.class);
|
||||
public static final String DOMAIN = Stripchat.domain;
|
||||
public static final String URL = Stripchat.baseUri;
|
||||
public static final String DOMAIN = Stripchat.getDomain();
|
||||
public static final String URL = Stripchat.getBaseUri();
|
||||
private CookieJar cookieJar;
|
||||
private ExternalBrowser browser;
|
||||
|
||||
|
@ -44,14 +43,14 @@ public class StripchatElectronLoginDialog {
|
|||
}
|
||||
|
||||
private Consumer<String> msgHandler = line -> {
|
||||
if(!line.startsWith("{")) {
|
||||
if (!line.startsWith("{")) {
|
||||
System.err.println(line); // NOSONAR
|
||||
} else {
|
||||
var json = new JSONObject(line);
|
||||
if(json.has("url")) {
|
||||
if (json.has("url")) {
|
||||
var url = json.getString("url");
|
||||
|
||||
if(url.endsWith(DOMAIN) || url.endsWith(DOMAIN + '/')) {
|
||||
if (url.endsWith(DOMAIN) || url.endsWith(DOMAIN + '/')) {
|
||||
try {
|
||||
browser.executeJavaScript("document.querySelector('button[class~=\"btn-visitors-agreement-accept\"]').click();");
|
||||
browser.executeJavaScript("document.querySelector('div[class~=\"header-dropdown\"] a[class~=\"dropdown-link\"]').click();");
|
||||
|
@ -67,7 +66,7 @@ public class StripchatElectronLoginDialog {
|
|||
}
|
||||
browser.executeJavaScript("document.querySelector('#recaptcha-checkbox-border').click();");
|
||||
browser.executeJavaScript("document.querySelector('*[class~=btn-login]').addEventListener('click', function() {window.setTimeout(function() {location.reload()}, 2000)});");
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Couldn't auto fill username and password for Stripchat", e);
|
||||
}
|
||||
}
|
||||
|
@ -85,14 +84,14 @@ public class StripchatElectronLoginDialog {
|
|||
var c = createCookie(domain, cookie);
|
||||
cookieJar.saveFromResponse(HttpUrl.parse(url), Collections.singletonList(c));
|
||||
c = createCookie(DOMAIN, cookie);
|
||||
cookieJar.saveFromResponse(HttpUrl.parse(Stripchat.baseUri), Collections.singletonList(c));
|
||||
cookieJar.saveFromResponse(HttpUrl.parse(Stripchat.getBaseUri()), Collections.singletonList(c));
|
||||
if (c.name().contains("_com_sessionId")) {
|
||||
sessionCookieFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(sessionCookieFound) {
|
||||
if (sessionCookieFound) {
|
||||
try {
|
||||
browser.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -111,13 +110,13 @@ public class StripchatElectronLoginDialog {
|
|||
.name(cookie.getString("name"))
|
||||
.value(cookie.getString("value"))
|
||||
.expiresAt(Double.valueOf(cookie.optDouble("expirationDate")).longValue()); // NOSONAR
|
||||
if(cookie.optBoolean("hostOnly")) {
|
||||
if (cookie.optBoolean("hostOnly")) {
|
||||
b.hostOnlyDomain(domain);
|
||||
}
|
||||
if(cookie.optBoolean("httpOnly")) {
|
||||
if (cookie.optBoolean("httpOnly")) {
|
||||
b.httpOnly();
|
||||
}
|
||||
if(cookie.optBoolean("secure")) {
|
||||
if (cookie.optBoolean("secure")) {
|
||||
b.secure();
|
||||
}
|
||||
return b.build();
|
||||
|
|
|
@ -5,6 +5,9 @@ import ctbrec.StringUtil;
|
|||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.sites.AbstractSite;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
|
@ -12,29 +15,31 @@ import org.json.JSONObject;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static ctbrec.io.HttpConstants.USER_AGENT;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class Stripchat extends AbstractSite {
|
||||
private static final Random RNG = new Random();
|
||||
private static final String KEY_MODELS = "models";
|
||||
|
||||
public static String domain = "stripchat.com";
|
||||
public static String baseUri = "https://stripchat.com";
|
||||
@Getter
|
||||
@Setter(AccessLevel.PROTECTED)
|
||||
private static String domain = "stripchat.com";
|
||||
@Getter
|
||||
@Setter(AccessLevel.PROTECTED)
|
||||
private static String baseUri = "https://stripchat.com";
|
||||
private HttpClient httpClient;
|
||||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
boolean hamster = getConfig().getSettings().stripchatUseXhamster;
|
||||
if (hamster) {
|
||||
domain = "xhamsterlive.com";
|
||||
baseUri = "https://" + domain;
|
||||
Stripchat.setDomain("xhamsterlive.com");
|
||||
Stripchat.setBaseUri("https://" + domain);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,22 +133,30 @@ public class Stripchat extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public List<Model> search(String q) throws IOException, InterruptedException {
|
||||
String url = baseUri + "/api/front/v2/models/search?limit=20&query=" + URLEncoder.encode(q, UTF_8);
|
||||
if (StringUtil.isBlank(q)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String url = baseUri + "/api/front/v4/models/search/suggestion?query=" + URLEncoder.encode(q, UTF_8) + "&limit=15&primaryTag=girls&uniq=" + getUniq();
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(REFERER, baseUri)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
if (json.optInt("totalCount") > 0) {
|
||||
if (json.has(KEY_MODELS)) {
|
||||
List<Model> models = new ArrayList<>();
|
||||
JSONArray results = json.getJSONArray("models");
|
||||
for (int i = 0; i < results.length(); i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
StripchatModel model = createModel(result.getString("username"));
|
||||
model.setPreview(result.optString("previewUrlThumbBig"));
|
||||
models.add(model);
|
||||
if (json.has(KEY_MODELS) && !json.isNull(KEY_MODELS)) {
|
||||
JSONArray results = json.getJSONArray(KEY_MODELS);
|
||||
for (int i = 0; i < results.length(); i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
StripchatModel model = createModel(result.getString("username"));
|
||||
model.setPreview(result.optString("avatarUrl"));
|
||||
models.add(model);
|
||||
}
|
||||
}
|
||||
return models;
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
loadCsrfToken();
|
||||
}
|
||||
|
||||
String url = Stripchat.baseUri + "/api/front/auth/login";
|
||||
String url = Stripchat.getBaseUri() + "/api/front/auth/login";
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("loginOrEmail", config.getSettings().stripchatUsername);
|
||||
requestParams.put("password", config.getSettings().stripchatPassword);
|
||||
|
@ -72,8 +72,8 @@ public class StripchatHttpClient extends HttpClient {
|
|||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.post(body)
|
||||
.build();
|
||||
|
@ -95,13 +95,13 @@ public class StripchatHttpClient extends HttpClient {
|
|||
}
|
||||
|
||||
private void loadCsrfToken() throws IOException {
|
||||
String url = Stripchat.baseUri + "/api/front/v2/config/data?requestPath=%2F&timezoneOffset=0";
|
||||
String url = Stripchat.getBaseUri() + "/api/front/v2/config/data?requestPath=%2F&timezoneOffset=0";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.build();
|
||||
try (Response response = execute(request)) {
|
||||
|
@ -118,13 +118,13 @@ public class StripchatHttpClient extends HttpClient {
|
|||
}
|
||||
|
||||
private void loadJwtToken() throws IOException {
|
||||
String url = Stripchat.baseUri + "/api/front/v2/config?requestPath=%2F&timezoneOffset=0";
|
||||
String url = Stripchat.getBaseUri() + "/api/front/v2/config?requestPath=%2F&timezoneOffset=0";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.build();
|
||||
try (Response response = execute(request)) {
|
||||
|
@ -140,8 +140,6 @@ public class StripchatHttpClient extends HttpClient {
|
|||
|
||||
/**
|
||||
* check, if the login worked
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean checkLoginSuccess() throws IOException {
|
||||
try {
|
||||
|
@ -156,13 +154,13 @@ public class StripchatHttpClient extends HttpClient {
|
|||
|
||||
public long getUserId() throws JSONException, IOException {
|
||||
if (userId == 0) {
|
||||
String url = Stripchat.baseUri + "/api/front/users/username/" + config.getSettings().stripchatUsername;
|
||||
String url = Stripchat.getBaseUri() + "/api/front/users/username/" + config.getSettings().stripchatUsername;
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.build();
|
||||
try (Response response = execute(request)) {
|
||||
|
@ -180,7 +178,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
|
||||
public JSONObject getAmpl() {
|
||||
try {
|
||||
Cookie cookie = getCookieJar().getCookie(HttpUrl.parse(Stripchat.baseUri), "baseAmpl");
|
||||
Cookie cookie = getCookieJar().getCookie(HttpUrl.parse(Stripchat.getBaseUri()), "baseAmpl");
|
||||
String json = URLDecoder.decode(cookie.value(), UTF_8);
|
||||
JSONObject ampl = new JSONObject(json);
|
||||
return ampl;
|
||||
|
|
|
@ -258,7 +258,7 @@ public class StripchatModel extends AbstractModel {
|
|||
JSONObject user = info.getJSONObject("user").getJSONObject("user");
|
||||
long id = user.optLong("id");
|
||||
|
||||
String url = Stripchat.baseUri + "/api/front/users/" + client.getUserId() + "/favorites/" + id;
|
||||
String url = Stripchat.getBaseUri() + "/api/front/users/" + client.getUserId() + "/favorites/" + id;
|
||||
JSONObject requestParams = new JSONObject()
|
||||
.put("csrfToken", client.getCsrfToken())
|
||||
.put("csrfTimestamp", client.getCsrfTimestamp())
|
||||
|
@ -270,8 +270,8 @@ public class StripchatModel extends AbstractModel {
|
|||
.url(url)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri + '/' + getName())
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri() + '/' + getName())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.put(body)
|
||||
.build();
|
||||
|
@ -294,7 +294,7 @@ public class StripchatModel extends AbstractModel {
|
|||
JSONArray favoriteIds = new JSONArray().put(id);
|
||||
favoriteIds.put(id);
|
||||
|
||||
String url = Stripchat.baseUri + "/api/front/users/" + client.getUserId() + "/favorites";
|
||||
String url = Stripchat.getBaseUri() + "/api/front/users/" + client.getUserId() + "/favorites";
|
||||
JSONObject requestParams = new JSONObject()
|
||||
.put("favoriteIds", favoriteIds)
|
||||
.put("csrfToken", client.getCsrfToken())
|
||||
|
@ -306,8 +306,8 @@ public class StripchatModel extends AbstractModel {
|
|||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(ORIGIN, Stripchat.getBaseUri())
|
||||
.header(REFERER, Stripchat.getBaseUri())
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
.delete(body)
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue