From 4e69d01c021273df95c05b44b094645895241d26 Mon Sep 17 00:00:00 2001 From: yutou Date: Tue, 13 Oct 2020 18:19:41 +0800 Subject: [PATCH] =?UTF-8?q?B=E7=AB=99=E4=B8=8B=E8=BD=BD=E5=A7=AC=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=B4=E6=92=AD=E7=94=A8=E6=88=B7=E5=90=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20=E6=96=B0=E5=A2=9E/=E4=BF=AE=E6=94=B9B=E7=AB=99?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=97=B6=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/yutou/tools/BiliBili/Live.java | 3 + .../yutou/tools/bangumi/AnimationData.java | 12 +++- .../tools/mybatis/model/BilibiliLive.java | 2 + .../mybatis/model/BilibiliLiveExample.java | 70 +++++++++++++++++++ .../yutou/tools/utils/BiliBiliLiveTools.java | 31 ++++++++ src/main/resources/mapper/BilibiliLiveDao.xml | 27 +++++-- web/html/body/nas/bilidown.html | 1 + web/html/header.html | 2 +- 9 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java diff --git a/pom.xml b/pom.xml index c8908e6..669f195 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.yutou tools - 1.0.9.1 + 1.0.9.3 tools Demo project for Spring Boot diff --git a/src/main/java/com/yutou/tools/BiliBili/Live.java b/src/main/java/com/yutou/tools/BiliBili/Live.java index 088508e..9ecdd5e 100644 --- a/src/main/java/com/yutou/tools/BiliBili/Live.java +++ b/src/main/java/com/yutou/tools/BiliBili/Live.java @@ -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"); diff --git a/src/main/java/com/yutou/tools/bangumi/AnimationData.java b/src/main/java/com/yutou/tools/bangumi/AnimationData.java index cc3ecfc..6cd207f 100644 --- a/src/main/java/com/yutou/tools/bangumi/AnimationData.java +++ b/src/main/java/com/yutou/tools/bangumi/AnimationData.java @@ -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")); } } diff --git a/src/main/java/com/yutou/tools/mybatis/model/BilibiliLive.java b/src/main/java/com/yutou/tools/mybatis/model/BilibiliLive.java index f363417..fdfce19 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/BilibiliLive.java +++ b/src/main/java/com/yutou/tools/mybatis/model/BilibiliLive.java @@ -12,6 +12,8 @@ import lombok.Data; public class BilibiliLive implements Serializable { private Integer id; + private String title; + private String url; private Integer cid; diff --git a/src/main/java/com/yutou/tools/mybatis/model/BilibiliLiveExample.java b/src/main/java/com/yutou/tools/mybatis/model/BilibiliLiveExample.java index 22806f7..8c3314b 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/BilibiliLiveExample.java +++ b/src/main/java/com/yutou/tools/mybatis/model/BilibiliLiveExample.java @@ -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 values) { + addCriterion("title in", values, "title"); + return (Criteria) this; + } + + public Criteria andTitleNotIn(List 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; diff --git a/src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java b/src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java new file mode 100644 index 0000000..7a8d2d8 --- /dev/null +++ b/src/main/java/com/yutou/tools/utils/BiliBiliLiveTools.java @@ -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; + } +} diff --git a/src/main/resources/mapper/BilibiliLiveDao.xml b/src/main/resources/mapper/BilibiliLiveDao.xml index 34dc112..790310f 100644 --- a/src/main/resources/mapper/BilibiliLiveDao.xml +++ b/src/main/resources/mapper/BilibiliLiveDao.xml @@ -3,6 +3,7 @@ + @@ -67,7 +68,7 @@ - id, url, cid, `status`, createTime + id, title, url, cid, `status`, createTime