diff --git a/app/src/main/java/com/github/catvod/spider/PushAgent.java b/app/src/main/java/com/github/catvod/spider/PushAgent.java index 1b44d2b..9ccfa48 100644 --- a/app/src/main/java/com/github/catvod/spider/PushAgent.java +++ b/app/src/main/java/com/github/catvod/spider/PushAgent.java @@ -11,6 +11,7 @@ import com.github.catvod.utils.okhttp.OKCallBack; 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; @@ -42,6 +43,8 @@ public class PushAgent extends Spider { 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 String Token="3a49cf29cf20410997247c6eb4509be9"; + public static JSONObject siteRule = null; + public static String jsonUrl = "http://test.xinjun58.com/sp/d.json"; @Override 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; } @@ -617,14 +652,33 @@ public class PushAgent extends Spider { return getAliContent(list,pic); } else if (url.startsWith("http") && (!matcher.find()) && (!matcher2.find())) { JSONObject vodAtom = new JSONObject(); - Document doc = Jsoup.parse(OkHttpUtil.string(url, Misc.Headers(0,url))); - doc.select("div.playon").remove(); + Document doc = null; 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 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()){//集合多个视频 String prefxUrl = url.replaceAll("(.*)-\\d+.html", "$1"); prefxUrl = prefxUrl.replace(baseUrl, "");// /vod/play/70631-1 @@ -633,7 +687,7 @@ public class PushAgent extends Spider { ArrayList playList = new ArrayList<>(); for (int i = 0; i < 9; i++) { - boolean fb = false; + fb = false; if(!content.contains(prefxs+"-"+i+"-"))continue; Map m = new LinkedHashMap<>(); 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("playUrl", ""); result.put("url", id); - result.put("header", Misc.jHeaders(type,id).toString()); + result.put("header", Misc.Headers(type,id)); return result.toString(); } } catch (Exception e) { diff --git a/app/src/main/java/com/github/catvod/spider/PushAgentQQ.java b/app/src/main/java/com/github/catvod/spider/PushAgentQQ.java index a90c839..7770ad4 100644 --- a/app/src/main/java/com/github/catvod/spider/PushAgentQQ.java +++ b/app/src/main/java/com/github/catvod/spider/PushAgentQQ.java @@ -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 extend) { + private JSONObject category(String tid, String pg, boolean filter, HashMap 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 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 ""; + } } \ No newline at end of file