B站下载姬添加直播用户名显示
新增/修改B站直播时自动获取直播用户名
This commit is contained in:
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.mybatis.dao.BilibiliLiveDao;
|
||||
import com.yutou.tools.mybatis.model.BilibiliLive;
|
||||
import com.yutou.tools.mybatis.model.BilibiliLiveExample;
|
||||
import com.yutou.tools.utils.BiliBiliLiveTools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -39,6 +40,7 @@ public class Live {
|
||||
}catch (Exception e){
|
||||
live.setCid(-1);
|
||||
}
|
||||
live.setTitle(BiliBiliLiveTools.getLiveUserName(live.getCid()+""));
|
||||
bilibiliLiveDao.insert(live);
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",0);
|
||||
@@ -77,6 +79,7 @@ public class Live {
|
||||
if(!StringUtils.isEmpty(status)){
|
||||
live.setStatus(Integer.parseInt(status));
|
||||
}
|
||||
live.setTitle(BiliBiliLiveTools.getLiveUserName(live.getCid()+""));
|
||||
int code=bilibiliLiveDao.updateByPrimaryKey(live);
|
||||
json.put("code",code);
|
||||
json.put("msg","ok");
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
package com.yutou.tools.bangumi;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.utils.BiliBiliLiveTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class AnimationData {
|
||||
@@ -53,8 +61,6 @@ public class AnimationData {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
AnimationData data=new AnimationData();
|
||||
int i=data.nameToValue("极影字幕社",true);
|
||||
System.out.println(i);
|
||||
System.out.println(BiliBiliLiveTools.getLiveUserName("59901"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import lombok.Data;
|
||||
public class BilibiliLive implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String url;
|
||||
|
||||
private Integer cid;
|
||||
|
||||
@@ -165,6 +165,76 @@ public class BilibiliLiveExample {
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIsNull() {
|
||||
addCriterion("title is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIsNotNull() {
|
||||
addCriterion("title is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleEqualTo(String value) {
|
||||
addCriterion("title =", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotEqualTo(String value) {
|
||||
addCriterion("title <>", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleGreaterThan(String value) {
|
||||
addCriterion("title >", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("title >=", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLessThan(String value) {
|
||||
addCriterion("title <", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLessThanOrEqualTo(String value) {
|
||||
addCriterion("title <=", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLike(String value) {
|
||||
addCriterion("title like", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotLike(String value) {
|
||||
addCriterion("title not like", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIn(List<String> values) {
|
||||
addCriterion("title in", values, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotIn(List<String> values) {
|
||||
addCriterion("title not in", values, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleBetween(String value1, String value2) {
|
||||
addCriterion("title between", value1, value2, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotBetween(String value1, String value2) {
|
||||
addCriterion("title not between", value1, value2, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUrlIsNull() {
|
||||
addCriterion("url is null");
|
||||
return (Criteria) this;
|
||||
|
||||
31
src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java
Normal file
31
src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class BiliBiliLiveTools {
|
||||
public static String getLiveUserName(String cid){
|
||||
try {
|
||||
HttpsURLConnection connection= (HttpsURLConnection) new URL("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id="+cid).openConnection();
|
||||
connection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36");
|
||||
BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String tmp;
|
||||
StringBuilder str= new StringBuilder();
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
str.append(tmp);
|
||||
}
|
||||
JSONObject json= JSON.parseObject(str.toString());
|
||||
reader.close();
|
||||
return json.getJSONObject("data").getJSONObject("anchor_info").getJSONObject("base_info").getString("uname");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user