add - 搜索
This commit is contained in:
@@ -11,6 +11,7 @@ import com.github.catvod.utils.okhttp.OKCallBack;
|
|||||||
import com.github.catvod.utils.okhttp.OkHttpUtil;
|
import com.github.catvod.utils.okhttp.OkHttpUtil;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
@@ -42,6 +43,8 @@ public class PushAgent extends Spider {
|
|||||||
private static final Pattern AliPLink = Pattern.compile("(https://www.aliyundrive.com/s/[^\"]+)");
|
private static final Pattern AliPLink = Pattern.compile("(https://www.aliyundrive.com/s/[^\"]+)");
|
||||||
public static Pattern Folder = Pattern.compile("www.aliyundrive.com/s/([^/]+)(/folder/([^/]+))?");
|
public static Pattern Folder = Pattern.compile("www.aliyundrive.com/s/([^/]+)(/folder/([^/]+))?");
|
||||||
public static String Token="3a49cf29cf20410997247c6eb4509be9";
|
public static String Token="3a49cf29cf20410997247c6eb4509be9";
|
||||||
|
public static JSONObject siteRule = null;
|
||||||
|
public static String jsonUrl = "http://test.xinjun58.com/sp/d.json";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
@@ -61,7 +64,39 @@ public class PushAgent extends Spider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static long Time() {
|
public JSONObject fetchRule(boolean flag,int t) {
|
||||||
|
try {
|
||||||
|
if (flag || siteRule == null) {
|
||||||
|
String json = OkHttpUtil.string(jsonUrl+"?t="+Time(), null);
|
||||||
|
JSONObject jo = new JSONObject(json);
|
||||||
|
type = jo.optInt("modelType", 1);
|
||||||
|
if(t==0) {
|
||||||
|
String[] fenleis = getRuleVal(jo,"fenlei", "").split("#");
|
||||||
|
for (String fenlei : fenleis) {
|
||||||
|
String[] info = fenlei.split("\\$");
|
||||||
|
jo.remove(info[1]);
|
||||||
|
}
|
||||||
|
siteRule = jo;
|
||||||
|
}
|
||||||
|
return jo;
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
}
|
||||||
|
return siteRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleVal(JSONObject o,String key, String defaultVal) {
|
||||||
|
String v = o.optString(key);
|
||||||
|
if (v.isEmpty() || v.equals("空"))
|
||||||
|
return defaultVal;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleVal(JSONObject o,String key) {
|
||||||
|
return getRuleVal(o,key, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long Time() {
|
||||||
return (System.currentTimeMillis() / 1000) + n;
|
return (System.currentTimeMillis() / 1000) + n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,14 +652,33 @@ public class PushAgent extends Spider {
|
|||||||
return getAliContent(list,pic);
|
return getAliContent(list,pic);
|
||||||
} else if (url.startsWith("http") && (!matcher.find()) && (!matcher2.find())) {
|
} else if (url.startsWith("http") && (!matcher.find()) && (!matcher2.find())) {
|
||||||
JSONObject vodAtom = new JSONObject();
|
JSONObject vodAtom = new JSONObject();
|
||||||
Document doc = Jsoup.parse(OkHttpUtil.string(url, Misc.Headers(0,url)));
|
Document doc = null;
|
||||||
doc.select("div.playon").remove();
|
|
||||||
String baseUrl = url.replaceAll("(^https?://.*?)(:\\d+)?/.*$", "$1");//https://www.dyk9.com
|
String baseUrl = url.replaceAll("(^https?://.*?)(:\\d+)?/.*$", "$1");//https://www.dyk9.com
|
||||||
String content = doc.body().html();//[\u4e00-\u9fa5]+
|
|
||||||
String VodName = doc.select("head > title").text();
|
|
||||||
Pattern urlder = Pattern.compile(".*-\\d+.html");
|
Pattern urlder = Pattern.compile(".*-\\d+.html");
|
||||||
Pattern urlder2 = Pattern.compile(".*-\\d+-\\d+");
|
Pattern urlder2 = Pattern.compile(".*-\\d+-\\d+");
|
||||||
String uri=null,a=null,b=null,text=null,prefxs=null;
|
String content=null,uri=null,a=null,b=null,hz=null,text=null,prefxs=null;
|
||||||
|
boolean fb = true;
|
||||||
|
Matcher mh = null;
|
||||||
|
if(!url.contains("-")){
|
||||||
|
fetchRule(false, 0);
|
||||||
|
String site2 = siteRule.optString("site2", "");
|
||||||
|
if (site2.contains(typeName)) {//https://www.dyk9.com/vod/detail/11203.html 详情页面再点击一次之后 才有播放地址
|
||||||
|
doc = Jsoup.parse(OkHttpUtil.string(url, Misc.Headers(0,url)));
|
||||||
|
content = doc.body().html();
|
||||||
|
hz=url.replaceAll(".*(\\..*)", "$1");
|
||||||
|
String detailRex = url.replaceAll(".*/(\\d+)\\..*", "$1");
|
||||||
|
mh = Pattern.compile("href=\"(.*/"+detailRex+"-.*"+hz+")\"").matcher(content);
|
||||||
|
while (mh.find()&&fb){
|
||||||
|
fb=false;
|
||||||
|
url = baseUrl+mh.group(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc = Jsoup.parse(OkHttpUtil.string(url, Misc.Headers(0,url)));
|
||||||
|
String VodName = doc.select("head > title").text();
|
||||||
|
doc.select("div.playon").remove();
|
||||||
|
content = doc.body().html();//[\u4e00-\u9fa5]+
|
||||||
if(urlder.matcher(url).find()){//集合多个视频
|
if(urlder.matcher(url).find()){//集合多个视频
|
||||||
String prefxUrl = url.replaceAll("(.*)-\\d+.html", "$1");
|
String prefxUrl = url.replaceAll("(.*)-\\d+.html", "$1");
|
||||||
prefxUrl = prefxUrl.replace(baseUrl, "");// /vod/play/70631-1
|
prefxUrl = prefxUrl.replace(baseUrl, "");// /vod/play/70631-1
|
||||||
@@ -633,7 +687,7 @@ public class PushAgent extends Spider {
|
|||||||
ArrayList<String> playList = new ArrayList<>();
|
ArrayList<String> playList = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
boolean fb = false;
|
fb = false;
|
||||||
if(!content.contains(prefxs+"-"+i+"-"))continue;
|
if(!content.contains(prefxs+"-"+i+"-"))continue;
|
||||||
Map<String, String> m = new LinkedHashMap<>();
|
Map<String, String> m = new LinkedHashMap<>();
|
||||||
Matcher mat = Pattern.compile("href=\"("+prefxs+"-"+i+"-\\d+.html).*?/a>").matcher(content);
|
Matcher mat = Pattern.compile("href=\"("+prefxs+"-"+i+"-\\d+.html).*?/a>").matcher(content);
|
||||||
@@ -774,7 +828,7 @@ public class PushAgent extends Spider {
|
|||||||
result.put("parse", 1);
|
result.put("parse", 1);
|
||||||
result.put("playUrl", "");
|
result.put("playUrl", "");
|
||||||
result.put("url", id);
|
result.put("url", id);
|
||||||
result.put("header", Misc.jHeaders(type,id).toString());
|
result.put("header", Misc.Headers(type,id));
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ import com.github.catvod.crawler.SpiderDebug;
|
|||||||
import com.github.catvod.utils.Misc;
|
import com.github.catvod.utils.Misc;
|
||||||
import com.github.catvod.utils.okhttp.OkHttpUtil;
|
import com.github.catvod.utils.okhttp.OkHttpUtil;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class PushAgentQQ extends Spider {
|
public class PushAgentQQ extends Spider {
|
||||||
private PushAgent pushAgent;
|
private PushAgent pushAgent;
|
||||||
@@ -20,43 +25,16 @@ public class PushAgentQQ extends Spider {
|
|||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
super.init(context, extend);
|
super.init(context, extend);
|
||||||
String token = null;
|
pushAgent = new PushAgent();
|
||||||
|
pushAgent.init(context, extend);
|
||||||
if (extend != null) {
|
if (extend != null) {
|
||||||
if (!extend.startsWith("http")) {
|
if (!extend.startsWith("http")) {
|
||||||
String[] arr = extend.split(";");
|
String[] arr = extend.split(";");
|
||||||
token = arr[0];
|
|
||||||
this.ext = arr[1];
|
this.ext = arr[1];
|
||||||
}else {
|
}else {
|
||||||
this.ext = extend;
|
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
|
@Override
|
||||||
@@ -65,7 +43,7 @@ public class PushAgentQQ extends Spider {
|
|||||||
fetchRule(true);
|
fetchRule(true);
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
JSONArray classes = new JSONArray();
|
JSONArray classes = new JSONArray();
|
||||||
String[] fenleis = getRuleVal(rule,"fenlei", "").split("#");
|
String[] fenleis = pushAgent.getRuleVal(rule,"fenlei", "").split("#");
|
||||||
for (String fenlei : fenleis) {
|
for (String fenlei : fenleis) {
|
||||||
String[] info = fenlei.split("\\$");
|
String[] info = fenlei.split("\\$");
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
@@ -81,16 +59,19 @@ public class PushAgentQQ extends Spider {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
protected JSONObject fetchRule(boolean flag) {
|
||||||
|
rule = pushAgent.fetchRule(flag, 0);
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String homeVideoContent() {
|
public String homeVideoContent() {
|
||||||
try {
|
try {
|
||||||
fetchRule(true);
|
JSONObject jo = pushAgent.fetchRule(true,1);
|
||||||
JSONArray videos = new JSONArray();
|
JSONArray videos = new JSONArray();
|
||||||
String[] fenleis = getRuleVal(rule, "fenlei", "").split("#");
|
String[] fenleis = pushAgent.getRuleVal(jo, "fenlei", "").split("#");
|
||||||
for (String fenlei : fenleis) {
|
for (String fenlei : fenleis) {
|
||||||
String[] info = fenlei.split("\\$");
|
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) {
|
if (data != null) {
|
||||||
JSONArray vids = data.optJSONArray("list");
|
JSONArray vids = data.optJSONArray("list");
|
||||||
if (vids != null) {
|
if (vids != null) {
|
||||||
@@ -111,19 +92,18 @@ public class PushAgentQQ extends Spider {
|
|||||||
return "";
|
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 {
|
try {
|
||||||
fetchRule(true);
|
if (jo == null) jo = pushAgent.fetchRule(true,1);
|
||||||
JSONArray videos = new JSONArray();
|
JSONArray videos = new JSONArray();
|
||||||
|
JSONArray array = jo.getJSONArray(tid);
|
||||||
JSONArray array = rule.getJSONArray(tid);
|
|
||||||
JSONObject jsonObject = null, v = null;
|
JSONObject jsonObject = null, v = null;
|
||||||
String url=null,name=null,pic=null;
|
String url=null,name=null,pic=null;
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
jsonObject = array.getJSONObject(i);
|
jsonObject = array.getJSONObject(i);
|
||||||
url = getRuleVal(jsonObject, "url");
|
url = pushAgent.getRuleVal(jsonObject, "url");
|
||||||
name = getRuleVal(jsonObject, "name");
|
name = pushAgent.getRuleVal(jsonObject, "name");
|
||||||
pic = getRuleVal(jsonObject, "pic");
|
pic = pushAgent.getRuleVal(jsonObject, "pic");
|
||||||
if(pic.equals("")) pic = Misc.getWebName(url, 1);
|
if(pic.equals("")) pic = Misc.getWebName(url, 1);
|
||||||
v = new JSONObject();
|
v = new JSONObject();
|
||||||
v.put("vod_id", url + "$$$" + pic + "$$$" + name);
|
v.put("vod_id", url + "$$$" + pic + "$$$" + name);
|
||||||
@@ -151,7 +131,7 @@ public class PushAgentQQ extends Spider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
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() : "";
|
return obj != null ? obj.toString() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,4 +146,52 @@ public class PushAgentQQ extends Spider {
|
|||||||
return pushAgent.playerContent(str, str2, list);
|
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