修复直播状态

This commit is contained in:
Yutousama 2022-04-11 19:02:24 +08:00
parent d9ec693694
commit 78abe9a16b

View File

@ -25,7 +25,7 @@ import java.util.zip.Inflater;
public class LiveUtils {
private static String cookie = null;
private static Map<Integer,Boolean> liveStateMap=new HashMap<>();
private static Map<Integer, Boolean> liveStateMap = new HashMap<>();
public LiveUtils() {
@ -53,7 +53,8 @@ public class LiveUtils {
}
}
}
public static String getHex(byte[] bytes){
public static String getHex(byte[] bytes) {
return DatatypeConverter.printHexBinary(bytes);
}
@ -348,21 +349,27 @@ 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+"&protocol=0,1&format=0,1,2&codec=0,1&qn=10000&platform=web&ptype=8");
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");
}
public static boolean getLiveState(int roomId){
public static boolean getLiveState(int roomId) {
return liveStateMap.get(roomId);
}
public static void reloadLiveState(int roomId){
public static void reloadLiveState(int roomId) {
JSONObject json = getLiveInfo(roomId);
if(json!=null){
liveStateMap.put(roomId,json.getJSONObject("data").getInteger("live_status") == 1);
if (json != null) {
try {
liveStateMap.put(roomId, json.getJSONObject("data").getInteger("live_status") == 1);
} catch (Exception e) {
System.out.println("json = " + json);
}
}
}
public static String getLiveTitle(int roomId) {
JSONObject json =getLiveInfo(roomId);
JSONObject json = getLiveInfo(roomId);
if (json != null) {
return json.getJSONObject("data").getJSONObject("room_info").getString("title");
}
@ -375,10 +382,10 @@ public class LiveUtils {
}
reloadLiveState(roomId);
return false;*/
if(!Live.lives.containsKey(roomId)){
if (!Live.lives.containsKey(roomId)) {
return false;
}
return Live.lives.get(roomId).geData().getLive()==1;
return Live.lives.get(roomId).geData().getLive() == 1;
}
private static void checkLiveSave(int roomId) {
@ -413,13 +420,13 @@ public class LiveUtils {
public void init() {
JSONObject json = http_get("https://api.live.bilibili.com/xlive/web-room/v1/giftPanel/giftConfig?platform=pc");
if(json==null){
if (json == null) {
return;
}
JSONArray list = json.getJSONObject("data").getJSONArray("list");
for (Object o : list) {
JSONObject item = (JSONObject) o;
RedisTools.set(2,"bili_gift_"+item.getInteger("id"),item.toJSONString());
RedisTools.set(2, "bili_gift_" + item.getInteger("id"), item.toJSONString());
}
}