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 Map<String, String> map;
|
||||
private String extend;
|
||||
|
||||
private boolean isJson(String json) {
|
||||
try {
|
||||
|
|
@ -45,6 +46,7 @@ public class AList extends Spider {
|
|||
private void parseJson(String extend) throws Exception {
|
||||
JSONObject object = new JSONObject(extend);
|
||||
JSONArray array = object.names();
|
||||
ext = new LinkedHashMap<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
String key = array.getString(i);
|
||||
ext.put(key, object.getString(key));
|
||||
|
|
@ -53,6 +55,7 @@ public class AList extends Spider {
|
|||
|
||||
private void parseText(String extend) {
|
||||
String[] array = extend.split("#");
|
||||
ext = new LinkedHashMap<>();
|
||||
for (String text : array) {
|
||||
String[] arr = text.split("\\$");
|
||||
if (arr.length == 2) ext.put(arr[0], arr[1]);
|
||||
|
|
@ -71,20 +74,26 @@ public class AList extends Spider {
|
|||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
try {
|
||||
map = new HashMap<>();
|
||||
ext = new LinkedHashMap<>();
|
||||
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
|
||||
public void init(Context context, String extend) {
|
||||
try {
|
||||
this.map = new HashMap<>();
|
||||
this.extend = extend;
|
||||
fetchRule();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String homeContent(boolean filter) {
|
||||
public String homeContent(boolean filter) throws Exception {
|
||||
fetchRule();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
||||
for (String key : ext.keySet()) classes.add(new Class(key, key, "1"));
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public class Ali {
|
|||
private static String accessToken;
|
||||
private String refreshToken;
|
||||
private ImageView view;
|
||||
private int index;
|
||||
|
||||
public Ali(String 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 org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
|
|
@ -29,6 +28,7 @@ public class Bili extends Spider {
|
|||
private static final String url = "https://www.bilibili.com";
|
||||
private HashMap<String, String> header;
|
||||
private JSONObject ext;
|
||||
private String extend;
|
||||
|
||||
private String getCookie(String cookie) {
|
||||
if (TextUtils.isEmpty(cookie)) return "buvid3=84B0395D-C9F2-C490-E92E-A09AB48FE26E71636infoc";
|
||||
|
|
@ -36,19 +36,25 @@ public class Bili extends Spider {
|
|||
return cookie;
|
||||
}
|
||||
|
||||
private void initHeader(JSONObject ext) throws JSONException {
|
||||
header = new HashMap<>();
|
||||
private void setHeader() throws Exception {
|
||||
header.put("cookie", getCookie(ext.getString("cookie")));
|
||||
header.put("User-Agent", Misc.CHROME);
|
||||
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
|
||||
public void init(Context context, String extend) {
|
||||
try {
|
||||
if (extend.startsWith("http")) extend = OkHttpUtil.string(extend);
|
||||
ext = new JSONObject(extend);
|
||||
initHeader(ext);
|
||||
this.extend = extend;
|
||||
this.header = new HashMap<>();
|
||||
fetchRule();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -56,6 +62,7 @@ public class Bili extends Spider {
|
|||
|
||||
@Override
|
||||
public String homeContent(boolean filter) throws Exception {
|
||||
fetchRule();
|
||||
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