Support alist login

This commit is contained in:
FongMi 2023-05-17 15:00:49 +08:00
parent 0894614b03
commit f68ef4b1aa
5 changed files with 79 additions and 14 deletions

View File

@ -18,14 +18,16 @@ public class Drive {
@SerializedName("drives")
private List<Drive> drives;
@SerializedName("params")
private Map<String, String> params;
@SerializedName("login")
private Login login;
@SerializedName("vodPic")
private String vodPic;
@SerializedName("name")
private String name;
@SerializedName("server")
private String server;
@SerializedName("password")
private String password;
@SerializedName("version")
private int version;
@SerializedName("path")
@ -39,6 +41,14 @@ public class Drive {
return drives == null ? new ArrayList<>() : drives;
}
public Map<String, String> getParams() {
return params == null ? new HashMap<>() : params;
}
public Login getLogin() {
return login;
}
public Drive(String name) {
this.name = name;
}
@ -55,10 +65,6 @@ public class Drive {
return TextUtils.isEmpty(server) ? "" : server;
}
public String getPassword() {
return TextUtils.isEmpty(password) ? "" : password;
}
public int getVersion() {
return version;
}
@ -91,6 +97,10 @@ public class Drive {
return getHost() + "/api/public/settings";
}
public String loginApi() {
return getHost() + "/api/auth/login";
}
public String listApi() {
return getHost() + (isNew() ? "/api/fs/list" : "/api/public/path");
}

View File

@ -0,0 +1,21 @@
package com.github.catvod.bean.alist;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
public class Login {
@SerializedName("username")
private String username;
@SerializedName("password")
private String password;
public String getUsername() {
return TextUtils.isEmpty(username) ? "" : username;
}
public String getPassword() {
return TextUtils.isEmpty(password) ? "" : password;
}
}

View File

@ -30,6 +30,7 @@ public class AList extends Spider {
private List<Drive> drives;
private String vodPic;
private String token;
private String ext;
private List<Filter> getFilter() {
@ -51,6 +52,23 @@ public class AList extends Spider {
return drives.get(drives.indexOf(new Drive(name))).check();
}
public HashMap<String, String> getHeader() {
HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME);
if (token != null) headers.put("Authorization", token);
return headers;
}
private String post(Drive drive, String url, String param) {
return post(drive, url, param, true);
}
private String post(Drive drive, String url, String param, boolean retry) {
String response = OkHttp.postJson(url, param, getHeader()).getBody();
if (retry && response.contains("Guest user is disabled") && login(drive)) return post(drive, url, param, false);
return response;
}
@Override
public void init(Context context, String extend) {
try {
@ -132,15 +150,30 @@ public class AList extends Spider {
return Result.get().url(getDetail(ids[0]).getUrl()).subs(getSub(ids)).string();
}
private boolean login(Drive drive) {
try {
JSONObject params = new JSONObject();
params.put("username", drive.getLogin().getUsername());
params.put("password", drive.getLogin().getPassword());
String response = OkHttp.postJson(drive.loginApi(), params.toString()).getBody();
token = new JSONObject(response).getJSONObject("data").getString("token");
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private Item getDetail(String id) {
try {
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
Drive drive = getDrive(key);
path = path.startsWith(drive.getPath()) ? path : drive.getPath() + path;
JSONObject params = new JSONObject();
params.put("password", drive.getPassword());
params.put("path", path.startsWith(drive.getPath()) ? path : drive.getPath() + path);
String response = OkHttp.postJson(drive.getApi(), params.toString()).getBody();
params.put("path", path);
params.put("password", drive.getParams().get(path));
String response = post(drive, drive.getApi(), params.toString());
return Item.objectFrom(getDetailJson(drive.isNew(), response));
} catch (Exception e) {
return new Item();
@ -152,10 +185,11 @@ public class AList extends Spider {
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
Drive drive = getDrive(key);
path = path.startsWith(drive.getPath()) ? path : drive.getPath() + path;
JSONObject params = new JSONObject();
params.put("password", drive.getPassword());
params.put("path", path.startsWith(drive.getPath()) ? path : drive.getPath() + path);
String response = OkHttp.postJson(drive.listApi(), params.toString()).getBody();
params.put("path", path);
params.put("password", drive.getParams().get(path));
String response = post(drive, drive.listApi(), params.toString());
List<Item> items = Item.arrayFrom(getListJson(drive.isNew(), response));
Iterator<Item> iterator = items.iterator();
if (filter) while (iterator.hasNext()) if (iterator.next().ignore(drive.isNew())) iterator.remove();
@ -167,7 +201,7 @@ public class AList extends Spider {
private void search(CountDownLatch cd, List<Vod> list, Drive drive, String keyword) {
try {
String response = OkHttp.postJson(drive.searchApi(), drive.params(keyword)).getBody();
String response = post(drive, drive.searchApi(), drive.params(keyword));
List<Item> items = Item.arrayFrom(getSearchJson(drive.isNew(), response));
for (Item item : items) if (!item.ignore(drive.isNew())) list.add(item.getVod(drive, vodPic));
} catch (Exception ignored) {

Binary file not shown.

View File

@ -1 +1 @@
630997f2d36dde4644f99300f559ff68
176b1654119d82e6231a4f6046f630e2