Update alist
This commit is contained in:
parent
4697b3566c
commit
ba7360595c
|
|
@ -35,6 +35,8 @@ public class Drive {
|
||||||
private String path;
|
private String path;
|
||||||
@SerializedName("token")
|
@SerializedName("token")
|
||||||
private String token;
|
private String token;
|
||||||
|
@SerializedName("search")
|
||||||
|
private Boolean search;
|
||||||
|
|
||||||
public static Drive objectFrom(String str) {
|
public static Drive objectFrom(String str) {
|
||||||
return new Gson().fromJson(str, Drive.class);
|
return new Gson().fromJson(str, Drive.class);
|
||||||
|
|
@ -92,6 +94,10 @@ public class Drive {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean search() {
|
||||||
|
return search == null || search;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
return getVersion() == 3;
|
return getVersion() == 3;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,11 @@ 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.concurrent.CountDownLatch;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class AList extends Spider {
|
public class AList extends Spider {
|
||||||
|
|
||||||
|
|
@ -130,9 +134,10 @@ public class AList extends Spider {
|
||||||
public String searchContent(String keyword, boolean quick) throws Exception {
|
public String searchContent(String keyword, boolean quick) throws Exception {
|
||||||
fetchRule();
|
fetchRule();
|
||||||
List<Vod> list = new ArrayList<>();
|
List<Vod> list = new ArrayList<>();
|
||||||
CountDownLatch cd = new CountDownLatch(drives.size());
|
List<Job> jobs = new ArrayList<>();
|
||||||
for (Drive drive : drives) new Thread(() -> search(cd, list, drive.check(), keyword)).start();
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
cd.await();
|
for (Drive drive : drives) if (drive.search()) jobs.add(new Job(drive.check(), keyword));
|
||||||
|
for (Future<List<Vod>> future : executor.invokeAll(jobs, 15, TimeUnit.SECONDS)) list.addAll(future.get());
|
||||||
return Result.string(list);
|
return Result.string(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,17 +196,6 @@ public class AList extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void search(CountDownLatch cd, List<Vod> list, Drive drive, String keyword) {
|
|
||||||
try {
|
|
||||||
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) {
|
|
||||||
} finally {
|
|
||||||
cd.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getListJson(boolean isNew, String response) throws Exception {
|
private String getListJson(boolean isNew, String response) throws Exception {
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
return new JSONObject(response).getJSONObject("data").getJSONArray("content").toString();
|
return new JSONObject(response).getJSONObject("data").getJSONArray("content").toString();
|
||||||
|
|
@ -244,4 +238,24 @@ public class AList extends Spider {
|
||||||
}
|
}
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Job implements Callable<List<Vod>> {
|
||||||
|
|
||||||
|
private final Drive drive;
|
||||||
|
private final String keyword;
|
||||||
|
|
||||||
|
public Job(Drive drive, String keyword) {
|
||||||
|
this.drive = drive;
|
||||||
|
this.keyword = keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Vod> call() throws Exception {
|
||||||
|
List<Vod> list = new ArrayList<>();
|
||||||
|
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));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
3e353d2564e6293da3520b21fb2867d9
|
74d87fdc0c6bfaf5fadc846b41ad2ef5
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue