Support alist login
This commit is contained in:
parent
0894614b03
commit
f68ef4b1aa
|
|
@ -18,14 +18,16 @@ public class Drive {
|
||||||
|
|
||||||
@SerializedName("drives")
|
@SerializedName("drives")
|
||||||
private List<Drive> drives;
|
private List<Drive> drives;
|
||||||
|
@SerializedName("params")
|
||||||
|
private Map<String, String> params;
|
||||||
|
@SerializedName("login")
|
||||||
|
private Login login;
|
||||||
@SerializedName("vodPic")
|
@SerializedName("vodPic")
|
||||||
private String vodPic;
|
private String vodPic;
|
||||||
@SerializedName("name")
|
@SerializedName("name")
|
||||||
private String name;
|
private String name;
|
||||||
@SerializedName("server")
|
@SerializedName("server")
|
||||||
private String server;
|
private String server;
|
||||||
@SerializedName("password")
|
|
||||||
private String password;
|
|
||||||
@SerializedName("version")
|
@SerializedName("version")
|
||||||
private int version;
|
private int version;
|
||||||
@SerializedName("path")
|
@SerializedName("path")
|
||||||
|
|
@ -39,6 +41,14 @@ public class Drive {
|
||||||
return drives == null ? new ArrayList<>() : drives;
|
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) {
|
public Drive(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
@ -55,10 +65,6 @@ public class Drive {
|
||||||
return TextUtils.isEmpty(server) ? "" : server;
|
return TextUtils.isEmpty(server) ? "" : server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return TextUtils.isEmpty(password) ? "" : password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersion() {
|
public int getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
@ -91,6 +97,10 @@ public class Drive {
|
||||||
return getHost() + "/api/public/settings";
|
return getHost() + "/api/public/settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String loginApi() {
|
||||||
|
return getHost() + "/api/auth/login";
|
||||||
|
}
|
||||||
|
|
||||||
public String listApi() {
|
public String listApi() {
|
||||||
return getHost() + (isNew() ? "/api/fs/list" : "/api/public/path");
|
return getHost() + (isNew() ? "/api/fs/list" : "/api/public/path");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ public class AList extends Spider {
|
||||||
|
|
||||||
private List<Drive> drives;
|
private List<Drive> drives;
|
||||||
private String vodPic;
|
private String vodPic;
|
||||||
|
private String token;
|
||||||
private String ext;
|
private String ext;
|
||||||
|
|
||||||
private List<Filter> getFilter() {
|
private List<Filter> getFilter() {
|
||||||
|
|
@ -51,6 +52,23 @@ public class AList extends Spider {
|
||||||
return drives.get(drives.indexOf(new Drive(name))).check();
|
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
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -132,15 +150,30 @@ public class AList extends Spider {
|
||||||
return Result.get().url(getDetail(ids[0]).getUrl()).subs(getSub(ids)).string();
|
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) {
|
private Item getDetail(String id) {
|
||||||
try {
|
try {
|
||||||
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
||||||
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
|
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
|
||||||
Drive drive = getDrive(key);
|
Drive drive = getDrive(key);
|
||||||
|
path = path.startsWith(drive.getPath()) ? path : drive.getPath() + path;
|
||||||
JSONObject params = new JSONObject();
|
JSONObject params = new JSONObject();
|
||||||
params.put("password", drive.getPassword());
|
params.put("path", path);
|
||||||
params.put("path", path.startsWith(drive.getPath()) ? path : drive.getPath() + path);
|
params.put("password", drive.getParams().get(path));
|
||||||
String response = OkHttp.postJson(drive.getApi(), params.toString()).getBody();
|
String response = post(drive, drive.getApi(), params.toString());
|
||||||
return Item.objectFrom(getDetailJson(drive.isNew(), response));
|
return Item.objectFrom(getDetailJson(drive.isNew(), response));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Item();
|
return new Item();
|
||||||
|
|
@ -152,10 +185,11 @@ public class AList extends Spider {
|
||||||
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
||||||
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
|
String path = id.contains("/") ? id.substring(id.indexOf("/")) : "";
|
||||||
Drive drive = getDrive(key);
|
Drive drive = getDrive(key);
|
||||||
|
path = path.startsWith(drive.getPath()) ? path : drive.getPath() + path;
|
||||||
JSONObject params = new JSONObject();
|
JSONObject params = new JSONObject();
|
||||||
params.put("password", drive.getPassword());
|
params.put("path", path);
|
||||||
params.put("path", path.startsWith(drive.getPath()) ? path : drive.getPath() + path);
|
params.put("password", drive.getParams().get(path));
|
||||||
String response = OkHttp.postJson(drive.listApi(), params.toString()).getBody();
|
String response = post(drive, drive.listApi(), params.toString());
|
||||||
List<Item> items = Item.arrayFrom(getListJson(drive.isNew(), response));
|
List<Item> items = Item.arrayFrom(getListJson(drive.isNew(), response));
|
||||||
Iterator<Item> iterator = items.iterator();
|
Iterator<Item> iterator = items.iterator();
|
||||||
if (filter) while (iterator.hasNext()) if (iterator.next().ignore(drive.isNew())) iterator.remove();
|
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) {
|
private void search(CountDownLatch cd, List<Vod> list, Drive drive, String keyword) {
|
||||||
try {
|
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));
|
List<Item> items = Item.arrayFrom(getSearchJson(drive.isNew(), response));
|
||||||
for (Item item : items) if (!item.ignore(drive.isNew())) list.add(item.getVod(drive, vodPic));
|
for (Item item : items) if (!item.ignore(drive.isNew())) list.add(item.getVod(drive, vodPic));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
630997f2d36dde4644f99300f559ff68
|
176b1654119d82e6231a4f6046f630e2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue