更新B站下载视频接口

This commit is contained in:
Yutou 2024-01-18 16:53:03 +08:00
parent 4dce74eaf8
commit af18663759
3 changed files with 19 additions and 8 deletions

View File

@ -3,4 +3,7 @@ package com.yutou.bilibili.api;
public class VideoApi {
public static final String VIDEO_AI = "https://api.bilibili.com/x/web-interface/view/conclusion/get";
@Deprecated
public static final String VIDEO_PLAY_URL = "https://api.bilibili.com/x/player/playurl";
public static final String VIDEO_PLAY_URL_V2 = "https://api.bilibili.com/x/player/wbi/playurl";
}

View File

@ -2,6 +2,7 @@ package com.yutou.qqbot.models.BiliBili;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.bilibili.api.VideoApi;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.QQNumberManager;
@ -158,7 +159,7 @@ public class BiliVideo extends Model {
json.put("avid", infoData.getLong("aid"));
if (eps.containsKey("cid")) {
json.put("cid", eps.getLong("cid"));
json.put("qn", 127);
json.put("qn", 125);
json.put("fnval", 80);
json.put("fourk", 1);
downVideo(json, eps);
@ -172,7 +173,7 @@ public class BiliVideo extends Model {
JSONObject item = (JSONObject) o;
json.put("avid", item.getLong("aid"));
json.put("cid", item.getLong("cid"));
json.put("qn", 127);
json.put("qn", 125);
json.put("fnval", 80);
json.put("fourk", 1);
item.put("title", eps.getString("title") + "$(File.separator)" + item.getString("title"));
@ -259,7 +260,8 @@ public class BiliVideo extends Model {
if (tmp.exists()) {
return;
}
JSONObject http = biliUtils.http("https://api.bilibili.com/x/player/playurl?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON);
TreeMap<String,String> body=BiliBiliWbiSign.getWbiSign(json);
JSONObject http = biliUtils.http(VideoApi.VIDEO_PLAY_URL_V2+"?" + HttpTools.toUrlParams(body), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON);
if (http.getInteger("code") == 0) {
JSONObject data = http.getJSONObject("data");
JSONObject dash = data.getJSONObject("dash");
@ -399,14 +401,12 @@ public class BiliVideo extends Model {
public static void main(String[] args) {
BiliVideo video = new BiliVideo(QQBotManager.defQQ);
JSONObject login = new BiliLogin(QQBotManager.defQQ).login();
System.out.println(login);
//岚少 480
//video.downVideo("https://www.bilibili.com/video/BV1Ps411m7pt?spm_id_from=333.999.0.0");
//唐诱 合集
//video.downVideo("https://www.bilibili.com/video/BV1Vv4y1K7ox?spm_id_from=444.41.top_right_bar_window_default_collection.content.click");
//邦邦 长视频
// video.downVideo("https://www.bilibili.com/video/BV1w5411271A?spm_id_from=444.41.list.card_archive.click");
video.downVideo("https://www.bilibili.com/video/BV1w5411271A?spm_id_from=444.41.list.card_archive.click");
//LK 超清4k hdr
//video.downVideo("https://www.bilibili.com/video/BV1uZ4y1U7h8/?spm_id_from=333.788.recommend_more_video.-1");
// hdr
@ -423,7 +423,7 @@ public class BiliVideo extends Model {
// int a=16|2048;
// System.out.println("a = " + a);
//video.downDanmu(428855000L,976216102L,"【都市_情感】《唐可可的诱惑》第一集",1);
video.downVideo("https://www.bilibili.com/bangumi/play/ep776259", false, false);// ep5
//video.downVideo("https://www.bilibili.com/bangumi/play/ep776259", false, false);// ep5
System.out.println("事件结束");
}
}

View File

@ -31,7 +31,13 @@ public class BiliBiliWbiSign {
body.put("w_rid", AppTools.getMD5(params + genMixinKey(rawWbiKey)));
return body;
}
public static TreeMap<String, String> getWbiSign(JSONObject json) {
TreeMap<String, String> body=new TreeMap<>();
for (String key : json.keySet()) {
body.put(key, json.getString(key));
}
return getWbiSign(body);
}
private static String genMixinKey(String rawWbiKey) {
byte[] rawBytes = rawWbiKey.getBytes(StandardCharsets.UTF_8);
byte[] mixinKey = new byte[32];
@ -71,4 +77,6 @@ public class BiliBiliWbiSign {
//https://api.bilibili.com/x/web-interface/view/conclusion/get?bvid=BV1L94y1H7CV&cid=1335073288&up_mid=297242063&web_location=333.788&w_rid=a5d90f60ac6b6b6fc9d49be3ba3fee53&wts=1705394671
//updateRawWbiKey();
}
}