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: 群友 不负此生
*/
public class AppYsV2 extends Spider {
private String extString = "";
@Override
public void init(Context context, String extend) {
super.init(context, extend);
this.extString = extend;
try {
extInfos = extend.split("###");
} catch (Throwable th) {
}
}
@Override
@ -43,7 +45,7 @@ public class AppYsV2 extends Spider {
JSONArray jsonArray = null;
if (!url.isEmpty()) {
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);
if (obj.has("list") && obj.get("list") instanceof JSONArray) {
jsonArray = obj.getJSONArray("list");
@ -153,7 +155,7 @@ public class AppYsV2 extends Spider {
isTV = true;
}
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);
JSONArray videos = new JSONArray();
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("排序", (extend != null && extend.containsKey("排序")) ? extend.get("排序") : "");
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);
int totalPg = Integer.MAX_VALUE;
try {
@ -278,7 +280,7 @@ public class AppYsV2 extends Spider {
String apiUrl = getApiUrl();
String url = getPlayUrlPrefix(apiUrl) + ids.get(0);
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 result = new JSONObject();
JSONObject vod = new JSONObject();
@ -299,7 +301,7 @@ public class AppYsV2 extends Spider {
String apiUrl = getApiUrl();
String url = getSearchUrl(apiUrl, URLEncoder.encode(key));
//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);
JSONArray jsonArray = null;
JSONArray videos = new JSONArray();
@ -347,8 +349,7 @@ public class AppYsV2 extends Spider {
parseUrls = new ArrayList<>();
String parseUrl = getCustomJxUrl(flag);
if (!parseUrl.isEmpty()) {
parseUrls.clear();
parseUrls.add(parseUrl);
parseUrls.add(0, parseUrl);
}
if (!parseUrls.isEmpty()) {
JSONObject result = getFinalVideo(flag, parseUrls, id);
@ -736,14 +737,28 @@ public class AppYsV2 extends Spider {
JSONObject playList = data.getJSONObject("videolist");
Iterator<String> playListKeys = playList.keys();
while (playListKeys.hasNext()) {
String from = playListKeys.next();
JSONArray playListUrls = playList.getJSONArray(from);
String flag = playListKeys.next();
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<>();
for (int j = 0; j < playListUrls.length(); 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));
}
}
@ -758,7 +773,7 @@ public class AppYsV2 extends Spider {
if (parseUrl.isEmpty() || parseUrl.equals("null"))
continue;
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;
try {
tryJson = Misc.jsonParse(url, content);
@ -804,28 +819,26 @@ public class AppYsV2 extends Spider {
private String getApiUrl() {
String[] urls = extString.split("###");
if (urls.length < 2)
if (extInfos == null || extInfos.length < 2)
return "";
JSONObject siteRule = fetchRule(urls[1].trim());
JSONObject siteRule = fetchRule(extInfos[1].trim());
if (siteRule == null)
return "";
try {
return siteRule.getJSONObject("sites").getJSONObject(urls[0].trim()).getString("url");
return siteRule.getJSONObject("sites").getJSONObject(extInfos[0].trim()).getString("url");
} catch (JSONException e) {
}
return "";
}
private String getCustomJxUrl(String flag) {
String[] urls = extString.split("###");
if (urls.length < 2)
if (extInfos == null || extInfos.length < 2)
return "";
JSONObject siteRule = fetchRule(urls[1].trim());
JSONObject siteRule = fetchRule(extInfos[1].trim());
if (siteRule == null)
return "";
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)
for (int i = 0; i < jxArray.length(); i++) {
JSONArray jxUrls = jxArray.getJSONArray(i);
@ -848,6 +861,8 @@ public class AppYsV2 extends Spider {
return "";
}
private String[] extInfos = null;
private static HashMap<String, JSONObject> rules = new HashMap<>();
private synchronized JSONObject fetchRule(String ruleUrl) {
@ -864,4 +879,10 @@ public class AppYsV2 extends Spider {
return object;
}
protected String desc(String src, byte type) {
if (extInfos.length > 2) {
String descFlag = extInfos[2];
}
return src;
}
}