forked from j62/ctbrec
Implement search for livejasmin
This commit is contained in:
parent
c364250440
commit
b8d9f4bc19
|
@ -1,11 +1,24 @@
|
||||||
package ctbrec.sites.jasmin;
|
package ctbrec.sites.jasmin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
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 ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
import ctbrec.io.HtmlParser;
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.sites.AbstractSite;
|
import ctbrec.sites.AbstractSite;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class LiveJasmin extends AbstractSite {
|
public class LiveJasmin extends AbstractSite {
|
||||||
|
|
||||||
|
@ -81,6 +94,55 @@ public class LiveJasmin extends AbstractSite {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsSearch() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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";
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.addHeader("Accept", "*/*")
|
||||||
|
.addHeader("Accept-Language", "en")
|
||||||
|
.addHeader("Referer", getBaseUrl())
|
||||||
|
.addHeader("X-Requested-With", "XMLHttpRequest")
|
||||||
|
.build();
|
||||||
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
String body = 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);
|
||||||
|
}
|
||||||
|
return models;
|
||||||
|
} else {
|
||||||
|
throw new IOException("Response was not successful: " + url + "\n" + body);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSiteForModel(Model m) {
|
public boolean isSiteForModel(Model m) {
|
||||||
return m instanceof LiveJasminModel;
|
return m instanceof LiveJasminModel;
|
||||||
|
|
Loading…
Reference in New Issue