Improve Chaturbate search
This commit is contained in:
parent
939758403e
commit
0b25c68bdb
|
@ -2,6 +2,7 @@
|
||||||
========================
|
========================
|
||||||
* Added Amateur.TV
|
* Added Amateur.TV
|
||||||
* Added XloveCam
|
* Added XloveCam
|
||||||
|
* Improved Chaturbate search
|
||||||
* Fixed tipping function
|
* Fixed tipping function
|
||||||
|
|
||||||
4.3.1
|
4.3.1
|
||||||
|
|
|
@ -10,8 +10,12 @@ import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.io.HtmlParser;
|
import ctbrec.io.HtmlParser;
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
import ctbrec.sites.AbstractSite;
|
import ctbrec.sites.AbstractSite;
|
||||||
|
@ -119,34 +123,37 @@ public class Chaturbate extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> search(String q) throws IOException, InterruptedException {
|
public List<Model> search(String q) throws IOException, InterruptedException {
|
||||||
String url = baseUrl + "?keywords=" + URLEncoder.encode(q, "utf-8");
|
String url = baseUrl + "/ax/search/?keywords=" + URLEncoder.encode(q, "utf-8");
|
||||||
List<Model> result = new ArrayList<>();
|
List<Model> result = new ArrayList<>();
|
||||||
|
|
||||||
// search online models
|
// search online models
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.header(ACCEPT, "*/*")
|
||||||
|
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
|
.header(REFERER, getBaseUrl())
|
||||||
.build();
|
.build();
|
||||||
try(Response resp = getHttpClient().execute(req)) {
|
try (Response resp = getHttpClient().execute(req)) {
|
||||||
if(resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
result.addAll(ChaturbateModelParser.parseModels(this, resp.body().string()));
|
JSONObject json = new JSONObject(resp.body().string());
|
||||||
}
|
JSONArray offline = json.getJSONArray("offline");
|
||||||
}
|
JSONArray online = json.getJSONArray("online");
|
||||||
|
|
||||||
// since chaturbate does not return offline models, we at least try, if the profile page
|
for (int i = 0; i < online.length(); i++) {
|
||||||
// exists for the search string
|
result.add(createModel(online.getString(i)));
|
||||||
url = baseUrl + '/' + q;
|
}
|
||||||
req = new Request.Builder()
|
for (int i = 0; i < offline.length(); i++) {
|
||||||
.url(url)
|
result.add(createModel(offline.getString(i)));
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
}
|
||||||
.build();
|
|
||||||
try(Response resp = getHttpClient().execute(req)) {
|
|
||||||
if(resp.isSuccessful()) {
|
|
||||||
Model model = createModel(q);
|
|
||||||
result.add(model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.sort((m1, m2) -> {
|
||||||
|
int m1match = StringUtil.percentageOfEquality(q, m1.getName());
|
||||||
|
int m2match = StringUtil.percentageOfEquality(q, m2.getName());
|
||||||
|
return m2match - m1match;
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue