From d9ec69369440ac6648fb0d5a00660335b864efc7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 11 Apr 2022 19:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/yutou/bilibili/BiliBili/Live.java | 7 +------ .../java/com/yutou/bilibili/BiliBili/LiveUtils.java | 12 ++++-------- .../com/yutou/bilibili/Tools/ApplicationInit.java | 4 ++-- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 5d8cfa2..73ced4c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ bilibili Demo project for Spring Boot - 17 + 1.8 1.6.10 diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index e288a8c..ee2957e 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -312,13 +312,8 @@ public class Live implements ApplicationContextAware { } catch (Exception e) { int popular = LiveUtils.bytesToInt2(bytes, 0); info.setPopular(popular); - if(popular>1){ - upData.setLive(1); - }else{ - upData.setLive(0); - } - Log.i(upData.getRoomid()+" >>> "+upData.getLive()+" >> "+popular); } + upData.setLive(LiveUtils.getLiveState(roomId)?1:0); } } catch (Exception e) { diff --git a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java index d865b9c..6f9358c 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java @@ -348,14 +348,14 @@ public class LiveUtils { } public static JSONObject getLiveInfo(int roomId) { - return http_get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + roomId); + return http_get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + roomId+"&protocol=0,1&format=0,1,2&codec=0,1&qn=10000&platform=web&ptype=8"); } - private static JSONObject getLiveState(int roomId){ - return http_get("https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id=" + roomId); + public static boolean getLiveState(int roomId){ + return liveStateMap.get(roomId); } public static void reloadLiveState(int roomId){ - JSONObject json = getLiveState(roomId); + JSONObject json = getLiveInfo(roomId); if(json!=null){ liveStateMap.put(roomId,json.getJSONObject("data").getInteger("live_status") == 1); } @@ -426,10 +426,6 @@ public class LiveUtils { } public static void main(String[] args) { - int index=1000; - for (int i = 0; i < index; i++) { - LiveUtils.getLiveInfo(21686237); - } } } diff --git a/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java b/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java index 58aaab5..0e04066 100644 --- a/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java +++ b/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java @@ -52,10 +52,10 @@ public class ApplicationInit implements ApplicationRunner { public void run() { Date date = new Date(); String time = new SimpleDateFormat("HH:mm").format(date); - checkLive(); if (time.equals(oldTime)) { return; } + checkLive(); oldTime = time; switch (time) { case "00:00": @@ -94,7 +94,7 @@ public class ApplicationInit implements ApplicationRunner { private void checkLive() { for (BilibiliUpInfo info : service.getUpInfo()) { - // LiveUtils.reloadLiveState(info.getRoomid()); + LiveUtils.reloadLiveState(info.getRoomid()); if (info.getOfflinelistening() == 1) { if (info.getEnable() == 1) { Live live = LiveUtils.liveContains(info);