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