|
|
|
|
@ -54,7 +54,7 @@ public class Bili extends Spider { |
|
|
|
|
private boolean login; |
|
|
|
|
private boolean vip; |
|
|
|
|
|
|
|
|
|
private Map<String, String> getHeader() { |
|
|
|
|
private Map<String, String> getHeader(String cookie) { |
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
headers.put("cookie", cookie); |
|
|
|
|
headers.put("User-Agent", Utils.CHROME); |
|
|
|
|
@ -62,6 +62,14 @@ public class Bili extends Spider { |
|
|
|
|
return headers; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, String> getGuest() { |
|
|
|
|
return getHeader(COOKIE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, String> getMember() { |
|
|
|
|
return getHeader(cookie); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setAudio() { |
|
|
|
|
audios = new HashMap<>(); |
|
|
|
|
audios.put("30280", "192000"); |
|
|
|
|
@ -110,7 +118,7 @@ public class Bili extends Spider { |
|
|
|
|
String order = extend.containsKey("order") ? extend.get("order") : "totalrank"; |
|
|
|
|
String duration = extend.containsKey("duration") ? extend.get("duration") : "0"; |
|
|
|
|
String api = "https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword=" + URLEncoder.encode(tid) + "&order=" + order + "&duration=" + duration + "&page=" + pg; |
|
|
|
|
String json = OkHttp.string(api, getHeader()); |
|
|
|
|
String json = OkHttp.string(api, getGuest()); |
|
|
|
|
Resp resp = Resp.objectFrom(json); |
|
|
|
|
List<Vod> list = new ArrayList<>(); |
|
|
|
|
for (Resp.Result item : Resp.Result.arrayFrom(resp.getData().getResult())) list.add(item.getVod()); |
|
|
|
|
@ -123,12 +131,12 @@ public class Bili extends Spider { |
|
|
|
|
|
|
|
|
|
String id = ids.get(0); |
|
|
|
|
String api = "https://api.bilibili.com/x/web-interface/archive/stat?bvid=" + id; |
|
|
|
|
String json = OkHttp.string(api, getHeader()); |
|
|
|
|
String json = OkHttp.string(api, getMember()); |
|
|
|
|
Resp resp = Resp.objectFrom(json); |
|
|
|
|
String aid = resp.getData().getAid(); |
|
|
|
|
|
|
|
|
|
api = "https://api.bilibili.com/x/web-interface/view?aid=" + aid; |
|
|
|
|
json = OkHttp.string(api, getHeader()); |
|
|
|
|
json = OkHttp.string(api, getMember()); |
|
|
|
|
Data detail = Resp.objectFrom(json).getData(); |
|
|
|
|
Vod vod = new Vod(); |
|
|
|
|
vod.setVodId(id); |
|
|
|
|
@ -139,7 +147,7 @@ public class Bili extends Spider { |
|
|
|
|
vod.setVodRemarks(detail.getDuration() / 60 + "分鐘"); |
|
|
|
|
|
|
|
|
|
api = "https://api.bilibili.com/x/player/playurl?avid=" + aid + "&cid=" + detail.getCid() + "&qn=127&fnval=4048&fourk=1"; |
|
|
|
|
json = OkHttp.string(api, getHeader()); |
|
|
|
|
json = OkHttp.string(api, getMember()); |
|
|
|
|
Data play = Resp.objectFrom(json).getData(); |
|
|
|
|
List<String> playList = new ArrayList<>(); |
|
|
|
|
List<String> playFrom = new ArrayList<>(); |
|
|
|
|
@ -171,7 +179,7 @@ public class Bili extends Spider { |
|
|
|
|
String qn = ids[2]; |
|
|
|
|
|
|
|
|
|
String api = "https://api.bilibili.com/x/player/playurl?avid=" + aid + "&cid=" + cid + "&qn=" + qn + "&fnval=4048&fourk=1"; |
|
|
|
|
String json = OkHttp.string(api, getHeader()); |
|
|
|
|
String json = OkHttp.string(api, getMember()); |
|
|
|
|
Resp resp = Resp.objectFrom(json); |
|
|
|
|
Dash dash = resp.getData().getDash(); |
|
|
|
|
|
|
|
|
|
@ -192,7 +200,7 @@ public class Bili extends Spider { |
|
|
|
|
|
|
|
|
|
String mpd = getMpd(dash, videoList.toString(), audioList.toString()); |
|
|
|
|
String url = "data:application/dash+xml;base64," + Base64.encodeToString(mpd.getBytes(), 0); |
|
|
|
|
return Result.get().url(url).header(getHeader()).string(); |
|
|
|
|
return Result.get().url(url).header(getMember()).string(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getMedia(Media media) { |
|
|
|
|
@ -241,7 +249,7 @@ public class Bili extends Spider { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkLogin() { |
|
|
|
|
String json = OkHttp.string("https://api.bilibili.com/x/web-interface/nav", getHeader()); |
|
|
|
|
String json = OkHttp.string("https://api.bilibili.com/x/web-interface/nav", getMember()); |
|
|
|
|
Data data = Resp.objectFrom(json).getData(); |
|
|
|
|
login = data.isLogin(); |
|
|
|
|
vip = data.getVipType() > 0; |
|
|
|
|
@ -275,7 +283,7 @@ public class Bili extends Spider { |
|
|
|
|
service = Executors.newScheduledThreadPool(1); |
|
|
|
|
service.scheduleAtFixedRate(() -> { |
|
|
|
|
String url = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + data.getQrcodeKey() + "&source=main_mini"; |
|
|
|
|
String json = OkHttp.string(url, getHeader()); |
|
|
|
|
String json = OkHttp.string(url, getGuest()); |
|
|
|
|
url = Resp.objectFrom(json).getData().getUrl(); |
|
|
|
|
if (url.length() > 0) setCookie(url); |
|
|
|
|
}, 1, 1, TimeUnit.SECONDS); |
|
|
|
|
|