B站下载姬添加直播用户名显示

新增/修改B站直播时自动获取直播用户名
This commit is contained in:
yutou 2020-10-13 18:19:41 +08:00
parent c62f6a59b9
commit 4e69d01c02
9 changed files with 139 additions and 11 deletions

View File

@ -10,7 +10,7 @@
</parent>
<groupId>com.yutou</groupId>
<artifactId>tools</artifactId>
<version>1.0.9.1</version>
<version>1.0.9.3</version>
<name>tools</name>
<description>Demo project for Spring Boot</description>

View File

@ -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");

View File

@ -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"));
}
}

View File

@ -12,6 +12,8 @@ import lombok.Data;
public class BilibiliLive implements Serializable {
private Integer id;
private String title;
private String url;
private Integer cid;

View File

@ -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;

View 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;
}
}

View File

@ -3,6 +3,7 @@
<mapper namespace="com.yutou.tools.mybatis.dao.BilibiliLiveDao">
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.BilibiliLive">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="cid" jdbcType="INTEGER" property="cid" />
<result column="status" jdbcType="INTEGER" property="status" />
@ -67,7 +68,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, url, cid, `status`, createTime
id, title, url, cid, `status`, createTime
</sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.BilibiliLiveExample" resultMap="BaseResultMap">
select
@ -100,14 +101,17 @@
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.BilibiliLive" useGeneratedKeys="true">
insert into bilibili_live (url, cid, `status`,
createTime)
values (#{url,jdbcType=VARCHAR}, #{cid,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
#{createtime,jdbcType=TIMESTAMP})
insert into bilibili_live (title, url, cid,
`status`, createTime)
values (#{title,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{cid,jdbcType=INTEGER},
#{status,jdbcType=INTEGER}, #{createtime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.BilibiliLive" useGeneratedKeys="true">
insert into bilibili_live
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">
title,
</if>
<if test="url != null">
url,
</if>
@ -122,6 +126,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="url != null">
#{url,jdbcType=VARCHAR},
</if>
@ -148,6 +155,9 @@
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR},
</if>
<if test="record.url != null">
url = #{record.url,jdbcType=VARCHAR},
</if>
@ -168,6 +178,7 @@
<update id="updateByExample" parameterType="map">
update bilibili_live
set id = #{record.id,jdbcType=INTEGER},
title = #{record.title,jdbcType=VARCHAR},
url = #{record.url,jdbcType=VARCHAR},
cid = #{record.cid,jdbcType=INTEGER},
`status` = #{record.status,jdbcType=INTEGER},
@ -179,6 +190,9 @@
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.tools.mybatis.model.BilibiliLive">
update bilibili_live
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
@ -196,7 +210,8 @@
</update>
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.BilibiliLive">
update bilibili_live
set url = #{url,jdbcType=VARCHAR},
set title = #{title,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
cid = #{cid,jdbcType=INTEGER},
`status` = #{status,jdbcType=INTEGER},
createTime = #{createtime,jdbcType=TIMESTAMP}

View File

@ -46,6 +46,7 @@
, page: true
, cols: [[
{ field: "id", title: "id", width: 80, sort: true, fixed: 'left' }
, { field: 'title', title: '直播间', width: 200 }
, { field: 'cid', title: 'cid', width: 100 }
, { field: 'url', title: 'url', width: 400 }
, { field: 'status', title: '状态', width: 80 }

View File

@ -105,7 +105,7 @@
})
})
$(document).ready(function () {
let mobile = navigator.userAgent.toLowerCase().match(/android/i) == "android" || navigator.userAgent.toLowerCase().match(/iphone os/i) == "iphone os";
let mobile = navigator.userAgent.toLowerCase().match(/android/i) === "android" || navigator.userAgent.toLowerCase().match(/iphone os/i) === "iphone os";
if (mobile) {
$('.layui-body').css('left', '0')
$('.layui-body').css('top', '150px')