Support alist v3 search

This commit is contained in:
FongMi 2022-12-06 14:54:45 +08:00
parent 6bf89b4f0d
commit 970aa5ab3f
5 changed files with 24 additions and 46 deletions

View File

@ -76,11 +76,7 @@ public class Drive {
} }
public String searchApi() { public String searchApi() {
return getServer() + "/api/public/search"; return getServer() + (isNew() ? "/api/fs/search" : "/api/public/search");
}
public String searchApi(String param) {
return getServer() + "/search?box=" + param + "&url=";
} }
public Drive check() { public Drive check() {

View File

@ -18,7 +18,7 @@ public class Item {
@SerializedName("name") @SerializedName("name")
private String name; private String name;
@SerializedName("path") @SerializedName(value = "path", alternate = "parent")
private String path; private String path;
@SerializedName("type") @SerializedName("type")
private int type; private int type;
@ -93,13 +93,13 @@ public class Item {
return getType() == 1; return getType() == 1;
} }
public boolean isMedia(boolean v3) { public boolean isMedia(boolean isNew) {
if (v3) return getType() == 2 || getType() == 3; if (isNew) return getType() == 2 || getType() == 3;
return getType() == 3 || getType() == 4; return getType() == 3 || getType() == 4;
} }
public boolean ignore(boolean v3) { public boolean ignore(boolean isNew) {
if (v3) return getType() == 0 || getType() == 4; if (isNew) return getType() == 0 || getType() == 4;
return getType() == 0 || getType() == 2 || getType() == 5; return getType() == 0 || getType() == 2 || getType() == 5;
} }

View File

@ -14,11 +14,9 @@ import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttpUtil; import com.github.catvod.net.OkHttpUtil;
import com.github.catvod.utils.Misc; import com.github.catvod.utils.Misc;
import com.github.catvod.utils.Trans; import com.github.catvod.utils.Trans;
import com.google.gson.Gson;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -27,6 +25,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public class AList extends Spider { public class AList extends Spider {
@ -165,47 +164,30 @@ public class AList extends Spider {
} }
} }
private String getParams(String keyword) { private String getParams(boolean isNew, String keyword) {
try { Map<String, Object> params = new HashMap<>();
JSONObject params = new JSONObject(); if (isNew) {
params.put("path", "/"); params.put("keywords", keyword);
params.put("page", 1);
params.put("parent", "/");
params.put("per_page", 100);
} else {
params.put("keyword", keyword); params.put("keyword", keyword);
return params.toString(); params.put("path", "/");
} catch (Exception e) {
return "";
} }
return new Gson().toJson(params);
} }
private void search(CountDownLatch cd, List<Vod> list, Drive drive, String 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, 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("\\.");
boolean file = splits.length > 1 && splits[1].length() == 3;
Item item = new Item();
int index = text.lastIndexOf("/");
if (index == -1) continue;
item.setPath("/" + text.substring(0, index));
item.setName(text.substring(index + 1));
item.setType(file ? 0 : 1);
list.add(item.getVod(drive.getName()));
}
}
private void searchV2(List<Vod> list, Drive drive, String param) {
try { try {
String response = OkHttpUtil.postJson(drive.searchApi(), param); String response = OkHttpUtil.postJson(drive.searchApi(), getParams(drive.isNew(), keyword));
String json = new JSONObject(response).getJSONArray("data").toString(); String json = drive.isNew() ? new JSONObject(response).getJSONObject("data").getJSONArray("content").toString() : new JSONObject(response).getJSONArray("data").toString();
List<Item> items = Item.arrayFrom(json); List<Item> items = Item.arrayFrom(json);
for (Item item : items) if (!item.ignore(false)) list.add(item.getVod(drive.getName())); for (Item item : items) if (!item.ignore(drive.isNew())) list.add(item.getVod(drive.getName()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
cd.countDown();
} }
} }

Binary file not shown.

View File

@ -1 +1 @@
7d655c54d086110028be6074c85dce66 10acad2429c1de8501f2b52a85730bcf