forked from j62/ctbrec
Fix LiveJasmin search
This commit is contained in:
parent
1bd83c5f31
commit
165eac94b9
|
@ -1,31 +1,25 @@
|
||||||
package ctbrec.sites.jasmin;
|
package ctbrec.sites.jasmin;
|
||||||
|
|
||||||
import static ctbrec.io.HttpConstants.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.jsoup.select.Elements;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.NotLoggedInExcetion;
|
import ctbrec.NotLoggedInExcetion;
|
||||||
import ctbrec.io.HtmlParser;
|
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.sites.AbstractSite;
|
import ctbrec.sites.AbstractSite;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
public class LiveJasmin extends AbstractSite {
|
public class LiveJasmin extends AbstractSite {
|
||||||
|
|
||||||
|
@ -74,7 +68,7 @@ public class LiveJasmin extends AbstractSite {
|
||||||
.build();
|
.build();
|
||||||
try (Response response = getHttpClient().execute(request)) {
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = Objects.requireNonNull(response.body()).string();
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
if (json.optBoolean("success")) {
|
if (json.optBoolean("success")) {
|
||||||
return json.optDouble("result");
|
return json.optDouble("result");
|
||||||
|
@ -139,9 +133,18 @@ public class LiveJasmin extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> search(String q) throws IOException, InterruptedException {
|
public List<Model> search(String q) throws IOException, InterruptedException {
|
||||||
String query = URLEncoder.encode(q, "utf-8");
|
String sessionId = getLiveJasminHttpClient().getSessionId();
|
||||||
long ts = System.currentTimeMillis();
|
String pathSegment = sessionId.charAt(0) == 'm' ? "member" : "guest";
|
||||||
String url = getBaseUrl() + "/en/auto-suggest-search/auto-suggest?category=girls&searchText=" + query + "&_dc=" + ts + "&appletType=html5";
|
String base = "https://api-gateway.dditsadn.com";
|
||||||
|
String url = base + "/v2/" + pathSegment + "/auto-suggest/suggestions?"
|
||||||
|
+ "product=livejasmin"
|
||||||
|
+ "&session=" + sessionId
|
||||||
|
+ "&limit=5"
|
||||||
|
+ "&embed[]=data.performers.*"
|
||||||
|
+ "&version=v2"
|
||||||
|
+ "&criteria[]=searchText,%3D," + URLEncoder.encode(q, "utf-8")
|
||||||
|
+ "&criteria[]=language,%3D,en"
|
||||||
|
+ "&criteria[]=gender,%3D,female";
|
||||||
Request request = new Request.Builder().url(url)
|
Request request = new Request.Builder().url(url)
|
||||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, "*/*")
|
.addHeader(ACCEPT, "*/*")
|
||||||
|
@ -149,34 +152,29 @@ public class LiveJasmin extends AbstractSite {
|
||||||
.addHeader(REFERER, getBaseUrl())
|
.addHeader(REFERER, getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.build();
|
.build();
|
||||||
|
LOG.debug("Search URL: {}", url);
|
||||||
try (Response response = getHttpClient().execute(request)) {
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = Objects.requireNonNull(response.body()).string();
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
if (json.optBoolean("success")) {
|
List<Model> models = new ArrayList<>();
|
||||||
List<Model> models = new ArrayList<>();
|
JSONObject data = json.getJSONObject("data");
|
||||||
JSONObject data = json.getJSONObject("data");
|
JSONArray performers = data.getJSONArray("performers");
|
||||||
String html = data.getString("content");
|
for (int i = 0; i < performers.length(); i++) {
|
||||||
Elements items = HtmlParser.getTags(html, "li.name");
|
JSONObject performer = performers.getJSONObject(i);
|
||||||
for (Element item : items) {
|
LiveJasminModel model = (LiveJasminModel) createModel(performer.getString("performerNick"));
|
||||||
String itemHtml = item.html();
|
model.setDisplayName(performer.optString("displayName", model.getName()));
|
||||||
Element link = HtmlParser.getTag(itemHtml, "a");
|
model.setId(String.valueOf(performer.getLong("performerId")));
|
||||||
LiveJasminModel model = (LiveJasminModel) createModel(link.attr("title"));
|
JSONArray profilePics = performer.optJSONArray("profilePictures");
|
||||||
Element pic = HtmlParser.getTag(itemHtml, "span.pic i");
|
if (profilePics != null && profilePics.length() > 0) {
|
||||||
String style = pic.attr("style");
|
JSONObject profilePic = profilePics.getJSONObject(profilePics.length() - 1);
|
||||||
Matcher m = Pattern.compile("url\\('(.*?)'\\)").matcher(style);
|
model.setPreview("https:" + profilePic.getString("url"));
|
||||||
if (m.find()) {
|
|
||||||
model.setPreview(m.group(1));
|
|
||||||
}
|
|
||||||
models.add(model);
|
|
||||||
}
|
}
|
||||||
return models;
|
models.add(model);
|
||||||
} else {
|
|
||||||
LOG.debug("Response was not successful: {}\n{}", url, body);
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
return models;
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), Objects.requireNonNull(response.body()).string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue