修复直播状态

This commit is contained in:
Yutousama 2022-04-11 19:00:07 +08:00
parent 0158f2ebf0
commit d9ec693694
4 changed files with 8 additions and 17 deletions

View File

@ -14,7 +14,7 @@
<name>bilibili</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<java.version>1.8</java.version>
<kotlin.version>1.6.10</kotlin.version>
</properties>
<dependencies>

View File

@ -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) {

View File

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

View File

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