AppYsV2 Test.

This commit is contained in:
小黄瓜 2022-02-24 10:21:46 +08:00
parent a73faaf3df
commit 6d2f97ff17
1 changed files with 43 additions and 22 deletions

View File

@ -28,12 +28,14 @@ import java.util.regex.Pattern;
* Author: 群友 不负此生 * Author: 群友 不负此生
*/ */
public class AppYsV2 extends Spider { public class AppYsV2 extends Spider {
private String extString = "";
@Override @Override
public void init(Context context, String extend) { public void init(Context context, String extend) {
super.init(context, extend); super.init(context, extend);
this.extString = extend; try {
extInfos = extend.split("###");
} catch (Throwable th) {
}
} }
@Override @Override
@ -43,7 +45,7 @@ public class AppYsV2 extends Spider {
JSONArray jsonArray = null; JSONArray jsonArray = null;
if (!url.isEmpty()) { if (!url.isEmpty()) {
SpiderDebug.log(url); SpiderDebug.log(url);
String json = SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content; String json = desc(SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content, (byte) 0);
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");
@ -153,7 +155,7 @@ public class AppYsV2 extends Spider {
isTV = true; isTV = true;
} }
SpiderDebug.log(url); SpiderDebug.log(url);
String json = SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content; String json = desc(SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content, (byte) 1);
JSONObject obj = new JSONObject(json); JSONObject obj = new JSONObject(json);
JSONArray videos = new JSONArray(); JSONArray videos = new JSONArray();
if (isTV) { if (isTV) {
@ -211,7 +213,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 = SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content; String json = desc(SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content, (byte) 2);
JSONObject obj = new JSONObject(json); JSONObject obj = new JSONObject(json);
int totalPg = Integer.MAX_VALUE; int totalPg = Integer.MAX_VALUE;
try { try {
@ -278,7 +280,7 @@ public class AppYsV2 extends Spider {
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 = SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content; String json = desc(SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content, (byte) 3);
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();
@ -299,7 +301,7 @@ public class AppYsV2 extends Spider {
String apiUrl = getApiUrl(); String apiUrl = getApiUrl();
String url = getSearchUrl(apiUrl, URLEncoder.encode(key)); String url = getSearchUrl(apiUrl, URLEncoder.encode(key));
//System.out.println(url); //System.out.println(url);
String json = SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content; String json = desc(SpiderReq.get(new SpiderUrl(url, getHeaders(url))).content, (byte) 5);
JSONObject obj = new JSONObject(json); JSONObject obj = new JSONObject(json);
JSONArray jsonArray = null; JSONArray jsonArray = null;
JSONArray videos = new JSONArray(); JSONArray videos = new JSONArray();
@ -347,8 +349,7 @@ public class AppYsV2 extends Spider {
parseUrls = new ArrayList<>(); parseUrls = new ArrayList<>();
String parseUrl = getCustomJxUrl(flag); String parseUrl = getCustomJxUrl(flag);
if (!parseUrl.isEmpty()) { if (!parseUrl.isEmpty()) {
parseUrls.clear(); parseUrls.add(0, parseUrl);
parseUrls.add(parseUrl);
} }
if (!parseUrls.isEmpty()) { if (!parseUrls.isEmpty()) {
JSONObject result = getFinalVideo(flag, parseUrls, id); JSONObject result = getFinalVideo(flag, parseUrls, id);
@ -736,14 +737,28 @@ public class AppYsV2 extends Spider {
JSONObject playList = data.getJSONObject("videolist"); JSONObject playList = data.getJSONObject("videolist");
Iterator<String> playListKeys = playList.keys(); Iterator<String> playListKeys = playList.keys();
while (playListKeys.hasNext()) { while (playListKeys.hasNext()) {
String from = playListKeys.next(); String flag = playListKeys.next();
JSONArray playListUrls = playList.getJSONArray(from); ArrayList<String> parseUrls = parseUrlMap.get(flag);
if (parseUrls == null) {
parseUrls = new ArrayList<>();
parseUrlMap.put(flag, parseUrls);
}
JSONArray playListUrls = playList.getJSONArray(flag);
ArrayList<String> urls = new ArrayList<>(); ArrayList<String> urls = new ArrayList<>();
for (int j = 0; j < playListUrls.length(); j++) { for (int j = 0; j < playListUrls.length(); j++) {
JSONObject urlObj = playListUrls.getJSONObject(j); JSONObject urlObj = playListUrls.getJSONObject(j);
urls.add(urlObj.getString("title") + "$" + urlObj.getString("url")); String url = urlObj.getString("url");
if (url.contains("url=")) {
int spIdx = url.indexOf("url=") + 4;
String pUrl = url.substring(0, spIdx).trim();
if (!pUrl.isEmpty() && !parseUrls.contains(pUrl))
parseUrls.add(pUrl);
urls.add(urlObj.getString("title") + "$" + url.substring(spIdx).trim());
} else {
urls.add(urlObj.getString("title") + "$" + url);
}
} }
playFlags.add(from); playFlags.add(flag);
playUrls.add(TextUtils.join("#", urls)); playUrls.add(TextUtils.join("#", urls));
} }
} }
@ -758,7 +773,7 @@ public class AppYsV2 extends Spider {
if (parseUrl.isEmpty() || parseUrl.equals("null")) if (parseUrl.isEmpty() || parseUrl.equals("null"))
continue; continue;
String playUrl = parseUrl + url; String playUrl = parseUrl + url;
String content = SpiderReq.get(new SpiderUrl(playUrl, null)).content; String content = desc(SpiderReq.get(new SpiderUrl(playUrl, null)).content, (byte) 4);
JSONObject tryJson = null; JSONObject tryJson = null;
try { try {
tryJson = Misc.jsonParse(url, content); tryJson = Misc.jsonParse(url, content);
@ -804,28 +819,26 @@ public class AppYsV2 extends Spider {
private String getApiUrl() { private String getApiUrl() {
String[] urls = extString.split("###"); if (extInfos == null || extInfos.length < 2)
if (urls.length < 2)
return ""; return "";
JSONObject siteRule = fetchRule(urls[1].trim()); JSONObject siteRule = fetchRule(extInfos[1].trim());
if (siteRule == null) if (siteRule == null)
return ""; return "";
try { try {
return siteRule.getJSONObject("sites").getJSONObject(urls[0].trim()).getString("url"); return siteRule.getJSONObject("sites").getJSONObject(extInfos[0].trim()).getString("url");
} catch (JSONException e) { } catch (JSONException e) {
} }
return ""; return "";
} }
private String getCustomJxUrl(String flag) { private String getCustomJxUrl(String flag) {
String[] urls = extString.split("###"); if (extInfos == null || extInfos.length < 2)
if (urls.length < 2)
return ""; return "";
JSONObject siteRule = fetchRule(urls[1].trim()); JSONObject siteRule = fetchRule(extInfos[1].trim());
if (siteRule == null) if (siteRule == null)
return ""; return "";
try { try {
JSONArray jxArray = siteRule.getJSONObject("sites").getJSONObject(urls[0].trim()).optJSONArray("jx"); JSONArray jxArray = siteRule.getJSONObject("sites").getJSONObject(extInfos[0].trim()).optJSONArray("jx");
if (jxArray != null) if (jxArray != null)
for (int i = 0; i < jxArray.length(); i++) { for (int i = 0; i < jxArray.length(); i++) {
JSONArray jxUrls = jxArray.getJSONArray(i); JSONArray jxUrls = jxArray.getJSONArray(i);
@ -848,6 +861,8 @@ public class AppYsV2 extends Spider {
return ""; return "";
} }
private String[] extInfos = null;
private static HashMap<String, JSONObject> rules = new HashMap<>(); private static HashMap<String, JSONObject> rules = new HashMap<>();
private synchronized JSONObject fetchRule(String ruleUrl) { private synchronized JSONObject fetchRule(String ruleUrl) {
@ -864,4 +879,10 @@ public class AppYsV2 extends Spider {
return object; return object;
} }
protected String desc(String src, byte type) {
if (extInfos.length > 2) {
String descFlag = extInfos[2];
}
return src;
}
} }