add - 搜索
This commit is contained in:
@@ -6,10 +6,15 @@ import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.utils.Misc;
|
||||
import com.github.catvod.utils.okhttp.OkHttpUtil;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PushAgentQQ extends Spider {
|
||||
private PushAgent pushAgent;
|
||||
@@ -20,43 +25,16 @@ public class PushAgentQQ extends Spider {
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
super.init(context, extend);
|
||||
String token = null;
|
||||
pushAgent = new PushAgent();
|
||||
pushAgent.init(context, extend);
|
||||
if (extend != null) {
|
||||
if (!extend.startsWith("http")) {
|
||||
String[] arr = extend.split(";");
|
||||
token = arr[0];
|
||||
this.ext = arr[1];
|
||||
}else {
|
||||
this.ext = extend;
|
||||
}
|
||||
}
|
||||
pushAgent = new PushAgent();
|
||||
pushAgent.init(context, token);
|
||||
}
|
||||
|
||||
protected void fetchRule(boolean flag) {
|
||||
try {
|
||||
if (flag || rule == null) {
|
||||
String json = OkHttpUtil.string(ext+"?t="+Time(), null);
|
||||
rule = new JSONObject(json);
|
||||
pushAgent.type = rule.optInt("modelType", 1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
private String getRuleVal(JSONObject o,String key, String defaultVal) {
|
||||
String v = o.optString(key);
|
||||
if (v.isEmpty() || v.equals("空"))
|
||||
return defaultVal;
|
||||
return v;
|
||||
}
|
||||
|
||||
private String getRuleVal(JSONObject o,String key) {
|
||||
return getRuleVal(o,key, "");
|
||||
}
|
||||
|
||||
protected static long Time() {
|
||||
return (System.currentTimeMillis() / 1000) + n;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +43,7 @@ public class PushAgentQQ extends Spider {
|
||||
fetchRule(true);
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray classes = new JSONArray();
|
||||
String[] fenleis = getRuleVal(rule,"fenlei", "").split("#");
|
||||
String[] fenleis = pushAgent.getRuleVal(rule,"fenlei", "").split("#");
|
||||
for (String fenlei : fenleis) {
|
||||
String[] info = fenlei.split("\\$");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -81,16 +59,19 @@ public class PushAgentQQ extends Spider {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
protected JSONObject fetchRule(boolean flag) {
|
||||
rule = pushAgent.fetchRule(flag, 0);
|
||||
return rule;
|
||||
}
|
||||
@Override
|
||||
public String homeVideoContent() {
|
||||
try {
|
||||
fetchRule(true);
|
||||
JSONObject jo = pushAgent.fetchRule(true,1);
|
||||
JSONArray videos = new JSONArray();
|
||||
String[] fenleis = getRuleVal(rule, "fenlei", "").split("#");
|
||||
String[] fenleis = pushAgent.getRuleVal(jo, "fenlei", "").split("#");
|
||||
for (String fenlei : fenleis) {
|
||||
String[] info = fenlei.split("\\$");
|
||||
JSONObject data = category(info[1], "1", false, new HashMap<>());
|
||||
JSONObject data = category(info[1], "1", false, new HashMap<>(),jo);
|
||||
if (data != null) {
|
||||
JSONArray vids = data.optJSONArray("list");
|
||||
if (vids != null) {
|
||||
@@ -111,19 +92,18 @@ public class PushAgentQQ extends Spider {
|
||||
return "";
|
||||
}
|
||||
|
||||
private JSONObject category(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
||||
private JSONObject category(String tid, String pg, boolean filter, HashMap<String, String> extend,JSONObject jo) {
|
||||
try {
|
||||
fetchRule(true);
|
||||
if (jo == null) jo = pushAgent.fetchRule(true,1);
|
||||
JSONArray videos = new JSONArray();
|
||||
|
||||
JSONArray array = rule.getJSONArray(tid);
|
||||
JSONArray array = jo.getJSONArray(tid);
|
||||
JSONObject jsonObject = null, v = null;
|
||||
String url=null,name=null,pic=null;
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
jsonObject = array.getJSONObject(i);
|
||||
url = getRuleVal(jsonObject, "url");
|
||||
name = getRuleVal(jsonObject, "name");
|
||||
pic = getRuleVal(jsonObject, "pic");
|
||||
url = pushAgent.getRuleVal(jsonObject, "url");
|
||||
name = pushAgent.getRuleVal(jsonObject, "name");
|
||||
pic = pushAgent.getRuleVal(jsonObject, "pic");
|
||||
if(pic.equals("")) pic = Misc.getWebName(url, 1);
|
||||
v = new JSONObject();
|
||||
v.put("vod_id", url + "$$$" + pic + "$$$" + name);
|
||||
@@ -151,7 +131,7 @@ public class PushAgentQQ extends Spider {
|
||||
|
||||
@Override
|
||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
||||
JSONObject obj = category(tid, pg, filter, extend);
|
||||
JSONObject obj = category(tid, pg, filter, extend,null);
|
||||
return obj != null ? obj.toString() : "";
|
||||
}
|
||||
|
||||
@@ -166,4 +146,52 @@ public class PushAgentQQ extends Spider {
|
||||
return pushAgent.playerContent(str, str2, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchContent(String key, boolean quick) {
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray videos = new JSONArray();
|
||||
try {
|
||||
fetchRule(true);
|
||||
String url = "",webUrl,detailRex,siteUrl,siteName;
|
||||
JSONArray siteArray = rule.getJSONArray("sites");
|
||||
for (int j = 0; j < siteArray.length(); j++) {
|
||||
JSONObject site = siteArray.getJSONObject(j);
|
||||
siteUrl = site.optString("site");
|
||||
siteName = site.optString("name");
|
||||
detailRex = siteUrl+site.optString("detailRex","/vod/%s.html");
|
||||
webUrl = siteUrl + "/index.php/ajax/suggest?mid=1&wd="+key;
|
||||
|
||||
JSONObject data = new JSONObject(OkHttpUtil.string(webUrl, Misc.Headers(0)));
|
||||
JSONArray vodArray = data.getJSONArray("list");
|
||||
for (int i = 0; i < vodArray.length(); i++) {
|
||||
JSONObject vod = vodArray.getJSONObject(i);
|
||||
String name = vod.optString("name").trim();
|
||||
String id = vod.optString("id").trim();
|
||||
String pic = vod.optString("pic").trim();
|
||||
pic = Misc.fixUrl(webUrl, pic);
|
||||
|
||||
url = detailRex.replace("%s",id);
|
||||
JSONObject v = new JSONObject();
|
||||
v.put("vod_id", url + "$$$" + pic + "$$$" + name);
|
||||
v.put("vod_name", "["+siteName+"]"+name);
|
||||
v.put("vod_pic", pic);
|
||||
v.put("vod_remarks", siteName);
|
||||
videos.put(v);
|
||||
}
|
||||
}
|
||||
result.put("list", videos);
|
||||
return result.toString();
|
||||
} catch (Exception e) {
|
||||
SpiderDebug.log(e);
|
||||
if (videos.length() > 0) {
|
||||
try {
|
||||
result.put("list", videos);
|
||||
} catch (JSONException jsonException) {
|
||||
jsonException.printStackTrace();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user