add - bili55
This commit is contained in:
@@ -6,7 +6,6 @@ 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 java.util.HashMap;
|
||||
@@ -21,16 +20,43 @@ public class PushAgentQQ extends Spider {
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
super.init(context, extend);
|
||||
pushAgent = new PushAgent();
|
||||
pushAgent.init(context, extend);
|
||||
String token = null;
|
||||
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
|
||||
@@ -39,7 +65,7 @@ public class PushAgentQQ extends Spider {
|
||||
fetchRule(true);
|
||||
JSONObject result = new JSONObject();
|
||||
JSONArray classes = new JSONArray();
|
||||
String[] fenleis = pushAgent.getRuleVal(rule,"fenlei", "").split("#");
|
||||
String[] fenleis = getRuleVal(rule,"fenlei", "").split("#");
|
||||
for (String fenlei : fenleis) {
|
||||
String[] info = fenlei.split("\\$");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -55,19 +81,16 @@ public class PushAgentQQ extends Spider {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
protected JSONObject fetchRule(boolean flag) {
|
||||
rule = pushAgent.fetchRule(flag, 0);
|
||||
return rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String homeVideoContent() {
|
||||
try {
|
||||
JSONObject jo = pushAgent.fetchRule(true,1);
|
||||
fetchRule(true);
|
||||
JSONArray videos = new JSONArray();
|
||||
String[] fenleis = pushAgent.getRuleVal(jo, "fenlei", "").split("#");
|
||||
String[] fenleis = getRuleVal(rule, "fenlei", "").split("#");
|
||||
for (String fenlei : fenleis) {
|
||||
String[] info = fenlei.split("\\$");
|
||||
JSONObject data = category(info[1], "1", false, new HashMap<>(),jo);
|
||||
JSONObject data = category(info[1], "1", false, new HashMap<>());
|
||||
if (data != null) {
|
||||
JSONArray vids = data.optJSONArray("list");
|
||||
if (vids != null) {
|
||||
@@ -88,35 +111,35 @@ public class PushAgentQQ extends Spider {
|
||||
return "";
|
||||
}
|
||||
|
||||
private JSONObject category(String tid, String pg, boolean filter, HashMap<String, String> extend,JSONObject jo) {
|
||||
private JSONObject category(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
||||
try {
|
||||
if (jo == null) jo = pushAgent.fetchRule(true,1);
|
||||
fetchRule(true);
|
||||
JSONArray videos = new JSONArray();
|
||||
JSONArray array = jo.getJSONArray(tid);
|
||||
|
||||
JSONArray array = rule.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 = pushAgent.getRuleVal(jsonObject, "url");
|
||||
name = pushAgent.getRuleVal(jsonObject, "name");
|
||||
pic = pushAgent.getRuleVal(jsonObject, "pic");
|
||||
if(pic.equals("")) pic = Misc.getWebName(url, 1);
|
||||
url = getRuleVal(jsonObject, "url");
|
||||
name = getRuleVal(jsonObject, "name");
|
||||
pic = getRuleVal(jsonObject, "pic");
|
||||
v = new JSONObject();
|
||||
v.put("vod_id", url + "$$$" + pic + "$$$" + name);
|
||||
v.put("vod_name", name);
|
||||
v.put("vod_pic", pic);
|
||||
v.put("vod_remarks", Misc.getWebName(url,0));
|
||||
v.put("vod_remarks", Misc.getWebName(url));
|
||||
videos.put(v);
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
int limit = 20;int total = videos.length();
|
||||
int limit = 20;
|
||||
int page = Integer.parseInt(pg);
|
||||
result.put("page", page);
|
||||
int pageCount = (int)Math.ceil((double)total/limit);
|
||||
int pageCount = videos.length() == limit ? page + 1 : page;
|
||||
result.put("pagecount", pageCount);
|
||||
result.put("limit", limit);
|
||||
result.put("total", total);
|
||||
result.put("total", Integer.MAX_VALUE);
|
||||
result.put("list", videos);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
@@ -127,7 +150,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,null);
|
||||
JSONObject obj = category(tid, pg, filter, extend);
|
||||
return obj != null ? obj.toString() : "";
|
||||
}
|
||||
|
||||
@@ -142,57 +165,4 @@ public class PushAgentQQ extends Spider {
|
||||
return pushAgent.playerContent(str, str2, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchContent(String key, boolean quick) {
|
||||
if (key.equals("000")) {
|
||||
PushAgent.type=0;
|
||||
}if (key.equals("111")) {
|
||||
PushAgent.type=1;
|
||||
}
|
||||
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", "");
|
||||
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