Update alist
This commit is contained in:
parent
997a6980b8
commit
768980f706
|
|
@ -5,14 +5,14 @@ import android.text.TextUtils;
|
|||
import com.github.catvod.bean.Class;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public class Drive {
|
||||
|
||||
@SerializedName("drives")
|
||||
private List<Drive> drives;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("server")
|
||||
|
|
@ -22,12 +22,15 @@ public class Config {
|
|||
@SerializedName("version")
|
||||
private int version;
|
||||
|
||||
public static List<Config> arrayFrom(String str) {
|
||||
Type listType = new TypeToken<ArrayList<Config>>() {}.getType();
|
||||
return new Gson().fromJson(str, listType);
|
||||
public static Drive objectFrom(String str) {
|
||||
return new Gson().fromJson(str, Drive.class);
|
||||
}
|
||||
|
||||
public Config(String name) {
|
||||
public List<Drive> getDrives() {
|
||||
return drives == null ? new ArrayList<>() : drives;
|
||||
}
|
||||
|
||||
public Drive(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
@ -82,8 +85,8 @@ public class Config {
|
|||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Config)) return false;
|
||||
Config it = (Config) obj;
|
||||
if (!(obj instanceof Drive)) return false;
|
||||
Drive it = (Drive) obj;
|
||||
return getName().equals(it.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import com.github.catvod.bean.Class;
|
|||
import com.github.catvod.bean.Filter;
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.Vod;
|
||||
import com.github.catvod.bean.alist.Config;
|
||||
import com.github.catvod.bean.alist.Drive;
|
||||
import com.github.catvod.bean.alist.Item;
|
||||
import com.github.catvod.bean.alist.Sorter;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
|
|
@ -30,7 +30,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
|
||||
public class AList extends Spider {
|
||||
|
||||
private List<Config> configs;
|
||||
private List<Drive> drives;
|
||||
private String ext;
|
||||
|
||||
private List<Filter> getFilter() {
|
||||
|
|
@ -41,14 +41,15 @@ public class AList extends Spider {
|
|||
}
|
||||
|
||||
private void fetchRule() {
|
||||
if (configs != null && !configs.isEmpty()) return;
|
||||
configs = Config.arrayFrom(ext);
|
||||
if (drives != null && !drives.isEmpty()) return;
|
||||
if (ext.startsWith("http")) ext = OkHttpUtil.string(ext);
|
||||
drives = Drive.objectFrom(ext).getDrives();
|
||||
}
|
||||
|
||||
private Config getConfig(String name) {
|
||||
Config config = configs.get(configs.indexOf(new Config(name)));
|
||||
if (config.getVersion() == 0) config.setVersion(OkHttpUtil.string(config.settingsApi()).contains("v3.") ? 3 : 2);
|
||||
return config;
|
||||
private Drive getDrive(String name) {
|
||||
Drive drive = drives.get(drives.indexOf(new Drive(name)));
|
||||
if (drive.getVersion() == 0) drive.setVersion(OkHttpUtil.string(drive.settingsApi()).contains("v3.") ? 3 : 2);
|
||||
return drive;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,7 +66,7 @@ public class AList extends Spider {
|
|||
fetchRule();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
||||
for (Config config : configs) classes.add(config.toType());
|
||||
for (Drive drive : drives) classes.add(drive.toType());
|
||||
for (Class item : classes) filters.put(item.getTypeId(), getFilter());
|
||||
return Result.string(classes, filters);
|
||||
}
|
||||
|
|
@ -110,12 +111,12 @@ public class AList extends Spider {
|
|||
try {
|
||||
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
||||
String path = id.contains("/") ? id.substring(id.indexOf("/") + 1) : "";
|
||||
Config config = getConfig(key);
|
||||
Drive drive = getDrive(key);
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("path", path);
|
||||
params.put("password", config.getPassword());
|
||||
String response = OkHttpUtil.postJson(config.getApi(), params.toString());
|
||||
String json = config.isNew() ? new JSONObject(response).getJSONObject("data").toString() : new JSONObject(response).getJSONObject("data").getJSONArray("files").getJSONObject(0).toString();
|
||||
params.put("password", drive.getPassword());
|
||||
String response = OkHttpUtil.postJson(drive.getApi(), params.toString());
|
||||
String json = drive.isNew() ? new JSONObject(response).getJSONObject("data").toString() : new JSONObject(response).getJSONObject("data").getJSONArray("files").getJSONObject(0).toString();
|
||||
return Item.objectFrom(json);
|
||||
} catch (Exception e) {
|
||||
return new Item();
|
||||
|
|
@ -126,15 +127,15 @@ public class AList extends Spider {
|
|||
try {
|
||||
String key = id.contains("/") ? id.substring(0, id.indexOf("/")) : id;
|
||||
String path = id.contains("/") ? id.substring(id.indexOf("/") + 1) : "";
|
||||
Config config = getConfig(key);
|
||||
Drive drive = getDrive(key);
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("path", path);
|
||||
params.put("password", config.getPassword());
|
||||
String response = OkHttpUtil.postJson(config.listApi(), params.toString());
|
||||
String json = new JSONObject(response).getJSONObject("data").getJSONArray(config.isNew() ? "content" : "files").toString();
|
||||
params.put("password", drive.getPassword());
|
||||
String response = OkHttpUtil.postJson(drive.listApi(), params.toString());
|
||||
String json = new JSONObject(response).getJSONObject("data").getJSONArray(drive.isNew() ? "content" : "files").toString();
|
||||
List<Item> items = Item.arrayFrom(json);
|
||||
Iterator<Item> iterator = items.iterator();
|
||||
if (filter) while (iterator.hasNext()) if (iterator.next().ignore(config.isNew())) iterator.remove();
|
||||
if (filter) while (iterator.hasNext()) if (iterator.next().ignore(drive.isNew())) iterator.remove();
|
||||
return items;
|
||||
} catch (Exception e) {
|
||||
return Collections.emptyList();
|
||||
|
|
@ -145,8 +146,8 @@ public class AList extends Spider {
|
|||
public String searchContent(String keyword, boolean quick) throws Exception {
|
||||
fetchRule();
|
||||
List<Vod> list = new ArrayList<>();
|
||||
CountDownLatch cd = new CountDownLatch(configs.size());
|
||||
for (Config config : configs) new Thread(() -> search(cd, list, config, keyword)).start();
|
||||
CountDownLatch cd = new CountDownLatch(drives.size());
|
||||
for (Drive drive : drives) new Thread(() -> search(cd, list, drive, keyword)).start();
|
||||
cd.await();
|
||||
return Result.string(list);
|
||||
}
|
||||
|
|
@ -168,14 +169,14 @@ public class AList extends Spider {
|
|||
}
|
||||
}
|
||||
|
||||
private void search(CountDownLatch cd, List<Vod> list, Config config, String keyword) {
|
||||
if (config.isNew()) searchV3(list, config, keyword);
|
||||
else searchV2(list, config, getParams(keyword));
|
||||
private void search(CountDownLatch cd, List<Vod> list, Drive drive, String keyword) {
|
||||
if (drive.isNew()) searchV3(list, drive, keyword);
|
||||
else searchV2(list, drive, getParams(keyword));
|
||||
cd.countDown();
|
||||
}
|
||||
|
||||
private void searchV3(List<Vod> list, Config config, String param) {
|
||||
Document doc = Jsoup.parse(OkHttpUtil.string(config.searchApi(param)));
|
||||
private void searchV3(List<Vod> list, Drive drive, String param) {
|
||||
Document doc = Jsoup.parse(OkHttpUtil.string(drive.searchApi(param)));
|
||||
for (Element a : doc.select("ul > a")) {
|
||||
String text = a.text();
|
||||
String[] splits = text.split("\\.");
|
||||
|
|
@ -186,16 +187,16 @@ public class AList extends Spider {
|
|||
item.setPath("/" + text.substring(0, index));
|
||||
item.setName(text.substring(index + 1));
|
||||
item.setType(file ? 0 : 1);
|
||||
list.add(item.getVod(config.getName()));
|
||||
list.add(item.getVod(drive.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private void searchV2(List<Vod> list, Config config, String param) {
|
||||
private void searchV2(List<Vod> list, Drive drive, String param) {
|
||||
try {
|
||||
String response = OkHttpUtil.postJson(config.searchApi(), param);
|
||||
String response = OkHttpUtil.postJson(drive.searchApi(), param);
|
||||
String json = new JSONObject(response).getJSONArray("data").toString();
|
||||
List<Item> items = Item.arrayFrom(json);
|
||||
for (Item item : items) if (!item.ignore(false)) list.add(item.getVod(config.getName()));
|
||||
for (Item item : items) if (!item.ignore(false)) list.add(item.getVod(drive.getName()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
7ee69b177d3dc555da364acebccca100
|
||||
cc2b0b7bef842b7a62cc722704abb70f
|
||||
|
|
|
|||
Loading…
Reference in New Issue