Clean code
This commit is contained in:
parent
8db7c6a4d3
commit
88c3d0b1ad
|
|
@ -2,10 +2,12 @@ package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
@ -17,7 +19,6 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M浏览器中的App影视
|
* M浏览器中的App影视
|
||||||
* <p>
|
|
||||||
* Author: 群友 不负此生
|
* Author: 群友 不负此生
|
||||||
*/
|
*/
|
||||||
public class AppYsV2 extends Spider {
|
public class AppYsV2 extends Spider {
|
||||||
|
|
@ -27,18 +28,17 @@ public class AppYsV2 extends Spider {
|
||||||
super.init(context, extend);
|
super.init(context, extend);
|
||||||
try {
|
try {
|
||||||
extInfos = extend.split("###");
|
extInfos = extend.split("###");
|
||||||
} catch (Throwable th) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String homeContent(boolean filter) {
|
public String homeContent(boolean filter) throws Exception {
|
||||||
try {
|
|
||||||
String url = getCateUrl(getApiUrl());
|
String url = getCateUrl(getApiUrl());
|
||||||
JSONArray jsonArray = null;
|
JSONArray jsonArray = null;
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
SpiderDebug.log(url);
|
SpiderDebug.log(url);
|
||||||
String json = desc(OkHttp.string(url, getHeaders(url)), (byte) 0);
|
String json = OkHttp.string(url, getHeaders(url));
|
||||||
JSONObject obj = new JSONObject(json);
|
JSONObject obj = new JSONObject(json);
|
||||||
if (obj.has("list") && obj.get("list") instanceof JSONArray) {
|
if (obj.has("list") && obj.get("list") instanceof JSONArray) {
|
||||||
jsonArray = obj.getJSONArray("list");
|
jsonArray = obj.getJSONArray("list");
|
||||||
|
|
@ -53,8 +53,7 @@ public class AppYsV2 extends Spider {
|
||||||
jsonArray = new JSONArray();
|
jsonArray = new JSONArray();
|
||||||
for (int i = 1; i < classes.length; i++) {
|
for (int i = 1; i < classes.length; i++) {
|
||||||
String[] kv = classes[i].trim().split("=");
|
String[] kv = classes[i].trim().split("=");
|
||||||
if (kv.length < 2)
|
if (kv.length < 2) continue;
|
||||||
continue;
|
|
||||||
JSONObject newCls = new JSONObject();
|
JSONObject newCls = new JSONObject();
|
||||||
newCls.put("type_name", kv[0].trim());
|
newCls.put("type_name", kv[0].trim());
|
||||||
newCls.put("type_id", kv[1].trim());
|
newCls.put("type_id", kv[1].trim());
|
||||||
|
|
@ -67,8 +66,6 @@ public class AppYsV2 extends Spider {
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject jObj = jsonArray.getJSONObject(i);
|
JSONObject jObj = jsonArray.getJSONObject(i);
|
||||||
String typeName = jObj.getString("type_name");
|
String typeName = jObj.getString("type_name");
|
||||||
if (isBan(typeName))
|
|
||||||
continue;
|
|
||||||
String typeId = jObj.getString("type_id");
|
String typeId = jObj.getString("type_id");
|
||||||
JSONObject newCls = new JSONObject();
|
JSONObject newCls = new JSONObject();
|
||||||
newCls.put("type_id", typeId);
|
newCls.put("type_id", typeId);
|
||||||
|
|
@ -80,8 +77,7 @@ public class AppYsV2 extends Spider {
|
||||||
JSONArray filterArr = new JSONArray();
|
JSONArray filterArr = new JSONArray();
|
||||||
for (int k = url.isEmpty() ? 1 : 0; k < filters.length; k++) {
|
for (int k = url.isEmpty() ? 1 : 0; k < filters.length; k++) {
|
||||||
String l = filters[k].trim();
|
String l = filters[k].trim();
|
||||||
if (l.isEmpty())
|
if (l.isEmpty()) continue;
|
||||||
continue;
|
|
||||||
String[] oneLine = l.split("\\+");
|
String[] oneLine = l.split("\\+");
|
||||||
String type = oneLine[0].trim();
|
String type = oneLine[0].trim();
|
||||||
String typeN = type;
|
String typeN = type;
|
||||||
|
|
@ -111,14 +107,10 @@ public class AppYsV2 extends Spider {
|
||||||
String kv = oneLine[j].trim();
|
String kv = oneLine[j].trim();
|
||||||
int sp = kv.indexOf("=");
|
int sp = kv.indexOf("=");
|
||||||
if (sp == -1) {
|
if (sp == -1) {
|
||||||
if (isBan(kv))
|
|
||||||
continue;
|
|
||||||
kvo.put("n", kv);
|
kvo.put("n", kv);
|
||||||
kvo.put("v", kv);
|
kvo.put("v", kv);
|
||||||
} else {
|
} else {
|
||||||
String n = kv.substring(0, sp);
|
String n = kv.substring(0, sp);
|
||||||
if (isBan(n))
|
|
||||||
continue;
|
|
||||||
kvo.put("n", n.trim());
|
kvo.put("n", n.trim());
|
||||||
kvo.put("v", kv.substring(sp + 1).trim());
|
kvo.put("v", kv.substring(sp + 1).trim());
|
||||||
}
|
}
|
||||||
|
|
@ -137,15 +129,10 @@ public class AppYsV2 extends Spider {
|
||||||
}
|
}
|
||||||
result.put("class", classes);
|
result.put("class", classes);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String homeVideoContent() {
|
public String homeVideoContent() throws Exception {
|
||||||
try {
|
|
||||||
String apiUrl = getApiUrl();
|
String apiUrl = getApiUrl();
|
||||||
String url = getRecommendUrl(apiUrl);
|
String url = getRecommendUrl(apiUrl);
|
||||||
boolean isTV = false;
|
boolean isTV = false;
|
||||||
|
|
@ -154,7 +141,7 @@ public class AppYsV2 extends Spider {
|
||||||
isTV = true;
|
isTV = true;
|
||||||
}
|
}
|
||||||
SpiderDebug.log(url);
|
SpiderDebug.log(url);
|
||||||
String json = desc(OkHttp.string(url, getHeaders(url)), (byte) 1);
|
String json = OkHttp.string(url, getHeaders(url));
|
||||||
JSONObject obj = new JSONObject(json);
|
JSONObject obj = new JSONObject(json);
|
||||||
JSONArray videos = new JSONArray();
|
JSONArray videos = new JSONArray();
|
||||||
if (isTV) {
|
if (isTV) {
|
||||||
|
|
@ -179,8 +166,7 @@ public class AppYsV2 extends Spider {
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject vObj = jsonArray.getJSONObject(i);
|
JSONObject vObj = jsonArray.getJSONObject(i);
|
||||||
String vid = vObj.getString("vod_id");
|
String vid = vObj.getString("vod_id");
|
||||||
if (ids.contains(vid))
|
if (ids.contains(vid)) continue;
|
||||||
continue;
|
|
||||||
ids.add(vid);
|
ids.add(vid);
|
||||||
JSONObject v = new JSONObject();
|
JSONObject v = new JSONObject();
|
||||||
v.put("vod_id", vid);
|
v.put("vod_id", vid);
|
||||||
|
|
@ -194,15 +180,10 @@ public class AppYsV2 extends Spider {
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("list", videos);
|
result.put("list", videos);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) throws Exception {
|
||||||
try {
|
|
||||||
String apiUrl = getApiUrl();
|
String apiUrl = getApiUrl();
|
||||||
String url = getCateFilterUrlPrefix(apiUrl) + tid + getCateFilterUrlSuffix(apiUrl);
|
String url = getCateFilterUrlPrefix(apiUrl) + tid + getCateFilterUrlSuffix(apiUrl);
|
||||||
url = url.replace("#PN#", pg);
|
url = url.replace("#PN#", pg);
|
||||||
|
|
@ -212,7 +193,7 @@ public class AppYsV2 extends Spider {
|
||||||
url = url.replace("筛选year", (extend != null && extend.containsKey("year")) ? extend.get("year") : "");
|
url = url.replace("筛选year", (extend != null && extend.containsKey("year")) ? extend.get("year") : "");
|
||||||
url = url.replace("排序", (extend != null && extend.containsKey("排序")) ? extend.get("排序") : "");
|
url = url.replace("排序", (extend != null && extend.containsKey("排序")) ? extend.get("排序") : "");
|
||||||
SpiderDebug.log(url);
|
SpiderDebug.log(url);
|
||||||
String json = desc(OkHttp.string(url, getHeaders(url)), (byte) 2);
|
String json = OkHttp.string(url, getHeaders(url));
|
||||||
JSONObject obj = new JSONObject(json);
|
JSONObject obj = new JSONObject(json);
|
||||||
int totalPg = Integer.MAX_VALUE;
|
int totalPg = Integer.MAX_VALUE;
|
||||||
try {
|
try {
|
||||||
|
|
@ -220,9 +201,7 @@ public class AppYsV2 extends Spider {
|
||||||
totalPg = obj.getInt("totalpage");
|
totalPg = obj.getInt("totalpage");
|
||||||
} else if (obj.has("pagecount") && obj.get("pagecount") instanceof Integer) {
|
} else if (obj.has("pagecount") && obj.get("pagecount") instanceof Integer) {
|
||||||
totalPg = obj.getInt("pagecount");
|
totalPg = obj.getInt("pagecount");
|
||||||
} else if (obj.has("data") && obj.get("data") instanceof JSONObject &&
|
} else if (obj.has("data") && obj.get("data") instanceof JSONObject && (obj.getJSONObject("data").has("total") && obj.getJSONObject("data").get("total") instanceof Integer && obj.getJSONObject("data").has("limit") && obj.getJSONObject("data").get("limit") instanceof Integer)) {
|
||||||
(obj.getJSONObject("data").has("total") && obj.getJSONObject("data").get("total") instanceof Integer &&
|
|
||||||
obj.getJSONObject("data").has("limit") && obj.getJSONObject("data").get("limit") instanceof Integer)) {
|
|
||||||
int limit = obj.getJSONObject("data").getInt("limit");
|
int limit = obj.getJSONObject("data").getInt("limit");
|
||||||
int total = obj.getJSONObject("data").getInt("total");
|
int total = obj.getJSONObject("data").getInt("total");
|
||||||
totalPg = total % limit == 0 ? (total / limit) : (total / limit + 1);
|
totalPg = total % limit == 0 ? (total / limit) : (total / limit + 1);
|
||||||
|
|
@ -267,19 +246,14 @@ public class AppYsV2 extends Spider {
|
||||||
result.put("total", Integer.MAX_VALUE);
|
result.put("total", Integer.MAX_VALUE);
|
||||||
result.put("list", videos);
|
result.put("list", videos);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) {
|
public String detailContent(List<String> ids) throws Exception {
|
||||||
try {
|
|
||||||
String apiUrl = getApiUrl();
|
String apiUrl = getApiUrl();
|
||||||
String url = getPlayUrlPrefix(apiUrl) + ids.get(0);
|
String url = getPlayUrlPrefix(apiUrl) + ids.get(0);
|
||||||
SpiderDebug.log(url);
|
SpiderDebug.log(url);
|
||||||
String json = desc(OkHttp.string(url, getHeaders(url)), (byte) 3);
|
String json = OkHttp.string(url, getHeaders(url));
|
||||||
JSONObject obj = new JSONObject(json);
|
JSONObject obj = new JSONObject(json);
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
JSONObject vod = new JSONObject();
|
JSONObject vod = new JSONObject();
|
||||||
|
|
@ -288,18 +262,13 @@ public class AppYsV2 extends Spider {
|
||||||
list.put(vod);
|
list.put(vod);
|
||||||
result.put("list", list);
|
result.put("list", list);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) {
|
public String searchContent(String key, boolean quick) throws Exception {
|
||||||
try {
|
|
||||||
String apiUrl = getApiUrl();
|
String apiUrl = getApiUrl();
|
||||||
String url = getSearchUrl(apiUrl, URLEncoder.encode(key));
|
String url = getSearchUrl(apiUrl, URLEncoder.encode(key));
|
||||||
String json = desc(OkHttp.string(url, getHeaders(url)), (byte) 5);
|
String json = OkHttp.string(url, getHeaders(url));
|
||||||
JSONObject obj = new JSONObject(json);
|
JSONObject obj = new JSONObject(json);
|
||||||
JSONArray jsonArray = null;
|
JSONArray jsonArray = null;
|
||||||
JSONArray videos = new JSONArray();
|
JSONArray videos = new JSONArray();
|
||||||
|
|
@ -333,14 +302,10 @@ public class AppYsV2 extends Spider {
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("list", videos);
|
result.put("list", videos);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
||||||
try {
|
|
||||||
if (flag.contains("fanqie") && Utils.isVideoFormat(id)) {
|
if (flag.contains("fanqie") && Utils.isVideoFormat(id)) {
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("parse", 0);
|
result.put("parse", 0);
|
||||||
|
|
@ -349,12 +314,10 @@ public class AppYsV2 extends Spider {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
ArrayList<String> parseUrls = parseUrlMap.get(flag);
|
ArrayList<String> parseUrls = parseUrlMap.get(flag);
|
||||||
if (parseUrls == null)
|
if (parseUrls == null) parseUrls = new ArrayList<>();
|
||||||
parseUrls = new ArrayList<>();
|
|
||||||
if (!parseUrls.isEmpty()) {
|
if (!parseUrls.isEmpty()) {
|
||||||
JSONObject result = getFinalVideo(flag, parseUrls, id);
|
JSONObject result = getFinalVideo(flag, parseUrls, id);
|
||||||
if (result != null)
|
if (result != null) return result.toString();
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
if (Utils.isVideoFormat(id)) {
|
if (Utils.isVideoFormat(id)) {
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
|
|
@ -369,10 +332,6 @@ public class AppYsV2 extends Spider {
|
||||||
result.put("url", id);
|
result.put("url", id);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
SpiderDebug.log(e);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findJsonArray(JSONObject obj, String match, ArrayList<JSONArray> result) {
|
private void findJsonArray(JSONObject obj, String match, ArrayList<JSONArray> result) {
|
||||||
|
|
@ -381,8 +340,7 @@ public class AppYsV2 extends Spider {
|
||||||
String k = keys.next();
|
String k = keys.next();
|
||||||
try {
|
try {
|
||||||
Object o = obj.get(k);
|
Object o = obj.get(k);
|
||||||
if (k.equals(match) && o instanceof JSONArray)
|
if (k.equals(match) && o instanceof JSONArray) result.add((JSONArray) o);
|
||||||
result.add((JSONArray) o);
|
|
||||||
if (o instanceof JSONObject) {
|
if (o instanceof JSONObject) {
|
||||||
findJsonArray((JSONObject) o, match, result);
|
findJsonArray((JSONObject) o, match, result);
|
||||||
} else if (o instanceof JSONArray) {
|
} else if (o instanceof JSONArray) {
|
||||||
|
|
@ -405,9 +363,9 @@ public class AppYsV2 extends Spider {
|
||||||
}
|
}
|
||||||
return TextUtils.join(",", strings);
|
return TextUtils.join(",", strings);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
}
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getHeaders(String URL) {
|
private HashMap<String, String> getHeaders(String URL) {
|
||||||
HashMap<String, String> headers = new HashMap<>();
|
HashMap<String, String> headers = new HashMap<>();
|
||||||
|
|
@ -415,12 +373,7 @@ public class AppYsV2 extends Spider {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBan(String key) {
|
|
||||||
return key.equals("伦理") || key.equals("情色") || key.equals("福利");
|
|
||||||
}
|
|
||||||
|
|
||||||
// M 扩展方法
|
// M 扩展方法
|
||||||
|
|
||||||
// ######重组搜索
|
// ######重组搜索
|
||||||
private String getSearchUrl(String URL, String KEY) {
|
private String getSearchUrl(String URL, String KEY) {
|
||||||
if (URL.contains(".vod")) {
|
if (URL.contains(".vod")) {
|
||||||
|
|
@ -432,32 +385,7 @@ public class AppYsV2 extends Spider {
|
||||||
} else if (URL.contains("api.php/app") || URL.contains("xgapp")) {
|
} else if (URL.contains("api.php/app") || URL.contains("xgapp")) {
|
||||||
return URL + "search?text=" + KEY + "&pg=";
|
return URL + "search?text=" + KEY + "&pg=";
|
||||||
} else if (urlPattern1.matcher(URL).find()) {
|
} else if (urlPattern1.matcher(URL).find()) {
|
||||||
if (URL.contains("esellauto")
|
if (URL.contains("esellauto") || URL.contains("1.14.63.101") || URL.contains("zjys") || URL.contains("dcd") || URL.contains("lxue") || URL.contains("weetai.cn") || URL.contains("haokanju1") || URL.contains("fit:8") || URL.contains("zjj.life") || URL.contains("love9989") || URL.contains("8d8q") || URL.contains("lk.pxun") || URL.contains("hgyx") || URL.contains("521x5") || URL.contains("lxyyy") || URL.contains("0818tv") || URL.contains("diyoui") || URL.contains("diliktv") || URL.contains("ppzhu") || URL.contains("aitesucai") || URL.contains("zz.ci") || URL.contains("chxjon") || URL.contains("watchmi") || URL.contains("vipbp") || URL.contains("bhtv") || URL.contains("xfykl")) {
|
||||||
|| URL.contains("1.14.63.101")
|
|
||||||
|| URL.contains("zjys")
|
|
||||||
|| URL.contains("dcd")
|
|
||||||
|| URL.contains("lxue")
|
|
||||||
|| URL.contains("weetai.cn")
|
|
||||||
|| URL.contains("haokanju1")
|
|
||||||
|| URL.contains("fit:8")
|
|
||||||
|| URL.contains("zjj.life")
|
|
||||||
|| URL.contains("love9989")
|
|
||||||
|| URL.contains("8d8q")
|
|
||||||
|| URL.contains("lk.pxun")
|
|
||||||
|| URL.contains("hgyx")
|
|
||||||
|| URL.contains("521x5")
|
|
||||||
|| URL.contains("lxyyy")
|
|
||||||
|| URL.contains("0818tv")
|
|
||||||
|| URL.contains("diyoui")
|
|
||||||
|| URL.contains("diliktv")
|
|
||||||
|| URL.contains("ppzhu")
|
|
||||||
|| URL.contains("aitesucai")
|
|
||||||
|| URL.contains("zz.ci")
|
|
||||||
|| URL.contains("chxjon")
|
|
||||||
|| URL.contains("watchmi")
|
|
||||||
|| URL.contains("vipbp")
|
|
||||||
|| URL.contains("bhtv")
|
|
||||||
|| URL.contains("xfykl")) {
|
|
||||||
return URL + "?ac=list&" + "wd=" + KEY + "&page=";
|
return URL + "?ac=list&" + "wd=" + KEY + "&page=";
|
||||||
} else {
|
} else {
|
||||||
return URL + "?ac=list&" + "zm=" + KEY + "&page=";
|
return URL + "?ac=list&" + "zm=" + KEY + "&page=";
|
||||||
|
|
@ -473,15 +401,7 @@ public class AppYsV2 extends Spider {
|
||||||
private static final Pattern parsePattern1 = Pattern.compile(".*(url|v|vid|php\\?id)=");
|
private static final Pattern parsePattern1 = Pattern.compile(".*(url|v|vid|php\\?id)=");
|
||||||
private static final Pattern parsePattern2 = Pattern.compile("https?://[^/]*");
|
private static final Pattern parsePattern2 = Pattern.compile("https?://[^/]*");
|
||||||
|
|
||||||
protected static final Pattern[] htmlVideoKeyMatch = new Pattern[]{
|
protected static final Pattern[] htmlVideoKeyMatch = new Pattern[]{Pattern.compile("player=new"), Pattern.compile("<div id=\"video\""), Pattern.compile("<div id=\"[^\"]*?player\""), Pattern.compile("//视频链接"), Pattern.compile("HlsJsPlayer\\("), Pattern.compile("<iframe[\\s\\S]*?src=\"[^\"]+?\""), Pattern.compile("<video[\\s\\S]*?src=\"[^\"]+?\"")};
|
||||||
Pattern.compile("player=new"),
|
|
||||||
Pattern.compile("<div id=\"video\""),
|
|
||||||
Pattern.compile("<div id=\"[^\"]*?player\""),
|
|
||||||
Pattern.compile("//视频链接"),
|
|
||||||
Pattern.compile("HlsJsPlayer\\("),
|
|
||||||
Pattern.compile("<iframe[\\s\\S]*?src=\"[^\"]+?\""),
|
|
||||||
Pattern.compile("<video[\\s\\S]*?src=\"[^\"]+?\"")
|
|
||||||
};
|
|
||||||
|
|
||||||
private String UA(String URL) {
|
private String UA(String URL) {
|
||||||
if (URL.contains("vod.9e03.com")) {
|
if (URL.contains("vod.9e03.com")) {
|
||||||
|
|
@ -626,8 +546,7 @@ public class AppYsV2 extends Spider {
|
||||||
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
||||||
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
||||||
String flag = from.optString("code").trim();
|
String flag = from.optString("code").trim();
|
||||||
if (flag.isEmpty())
|
if (flag.isEmpty()) flag = from.getString("name").trim();
|
||||||
flag = from.getString("name").trim();
|
|
||||||
playFlags.add(flag);
|
playFlags.add(flag);
|
||||||
playUrls.add(from.getString("url"));
|
playUrls.add(from.getString("url"));
|
||||||
String purl = from.optString("parse_api").trim();
|
String purl = from.optString("parse_api").trim();
|
||||||
|
|
@ -636,8 +555,7 @@ public class AppYsV2 extends Spider {
|
||||||
parseUrls = new ArrayList<>();
|
parseUrls = new ArrayList<>();
|
||||||
parseUrlMap.put(flag, parseUrls);
|
parseUrlMap.put(flag, parseUrls);
|
||||||
}
|
}
|
||||||
if (!purl.isEmpty() && !parseUrls.contains(purl))
|
if (!purl.isEmpty() && !parseUrls.contains(purl)) parseUrls.add(purl);
|
||||||
parseUrls.add(purl);
|
|
||||||
}
|
}
|
||||||
} else if (URL.contains("xgapp")) {
|
} else if (URL.contains("xgapp")) {
|
||||||
JSONObject data = object.getJSONObject("data").getJSONObject("vod_info");
|
JSONObject data = object.getJSONObject("data").getJSONObject("vod_info");
|
||||||
|
|
@ -655,8 +573,7 @@ public class AppYsV2 extends Spider {
|
||||||
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
||||||
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
||||||
String flag = from.optString("code").trim();
|
String flag = from.optString("code").trim();
|
||||||
if (flag.isEmpty())
|
if (flag.isEmpty()) flag = from.getString("name").trim();
|
||||||
flag = from.getString("name").trim();
|
|
||||||
playFlags.add(flag);
|
playFlags.add(flag);
|
||||||
playUrls.add(from.getString("url"));
|
playUrls.add(from.getString("url"));
|
||||||
String purl = from.optString("parse_api").trim();
|
String purl = from.optString("parse_api").trim();
|
||||||
|
|
@ -665,8 +582,7 @@ public class AppYsV2 extends Spider {
|
||||||
parseUrls = new ArrayList<>();
|
parseUrls = new ArrayList<>();
|
||||||
parseUrlMap.put(flag, parseUrls);
|
parseUrlMap.put(flag, parseUrls);
|
||||||
}
|
}
|
||||||
if (!purl.isEmpty() && !parseUrls.contains(purl))
|
if (!purl.isEmpty() && !parseUrls.contains(purl)) parseUrls.add(purl);
|
||||||
parseUrls.add(purl);
|
|
||||||
}
|
}
|
||||||
} else if (/*urlPattern2.matcher(URL).find()*/URL.contains(".vod")) {
|
} else if (/*urlPattern2.matcher(URL).find()*/URL.contains(".vod")) {
|
||||||
JSONObject data = object.getJSONObject("data");
|
JSONObject data = object.getJSONObject("data");
|
||||||
|
|
@ -684,8 +600,7 @@ public class AppYsV2 extends Spider {
|
||||||
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
for (int i = 0; i < vodUrlWithPlayer.length(); i++) {
|
||||||
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
JSONObject from = vodUrlWithPlayer.getJSONObject(i);
|
||||||
String flag = from.getJSONObject("player_info").optString("from").trim();
|
String flag = from.getJSONObject("player_info").optString("from").trim();
|
||||||
if (flag.isEmpty())
|
if (flag.isEmpty()) flag = from.getJSONObject("player_info").optString("show").trim();
|
||||||
flag = from.getJSONObject("player_info").optString("show").trim();
|
|
||||||
playFlags.add(flag);
|
playFlags.add(flag);
|
||||||
playUrls.add(from.getString("url"));
|
playUrls.add(from.getString("url"));
|
||||||
try {
|
try {
|
||||||
|
|
@ -720,8 +635,7 @@ public class AppYsV2 extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
purl = purl.replace("..", ".").trim();
|
purl = purl.replace("..", ".").trim();
|
||||||
if (!purl.isEmpty() && !parseUrls.contains(purl))
|
if (!purl.isEmpty() && !parseUrls.contains(purl)) parseUrls.add(purl);
|
||||||
parseUrls.add(purl);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SpiderDebug.log(e);
|
SpiderDebug.log(e);
|
||||||
|
|
@ -756,8 +670,7 @@ public class AppYsV2 extends Spider {
|
||||||
if (url.contains("url=")) {
|
if (url.contains("url=")) {
|
||||||
int spIdx = url.indexOf("url=") + 4;
|
int spIdx = url.indexOf("url=") + 4;
|
||||||
String pUrl = url.substring(0, spIdx).trim();
|
String pUrl = url.substring(0, spIdx).trim();
|
||||||
if (!pUrl.isEmpty() && !parseUrls.contains(pUrl))
|
if (!pUrl.isEmpty() && !parseUrls.contains(pUrl)) parseUrls.add(pUrl);
|
||||||
parseUrls.add(pUrl);
|
|
||||||
urls.add(urlObj.getString("title") + "$" + url.substring(spIdx).trim());
|
urls.add(urlObj.getString("title") + "$" + url.substring(spIdx).trim());
|
||||||
} else {
|
} else {
|
||||||
urls.add(urlObj.getString("title") + "$" + url);
|
urls.add(urlObj.getString("title") + "$" + url);
|
||||||
|
|
@ -775,10 +688,9 @@ public class AppYsV2 extends Spider {
|
||||||
protected JSONObject getFinalVideo(String flag, ArrayList<String> parseUrls, String url) throws JSONException {
|
protected JSONObject getFinalVideo(String flag, ArrayList<String> parseUrls, String url) throws JSONException {
|
||||||
String htmlPlayUrl = "";
|
String htmlPlayUrl = "";
|
||||||
for (String parseUrl : parseUrls) {
|
for (String parseUrl : parseUrls) {
|
||||||
if (parseUrl.isEmpty() || parseUrl.equals("null"))
|
if (parseUrl.isEmpty() || parseUrl.equals("null")) continue;
|
||||||
continue;
|
|
||||||
String playUrl = parseUrl + url;
|
String playUrl = parseUrl + url;
|
||||||
String content = desc(OkHttp.string(playUrl, null), (byte) 4);
|
String content = OkHttp.string(playUrl);
|
||||||
JSONObject tryJson = null;
|
JSONObject tryJson = null;
|
||||||
try {
|
try {
|
||||||
tryJson = jsonParse(url, content);
|
tryJson = jsonParse(url, content);
|
||||||
|
|
@ -823,20 +735,12 @@ public class AppYsV2 extends Spider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiUrl() {
|
private String getApiUrl() {
|
||||||
if (extInfos == null || extInfos.length < 1)
|
if (extInfos == null || extInfos.length < 1) return "";
|
||||||
return "";
|
|
||||||
return extInfos[0].trim();
|
return extInfos[0].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] extInfos = null;
|
private String[] extInfos = null;
|
||||||
|
|
||||||
protected String desc(String src, byte type) {
|
|
||||||
if (extInfos.length > 1) {
|
|
||||||
String descFlag = extInfos[1];
|
|
||||||
}
|
|
||||||
return src;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JSONObject jsonParse(String input, String json) throws JSONException {
|
public static JSONObject jsonParse(String input, String json) throws JSONException {
|
||||||
//处理解析接口返回的报文,如果返回的报文中包含header信息,就加到返回值中
|
//处理解析接口返回的报文,如果返回的报文中包含header信息,就加到返回值中
|
||||||
JSONObject jsonPlayData = new JSONObject(json);
|
JSONObject jsonPlayData = new JSONObject(json);
|
||||||
|
|
@ -861,21 +765,17 @@ public class AppYsV2 extends Spider {
|
||||||
JSONObject headers = new JSONObject();
|
JSONObject headers = new JSONObject();
|
||||||
if (jsonPlayData.has("header")) {
|
if (jsonPlayData.has("header")) {
|
||||||
headers = jsonPlayData.optJSONObject("header");
|
headers = jsonPlayData.optJSONObject("header");
|
||||||
}
|
} else if (jsonPlayData.has("Header")) {
|
||||||
else if (jsonPlayData.has("Header")) {
|
|
||||||
headers = jsonPlayData.optJSONObject("Header");
|
headers = jsonPlayData.optJSONObject("Header");
|
||||||
}
|
} else if (jsonPlayData.has("headers")) {
|
||||||
else if (jsonPlayData.has("headers")) {
|
|
||||||
headers = jsonPlayData.optJSONObject("headers");
|
headers = jsonPlayData.optJSONObject("headers");
|
||||||
}
|
} else if (jsonPlayData.has("Headers")) {
|
||||||
else if (jsonPlayData.has("Headers")) {
|
|
||||||
headers = jsonPlayData.optJSONObject("Headers");
|
headers = jsonPlayData.optJSONObject("Headers");
|
||||||
}
|
}
|
||||||
String ua = "";
|
String ua = "";
|
||||||
if (jsonPlayData.has("user-agent")) {
|
if (jsonPlayData.has("user-agent")) {
|
||||||
ua = jsonPlayData.optString("user-agent", "");
|
ua = jsonPlayData.optString("user-agent", "");
|
||||||
}
|
} else if (jsonPlayData.has("User-Agent")) {
|
||||||
else if (jsonPlayData.has("User-Agent")) {
|
|
||||||
ua = jsonPlayData.optString("User-Agent", "");
|
ua = jsonPlayData.optString("User-Agent", "");
|
||||||
}
|
}
|
||||||
if (ua.trim().length() > 0) {
|
if (ua.trim().length() > 0) {
|
||||||
|
|
@ -884,8 +784,7 @@ public class AppYsV2 extends Spider {
|
||||||
String referer = "";
|
String referer = "";
|
||||||
if (jsonPlayData.has("referer")) {
|
if (jsonPlayData.has("referer")) {
|
||||||
referer = jsonPlayData.optString("referer", "");
|
referer = jsonPlayData.optString("referer", "");
|
||||||
}
|
} else if (jsonPlayData.has("Referer")) {
|
||||||
else if (jsonPlayData.has("Referer")) {
|
|
||||||
referer = jsonPlayData.optString("Referer", "");
|
referer = jsonPlayData.optString("Referer", "");
|
||||||
}
|
}
|
||||||
if (referer.trim().length() > 0) {
|
if (referer.trim().length() > 0) {
|
||||||
|
|
@ -901,8 +800,7 @@ public class AppYsV2 extends Spider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject fixJsonVodHeader(JSONObject headers, String input, String url) throws JSONException {
|
public static JSONObject fixJsonVodHeader(JSONObject headers, String input, String url) throws JSONException {
|
||||||
if (headers == null)
|
if (headers == null) headers = new JSONObject();
|
||||||
headers = new JSONObject();
|
|
||||||
if (input.contains("www.mgtv.com")) {
|
if (input.contains("www.mgtv.com")) {
|
||||||
headers.put("Referer", " ");
|
headers.put("Referer", " ");
|
||||||
headers.put("User-Agent", " Mozilla/5.0");
|
headers.put("User-Agent", " Mozilla/5.0");
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ public class Proxy extends Spider {
|
||||||
switch (params.get("do")) {
|
switch (params.get("do")) {
|
||||||
case "ck":
|
case "ck":
|
||||||
return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))};
|
return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))};
|
||||||
case "yingshi":
|
|
||||||
return YingShi.vod(params);
|
|
||||||
case "ali":
|
case "ali":
|
||||||
return Ali.proxy(params);
|
return Ali.proxy(params);
|
||||||
case "bili":
|
case "bili":
|
||||||
|
|
|
||||||
|
|
@ -7,30 +7,26 @@ import com.github.catvod.bean.Class;
|
||||||
import com.github.catvod.bean.Filter;
|
import com.github.catvod.bean.Filter;
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.bean.webdav.Drive;
|
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
import com.github.catvod.utils.FileUtil;
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class YingShi extends Spider {
|
public class YingShi extends Spider {
|
||||||
|
|
||||||
|
|
@ -114,8 +110,7 @@ public class YingShi extends Spider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
||||||
String proxyUrl = Proxy.getUrl() + "?do=yingshi&url=" + id;
|
return Result.get().url(id).string();
|
||||||
return Result.get().url(proxyUrl).string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -169,30 +164,4 @@ public class YingShi extends Spider {
|
||||||
return new Filter(key, name, values);
|
return new Filter(key, name, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object[] vod(Map<String, String> params) throws Exception {
|
|
||||||
String url = params.get("url");
|
|
||||||
List<String> AdBlock = Arrays.asList("10.0099", "8.1748"); // Advertisement ts
|
|
||||||
String content = OkHttp.string(url);
|
|
||||||
Matcher m = Pattern.compile("#EXT-X-DISCONTINUITY[\\s\\S]*?(?=#EXT-X-DISCONTINUITY|$)").matcher(content);
|
|
||||||
while (m.find()) {
|
|
||||||
BigDecimal k = BigDecimal.ZERO;
|
|
||||||
Matcher digit = Pattern.compile("#EXTINF:(\\d+\\.\\d+)").matcher(m.group(0));
|
|
||||||
while (digit.find()) {
|
|
||||||
BigDecimal g = new BigDecimal(digit.group(1));
|
|
||||||
k = k.add(g);
|
|
||||||
}
|
|
||||||
for (String ads : AdBlock) {
|
|
||||||
if (k.toString().contains(ads)) {
|
|
||||||
content = content.replaceAll(m.group(0), "");
|
|
||||||
System.out.println("Found ads: " + ads);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object[] result = new Object[3];
|
|
||||||
result[0] = 200;
|
|
||||||
result[1] = "application/octet-stream";
|
|
||||||
result[2] = new ByteArrayInputStream(content.getBytes());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
e99f254a76be4612aaf4f8e6eef5dae1
|
805e97263746889cf1405e74ec9d0824
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue