新增B站AI总结功能
This commit is contained in:
@@ -2,7 +2,9 @@ package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.BiliBili.BiliVideo;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.BiliBiliWbiSign;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
@@ -135,8 +137,51 @@ public class BiliBiliAppUtils {
|
||||
});
|
||||
return task;
|
||||
}
|
||||
public static String getVideoAI(String url){
|
||||
if(url.startsWith("https://b23.tv")){
|
||||
url=b23ToUrl(url);
|
||||
}
|
||||
JSONObject videoInfo = new BiliVideo().getVideoInfo(url);
|
||||
if(videoInfo==null){
|
||||
return null;
|
||||
}
|
||||
String cid = videoInfo.getJSONObject("data").getString("cid");
|
||||
TreeMap<String,String> body=new TreeMap<>();
|
||||
body.put("cid",cid);
|
||||
body.put("up_mid",videoInfo.getJSONObject("data").getJSONObject("owner").getString("mid"));
|
||||
body.put("bvid",videoInfo.getJSONObject("data").getString("bvid"));
|
||||
BiliBiliWbiSign.getWbiSign(body);
|
||||
JSONObject object = BiliBiliUtils.getInstance(QQBotManager.defQQ).http_get("https://api.bilibili.com/x/web-interface/view/conclusion/get"+"?"+HttpTools.toUrlParams(body));
|
||||
if(object.getInteger("code")==0){
|
||||
if(object.getJSONObject("data").getInteger("code")==0) {
|
||||
return object.getJSONObject("data").getJSONObject("model_result").getString("summary");
|
||||
}else{
|
||||
return "没得省流";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String b23ToUrl(String url){
|
||||
try {
|
||||
HttpsURLConnection connection = BiliBiliUtils.getInstance(QQBotManager.defQQ).getBiliHttpGet(url, BiliBiliUtils.getInstance(QQBotManager.defQQ).getCookie());
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.connect();
|
||||
if(connection.getResponseCode()==302){
|
||||
connection.setConnectTimeout(5000);
|
||||
return connection.getHeaderField("Location");
|
||||
}
|
||||
return connection.getURL().toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(new BiliBiliAppUtils(QQBotManager.defQQ).startAppTask().toMessageFormat());
|
||||
BiliBiliWbiSign.updateRawWbiKey();
|
||||
String url="https://b23.tv/NtqDorB?share_medium=android&share_source=qq&bbid=XUDCA4BDD60B5853ACDC17794BFAEF91F874A&ts=1705470976484";
|
||||
// url="https://www.bilibili.com/video/BV1fw411E75p/?buvid=XUDCA4BDD60B5853ACDC17794BFAEF91F874A&from_spmid=tm.recommend.0.0&is_story_h5=false&mid=7G8S%2B4e7nx6XSaU3oMQKXA%3D%3D&p=1&plat_id=116&share_from=ugc&share_medium=android&share_plat=android&share_session_id=ab27db6e-47a5-43b5-b0ec-b027bcfdeccc&share_source=QQ&share_tag=s_i&spmid=main.ugc-video-detail.0.0×tamp=1705470976&unique_k=NtqDorB&up_id=1156809979";
|
||||
String ai = getVideoAI(url);
|
||||
System.out.println("ai = " + ai);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BiliBiliUtils {
|
||||
|
||||
public synchronized JSONObject http_get(String url) {
|
||||
try {
|
||||
// Log.i("调用url = "+url);
|
||||
Log.i("调用url = "+url);
|
||||
HttpsURLConnection connection = getBiliHttpGet(url, getCookie());
|
||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
Reference in New Issue
Block a user