Fix init error bug
This commit is contained in:
parent
288863ce80
commit
60b62c99ed
|
|
@ -32,6 +32,7 @@ public class AList extends Spider {
|
||||||
|
|
||||||
private LinkedHashMap<String, String> ext;
|
private LinkedHashMap<String, String> ext;
|
||||||
private Map<String, String> map;
|
private Map<String, String> map;
|
||||||
|
private String extend;
|
||||||
|
|
||||||
private boolean isJson(String json) {
|
private boolean isJson(String json) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -45,6 +46,7 @@ public class AList extends Spider {
|
||||||
private void parseJson(String extend) throws Exception {
|
private void parseJson(String extend) throws Exception {
|
||||||
JSONObject object = new JSONObject(extend);
|
JSONObject object = new JSONObject(extend);
|
||||||
JSONArray array = object.names();
|
JSONArray array = object.names();
|
||||||
|
ext = new LinkedHashMap<>();
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
String key = array.getString(i);
|
String key = array.getString(i);
|
||||||
ext.put(key, object.getString(key));
|
ext.put(key, object.getString(key));
|
||||||
|
|
@ -53,6 +55,7 @@ public class AList extends Spider {
|
||||||
|
|
||||||
private void parseText(String extend) {
|
private void parseText(String extend) {
|
||||||
String[] array = extend.split("#");
|
String[] array = extend.split("#");
|
||||||
|
ext = new LinkedHashMap<>();
|
||||||
for (String text : array) {
|
for (String text : array) {
|
||||||
String[] arr = text.split("\\$");
|
String[] arr = text.split("\\$");
|
||||||
if (arr.length == 2) ext.put(arr[0], arr[1]);
|
if (arr.length == 2) ext.put(arr[0], arr[1]);
|
||||||
|
|
@ -71,20 +74,26 @@ public class AList extends Spider {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fetchRule() throws Exception {
|
||||||
|
if (ext != null && !ext.isEmpty()) return;
|
||||||
|
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
||||||
|
if (isJson(extend)) parseJson(extend);
|
||||||
|
else parseText(extend);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
try {
|
try {
|
||||||
map = new HashMap<>();
|
this.map = new HashMap<>();
|
||||||
ext = new LinkedHashMap<>();
|
this.extend = extend;
|
||||||
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
fetchRule();
|
||||||
if (isJson(extend)) parseJson(extend);
|
|
||||||
else parseText(extend);
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String homeContent(boolean filter) {
|
public String homeContent(boolean filter) throws Exception {
|
||||||
|
fetchRule();
|
||||||
List<Class> classes = new ArrayList<>();
|
List<Class> classes = new ArrayList<>();
|
||||||
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
||||||
for (String key : ext.keySet()) classes.add(new Class(key, key, "1"));
|
for (String key : ext.keySet()) classes.add(new Class(key, key, "1"));
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ public class Ali {
|
||||||
private static String accessToken;
|
private static String accessToken;
|
||||||
private String refreshToken;
|
private String refreshToken;
|
||||||
private ImageView view;
|
private ImageView view;
|
||||||
private int index;
|
|
||||||
|
|
||||||
public Ali(String token) {
|
public Ali(String token) {
|
||||||
if (TextUtils.isEmpty(token)) Init.show("尚未設定 Token");
|
if (TextUtils.isEmpty(token)) Init.show("尚未設定 Token");
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import com.github.catvod.utils.Misc;
|
||||||
import com.github.catvod.utils.Trans;
|
import com.github.catvod.utils.Trans;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
|
||||||
|
|
@ -29,6 +28,7 @@ public class Bili extends Spider {
|
||||||
private static final String url = "https://www.bilibili.com";
|
private static final String url = "https://www.bilibili.com";
|
||||||
private HashMap<String, String> header;
|
private HashMap<String, String> header;
|
||||||
private JSONObject ext;
|
private JSONObject ext;
|
||||||
|
private String extend;
|
||||||
|
|
||||||
private String getCookie(String cookie) {
|
private String getCookie(String cookie) {
|
||||||
if (TextUtils.isEmpty(cookie)) return "buvid3=84B0395D-C9F2-C490-E92E-A09AB48FE26E71636infoc";
|
if (TextUtils.isEmpty(cookie)) return "buvid3=84B0395D-C9F2-C490-E92E-A09AB48FE26E71636infoc";
|
||||||
|
|
@ -36,19 +36,25 @@ public class Bili extends Spider {
|
||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initHeader(JSONObject ext) throws JSONException {
|
private void setHeader() throws Exception {
|
||||||
header = new HashMap<>();
|
|
||||||
header.put("cookie", getCookie(ext.getString("cookie")));
|
header.put("cookie", getCookie(ext.getString("cookie")));
|
||||||
header.put("User-Agent", Misc.CHROME);
|
header.put("User-Agent", Misc.CHROME);
|
||||||
header.put("Referer", url);
|
header.put("Referer", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fetchRule() throws Exception {
|
||||||
|
if (ext != null && !header.isEmpty()) return;
|
||||||
|
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
||||||
|
ext = new JSONObject(extend);
|
||||||
|
setHeader();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
try {
|
try {
|
||||||
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
this.extend = extend;
|
||||||
ext = new JSONObject(extend);
|
this.header = new HashMap<>();
|
||||||
initHeader(ext);
|
fetchRule();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +62,7 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String homeContent(boolean filter) throws Exception {
|
public String homeContent(boolean filter) throws Exception {
|
||||||
|
fetchRule();
|
||||||
return Result.string(Class.arrayFrom(ext.getJSONArray("classes").toString()), ext.getJSONObject("filter"));
|
return Result.string(Class.arrayFrom(ext.getJSONArray("classes").toString()), ext.getJSONObject("filter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
2ea843631a94122807d0765131c5ccb5
|
8db26ed82717e72b5713818e0123a993
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue