Save bili cookie to file
This commit is contained in:
parent
eb4dba455d
commit
d8a2144468
|
|
@ -36,96 +36,4 @@ public class Dash {
|
||||||
public List<Media> getAudio() {
|
public List<Media> getAudio() {
|
||||||
return audio == null ? Collections.emptyList() : audio;
|
return audio == null ? Collections.emptyList() : audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Media {
|
|
||||||
|
|
||||||
@SerializedName("id")
|
|
||||||
private String id;
|
|
||||||
@SerializedName("baseUrl")
|
|
||||||
private String baseUrl;
|
|
||||||
@SerializedName("bandwidth")
|
|
||||||
private String bandwidth;
|
|
||||||
@SerializedName("mimeType")
|
|
||||||
private String mimeType;
|
|
||||||
@SerializedName("codecs")
|
|
||||||
private String codecs;
|
|
||||||
@SerializedName("width")
|
|
||||||
private String width;
|
|
||||||
@SerializedName("height")
|
|
||||||
private String height;
|
|
||||||
@SerializedName("frameRate")
|
|
||||||
private String frameRate;
|
|
||||||
@SerializedName("sar")
|
|
||||||
private String sar;
|
|
||||||
@SerializedName("startWithSap")
|
|
||||||
private String startWithSap;
|
|
||||||
@SerializedName("SegmentBase")
|
|
||||||
private SegmentBase segmentBase;
|
|
||||||
@SerializedName("codecid")
|
|
||||||
private String codecid;
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBaseUrl() {
|
|
||||||
return baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBandWidth() {
|
|
||||||
return bandwidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMimeType() {
|
|
||||||
return mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodecs() {
|
|
||||||
return codecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFrameRate() {
|
|
||||||
return frameRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSar() {
|
|
||||||
return sar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStartWithSap() {
|
|
||||||
return startWithSap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SegmentBase getSegmentBase() {
|
|
||||||
return segmentBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodecId() {
|
|
||||||
return codecid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SegmentBase {
|
|
||||||
|
|
||||||
@SerializedName("Initialization")
|
|
||||||
private String initialization;
|
|
||||||
@SerializedName("indexRange")
|
|
||||||
private String indexRange;
|
|
||||||
|
|
||||||
public String getInitialization() {
|
|
||||||
return initialization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIndexRange() {
|
|
||||||
return indexRange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
package com.github.catvod.bean.bili;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Data {
|
||||||
|
|
||||||
|
@SerializedName("result")
|
||||||
|
private JsonElement result;
|
||||||
|
@SerializedName("isLogin")
|
||||||
|
private Boolean isLogin;
|
||||||
|
@SerializedName("vipType")
|
||||||
|
private Integer vipType;
|
||||||
|
@SerializedName("qrcode_key")
|
||||||
|
private String qrcodeKey;
|
||||||
|
@SerializedName("url")
|
||||||
|
private String url;
|
||||||
|
@SerializedName("aid")
|
||||||
|
private String aid;
|
||||||
|
@SerializedName("cid")
|
||||||
|
private String cid;
|
||||||
|
@SerializedName("title")
|
||||||
|
private String title;
|
||||||
|
@SerializedName("tname")
|
||||||
|
private String tname;
|
||||||
|
@SerializedName("pic")
|
||||||
|
private String pic;
|
||||||
|
@SerializedName("duration")
|
||||||
|
private Long duration;
|
||||||
|
@SerializedName("desc")
|
||||||
|
private String desc;
|
||||||
|
@SerializedName("accept_description")
|
||||||
|
private List<String> acceptDescription;
|
||||||
|
@SerializedName("accept_quality")
|
||||||
|
private List<Integer> acceptQuality;
|
||||||
|
@SerializedName("pages")
|
||||||
|
private List<Page> pages;
|
||||||
|
@SerializedName("dash")
|
||||||
|
private Dash dash;
|
||||||
|
|
||||||
|
public JsonElement getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLogin() {
|
||||||
|
return isLogin != null && isLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVipType() {
|
||||||
|
return vipType == null ? 0 : vipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQrcodeKey() {
|
||||||
|
return TextUtils.isEmpty(qrcodeKey) ? "" : qrcodeKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return TextUtils.isEmpty(url) ? "" : url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAid() {
|
||||||
|
return TextUtils.isEmpty(aid) ? "" : aid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCid() {
|
||||||
|
return TextUtils.isEmpty(cid) ? "" : cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return TextUtils.isEmpty(title) ? "" : title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return TextUtils.isEmpty(tname) ? "" : tname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPic() {
|
||||||
|
return TextUtils.isEmpty(pic) ? "" : pic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDuration() {
|
||||||
|
return duration == null ? 0 : duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return TextUtils.isEmpty(desc) ? "" : desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAcceptDescription() {
|
||||||
|
return acceptDescription == null ? Collections.emptyList() : acceptDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getAcceptQuality() {
|
||||||
|
return acceptQuality == null ? Collections.emptyList() : acceptQuality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Page> getPages() {
|
||||||
|
return pages == null ? Collections.emptyList() : pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dash getDash() {
|
||||||
|
return dash == null ? new Dash() : dash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.github.catvod.bean.bili;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Media {
|
||||||
|
|
||||||
|
@SerializedName("id")
|
||||||
|
private String id;
|
||||||
|
@SerializedName("baseUrl")
|
||||||
|
private String baseUrl;
|
||||||
|
@SerializedName("bandwidth")
|
||||||
|
private String bandwidth;
|
||||||
|
@SerializedName("mimeType")
|
||||||
|
private String mimeType;
|
||||||
|
@SerializedName("codecs")
|
||||||
|
private String codecs;
|
||||||
|
@SerializedName("width")
|
||||||
|
private String width;
|
||||||
|
@SerializedName("height")
|
||||||
|
private String height;
|
||||||
|
@SerializedName("frameRate")
|
||||||
|
private String frameRate;
|
||||||
|
@SerializedName("sar")
|
||||||
|
private String sar;
|
||||||
|
@SerializedName("startWithSap")
|
||||||
|
private String startWithSap;
|
||||||
|
@SerializedName("SegmentBase")
|
||||||
|
private Segment segmentBase;
|
||||||
|
@SerializedName("codecid")
|
||||||
|
private String codecid;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBaseUrl() {
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBandWidth() {
|
||||||
|
return bandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMimeType() {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodecs() {
|
||||||
|
return codecs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFrameRate() {
|
||||||
|
return frameRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSar() {
|
||||||
|
return sar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartWithSap() {
|
||||||
|
return startWithSap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Segment getSegmentBase() {
|
||||||
|
return segmentBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodecId() {
|
||||||
|
return codecid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.github.catvod.bean.bili;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Page {
|
||||||
|
|
||||||
|
@SerializedName("cid")
|
||||||
|
private String cid;
|
||||||
|
@SerializedName("part")
|
||||||
|
private String part;
|
||||||
|
|
||||||
|
public String getCid() {
|
||||||
|
return TextUtils.isEmpty(cid) ? "" : cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPart() {
|
||||||
|
return TextUtils.isEmpty(part) ? "" : part;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,6 @@ import com.google.gson.reflect.TypeToken;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Resp {
|
public class Resp {
|
||||||
|
|
@ -31,122 +30,6 @@ public class Resp {
|
||||||
return data == null ? new Data() : data;
|
return data == null ? new Data() : data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Data {
|
|
||||||
|
|
||||||
@SerializedName("result")
|
|
||||||
private JsonElement result;
|
|
||||||
@SerializedName("isLogin")
|
|
||||||
private boolean isLogin;
|
|
||||||
@SerializedName("vipType")
|
|
||||||
private int vipType;
|
|
||||||
@SerializedName("qrcode_key")
|
|
||||||
private String qrcodeKey;
|
|
||||||
@SerializedName("url")
|
|
||||||
private String url;
|
|
||||||
@SerializedName("aid")
|
|
||||||
private String aid;
|
|
||||||
@SerializedName("cid")
|
|
||||||
private String cid;
|
|
||||||
@SerializedName("title")
|
|
||||||
private String title;
|
|
||||||
@SerializedName("tname")
|
|
||||||
private String tname;
|
|
||||||
@SerializedName("pic")
|
|
||||||
private String pic;
|
|
||||||
@SerializedName("duration")
|
|
||||||
private Long duration;
|
|
||||||
@SerializedName("desc")
|
|
||||||
private String desc;
|
|
||||||
@SerializedName("accept_description")
|
|
||||||
private List<String> acceptDescription;
|
|
||||||
@SerializedName("accept_quality")
|
|
||||||
private List<Integer> acceptQuality;
|
|
||||||
@SerializedName("pages")
|
|
||||||
private List<Page> pages;
|
|
||||||
@SerializedName("dash")
|
|
||||||
private Dash dash;
|
|
||||||
|
|
||||||
public JsonElement getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLogin() {
|
|
||||||
return isLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVipType() {
|
|
||||||
return vipType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQrcodeKey() {
|
|
||||||
return TextUtils.isEmpty(qrcodeKey) ? "" : qrcodeKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return TextUtils.isEmpty(url) ? "" : url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAid() {
|
|
||||||
return TextUtils.isEmpty(aid) ? "" : aid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCid() {
|
|
||||||
return TextUtils.isEmpty(cid) ? "" : cid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return TextUtils.isEmpty(title) ? "" : title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return TextUtils.isEmpty(tname) ? "" : tname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPic() {
|
|
||||||
return TextUtils.isEmpty(pic) ? "" : pic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getDuration() {
|
|
||||||
return duration == null ? 0 : duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return TextUtils.isEmpty(desc) ? "" : desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAcceptDescription() {
|
|
||||||
return acceptDescription == null ? Collections.emptyList() : acceptDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getAcceptQuality() {
|
|
||||||
return acceptQuality == null ? Collections.emptyList() : acceptQuality;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Page> getPages() {
|
|
||||||
return pages == null ? Collections.emptyList() : pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dash getDash() {
|
|
||||||
return dash == null ? new Dash() : dash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Page {
|
|
||||||
|
|
||||||
@SerializedName("cid")
|
|
||||||
private String cid;
|
|
||||||
@SerializedName("part")
|
|
||||||
private String part;
|
|
||||||
|
|
||||||
public String getCid() {
|
|
||||||
return TextUtils.isEmpty(cid) ? "" : cid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPart() {
|
|
||||||
return TextUtils.isEmpty(part) ? "" : part;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Result {
|
public static class Result {
|
||||||
|
|
||||||
@SerializedName("bvid")
|
@SerializedName("bvid")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.github.catvod.bean.bili;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Segment {
|
||||||
|
|
||||||
|
@SerializedName("Initialization")
|
||||||
|
private String initialization;
|
||||||
|
@SerializedName("indexRange")
|
||||||
|
private String indexRange;
|
||||||
|
|
||||||
|
public String getInitialization() {
|
||||||
|
return initialization;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIndexRange() {
|
||||||
|
return indexRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,13 +17,17 @@ import com.github.catvod.bean.Filter;
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.bean.bili.Dash;
|
import com.github.catvod.bean.bili.Dash;
|
||||||
|
import com.github.catvod.bean.bili.Data;
|
||||||
|
import com.github.catvod.bean.bili.Media;
|
||||||
|
import com.github.catvod.bean.bili.Page;
|
||||||
import com.github.catvod.bean.bili.Resp;
|
import com.github.catvod.bean.bili.Resp;
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
import com.github.catvod.utils.Prefers;
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.github.catvod.utils.QRCode;
|
import com.github.catvod.utils.QRCode;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -52,9 +56,9 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
private void setHeader() {
|
private void setHeader() {
|
||||||
header = new HashMap<>();
|
header = new HashMap<>();
|
||||||
header.put("cookie", Prefers.getString("BiliCookie", COOKIE));
|
header.put("cookie", getCookie());
|
||||||
header.put("Referer", "https://www.bilibili.com");
|
|
||||||
header.put("User-Agent", Utils.CHROME);
|
header.put("User-Agent", Utils.CHROME);
|
||||||
|
header.put("Referer", "https://www.bilibili.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAudio() {
|
private void setAudio() {
|
||||||
|
|
@ -71,6 +75,15 @@ public class Bili extends Spider {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File getUserCache() {
|
||||||
|
return FileUtil.getCacheFile("bilibili_user");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCookie() {
|
||||||
|
String cookie = FileUtil.read(getUserCache());
|
||||||
|
return TextUtils.isEmpty(cookie) ? COOKIE : cookie;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -123,7 +136,7 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
api = "https://api.bilibili.com/x/web-interface/view?aid=" + aid;
|
api = "https://api.bilibili.com/x/web-interface/view?aid=" + aid;
|
||||||
json = OkHttp.string(api, header);
|
json = OkHttp.string(api, header);
|
||||||
Resp.Data detail = Resp.objectFrom(json).getData();
|
Data detail = Resp.objectFrom(json).getData();
|
||||||
Vod vod = new Vod();
|
Vod vod = new Vod();
|
||||||
vod.setVodId(id);
|
vod.setVodId(id);
|
||||||
vod.setVodPic(detail.getPic());
|
vod.setVodPic(detail.getPic());
|
||||||
|
|
@ -134,7 +147,7 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
api = "https://api.bilibili.com/x/player/playurl?avid=" + aid + "&cid=" + detail.getCid() + "&qn=120&fnval=4048&fourk=1";
|
api = "https://api.bilibili.com/x/player/playurl?avid=" + aid + "&cid=" + detail.getCid() + "&qn=120&fnval=4048&fourk=1";
|
||||||
json = OkHttp.string(api, header);
|
json = OkHttp.string(api, header);
|
||||||
Resp.Data play = Resp.objectFrom(json).getData();
|
Data play = Resp.objectFrom(json).getData();
|
||||||
List<String> playList = new ArrayList<>();
|
List<String> playList = new ArrayList<>();
|
||||||
List<String> playFrom = new ArrayList<>();
|
List<String> playFrom = new ArrayList<>();
|
||||||
for (int i = 0; i < play.getAcceptQuality().size(); i++) {
|
for (int i = 0; i < play.getAcceptQuality().size(); i++) {
|
||||||
|
|
@ -142,7 +155,7 @@ public class Bili extends Spider {
|
||||||
List<String> vodItems = new ArrayList<>();
|
List<String> vodItems = new ArrayList<>();
|
||||||
if (!login && quality > 32) continue;
|
if (!login && quality > 32) continue;
|
||||||
if (!vip && quality > 80) continue;
|
if (!vip && quality > 80) continue;
|
||||||
for (Resp.Page page : detail.getPages()) vodItems.add(page.getPart() + "$" + aid + "+" + page.getCid() + "+" + quality);
|
for (Page page : detail.getPages()) vodItems.add(page.getPart() + "$" + aid + "+" + page.getCid() + "+" + quality);
|
||||||
playList.add(TextUtils.join("#", vodItems));
|
playList.add(TextUtils.join("#", vodItems));
|
||||||
playFrom.add(play.getAcceptDescription().get(i));
|
playFrom.add(play.getAcceptDescription().get(i));
|
||||||
}
|
}
|
||||||
|
|
@ -171,12 +184,12 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
StringBuilder videoList = new StringBuilder();
|
StringBuilder videoList = new StringBuilder();
|
||||||
StringBuilder audioList = new StringBuilder();
|
StringBuilder audioList = new StringBuilder();
|
||||||
for (Dash.Media video : dash.getVideo()) {
|
for (Media video : dash.getVideo()) {
|
||||||
if (video.getId().equals(qn)) {
|
if (video.getId().equals(qn)) {
|
||||||
videoList.append(getMedia(video));
|
videoList.append(getMedia(video));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Dash.Media audio : dash.getAudio()) {
|
for (Media audio : dash.getAudio()) {
|
||||||
for (String key : audios.keySet()) {
|
for (String key : audios.keySet()) {
|
||||||
if (audio.getId().equals(key)) {
|
if (audio.getId().equals(key)) {
|
||||||
audioList.append(getMedia(audio));
|
audioList.append(getMedia(audio));
|
||||||
|
|
@ -189,7 +202,7 @@ public class Bili extends Spider {
|
||||||
return Result.get().url(url).header(header).string();
|
return Result.get().url(url).header(header).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMedia(Dash.Media media) {
|
private String getMedia(Media media) {
|
||||||
if (media.getMimeType().startsWith("video")) {
|
if (media.getMimeType().startsWith("video")) {
|
||||||
return getAdaptationSet(media, String.format(Locale.getDefault(), "height='%s' width='%s' frameRate='%s' sar='%s'", media.getHeight(), media.getWidth(), media.getFrameRate(), media.getSar()));
|
return getAdaptationSet(media, String.format(Locale.getDefault(), "height='%s' width='%s' frameRate='%s' sar='%s'", media.getHeight(), media.getWidth(), media.getFrameRate(), media.getSar()));
|
||||||
} else if (media.getMimeType().startsWith("audio")) {
|
} else if (media.getMimeType().startsWith("audio")) {
|
||||||
|
|
@ -199,7 +212,7 @@ public class Bili extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAdaptationSet(Dash.Media media, String params) {
|
private String getAdaptationSet(Media media, String params) {
|
||||||
String id = media.getId() + "_" + media.getCodecId();
|
String id = media.getId() + "_" + media.getCodecId();
|
||||||
String type = media.getMimeType().split("/")[0];
|
String type = media.getMimeType().split("/")[0];
|
||||||
String baseUrl = media.getBaseUrl().replace("&", "&");
|
String baseUrl = media.getBaseUrl().replace("&", "&");
|
||||||
|
|
@ -236,20 +249,19 @@ public class Bili extends Spider {
|
||||||
|
|
||||||
private void checkLogin() {
|
private void checkLogin() {
|
||||||
String json = OkHttp.string("https://api.bilibili.com/x/web-interface/nav", header);
|
String json = OkHttp.string("https://api.bilibili.com/x/web-interface/nav", header);
|
||||||
Resp.Data data = Resp.objectFrom(json).getData();
|
Data data = Resp.objectFrom(json).getData();
|
||||||
login = data.isLogin();
|
login = data.isLogin();
|
||||||
vip = data.getVipType() > 0;
|
vip = data.getVipType() > 0;
|
||||||
boolean showCode = Prefers.getBoolean("BiliQRCode", true);
|
if (!login && !getUserCache().exists()) getQRCode();
|
||||||
if (!login && showCode) getQRCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getQRCode() {
|
private void getQRCode() {
|
||||||
String json = OkHttp.string("https://passport.bilibili.com/x/passport-login/web/qrcode/generate?source=main-mini");
|
String json = OkHttp.string("https://passport.bilibili.com/x/passport-login/web/qrcode/generate?source=main-mini");
|
||||||
Resp.Data data = Resp.objectFrom(json).getData();
|
Data data = Resp.objectFrom(json).getData();
|
||||||
Init.run(() -> showQRCode(data));
|
Init.run(() -> showQRCode(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showQRCode(Resp.Data data) {
|
private void showQRCode(Data data) {
|
||||||
try {
|
try {
|
||||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240));
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240));
|
||||||
ImageView image = new ImageView(Init.context());
|
ImageView image = new ImageView(Init.context());
|
||||||
|
|
@ -266,7 +278,7 @@ public class Bili extends Spider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startService(Resp.Data data) {
|
private void startService(Data data) {
|
||||||
service = Executors.newScheduledThreadPool(1);
|
service = Executors.newScheduledThreadPool(1);
|
||||||
service.scheduleAtFixedRate(() -> {
|
service.scheduleAtFixedRate(() -> {
|
||||||
String url = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + data.getQrcodeKey() + "&source=main_mini";
|
String url = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + data.getQrcodeKey() + "&source=main_mini";
|
||||||
|
|
@ -280,7 +292,7 @@ public class Bili extends Spider {
|
||||||
StringBuilder cookie = new StringBuilder();
|
StringBuilder cookie = new StringBuilder();
|
||||||
String[] splits = Uri.parse(url).getQuery().split("&");
|
String[] splits = Uri.parse(url).getQuery().split("&");
|
||||||
for (String split : splits) cookie.append(split).append(";");
|
for (String split : splits) cookie.append(split).append(";");
|
||||||
Prefers.put("BiliCookie", cookie.toString());
|
FileUtil.write(getUserCache(), cookie.toString());
|
||||||
Init.show("請重新進入播放頁");
|
Init.show("請重新進入播放頁");
|
||||||
stopService();
|
stopService();
|
||||||
}
|
}
|
||||||
|
|
@ -291,7 +303,7 @@ public class Bili extends Spider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismiss(DialogInterface dialog) {
|
private void dismiss(DialogInterface dialog) {
|
||||||
Prefers.put("BiliQRCode", false);
|
FileUtil.write(getUserCache(), COOKIE);
|
||||||
stopService();
|
stopService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
3cc1dc85dad21ad4f41ad8f5139a205e
|
1a95a254c163853dc114032bdc5423a2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue