update
This commit is contained in:
parent
be3e3bbf9d
commit
57ec517608
@ -152,6 +152,10 @@ public class Live implements ApplicationContextAware {
|
|||||||
header.put("Pragma", "no-cache");
|
header.put("Pragma", "no-cache");
|
||||||
header.put("Upgrade", "websocket");
|
header.put("Upgrade", "websocket");
|
||||||
header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36");
|
header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36");
|
||||||
|
if (client != null && !client.isClosed()) {
|
||||||
|
stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
client = new WebSocketClient(new URI(url), header) {
|
client = new WebSocketClient(new URI(url), header) {
|
||||||
private long time = 0;
|
private long time = 0;
|
||||||
private boolean init = true;
|
private boolean init = true;
|
||||||
@ -223,6 +227,14 @@ public class Live implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
client.connect();
|
client.connect();
|
||||||
|
new Timer().schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (client == null || client.isClosed()) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@ -294,9 +306,9 @@ public class Live implements ApplicationContextAware {
|
|||||||
if (data.length > 32) {
|
if (data.length > 32) {
|
||||||
List<String> list = LiveUtils.getMsgList(LiveUtils.dec(bytes), new ArrayList<>(), true);
|
List<String> list = LiveUtils.getMsgList(LiveUtils.dec(bytes), new ArrayList<>(), true);
|
||||||
String tmp = "";
|
String tmp = "";
|
||||||
for (int i=0;i<list.size();i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
processData(list.get(i), data);
|
processData(list.get(i), data);
|
||||||
tmp +="|||"+i+"[start] "+ list.get(i)+ " [end]||| ";
|
tmp += "|||" + i + "[start] " + list.get(i) + " [end]||| ";
|
||||||
}
|
}
|
||||||
// Log.i(AppTools.getToDayTimeToString(startTime), roomId, "list size = " + list.size() + " data = " + tmp);
|
// Log.i(AppTools.getToDayTimeToString(startTime), roomId, "list size = " + list.size() + " data = " + tmp);
|
||||||
} else {
|
} else {
|
||||||
@ -306,9 +318,9 @@ public class Live implements ApplicationContextAware {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
int popular = LiveUtils.bytesToInt2(bytes, 0);
|
int popular = LiveUtils.bytesToInt2(bytes, 0);
|
||||||
info.setPopular(popular);
|
info.setPopular(popular);
|
||||||
if(popular>1){
|
if (popular > 1) {
|
||||||
upData.setLive(1);
|
upData.setLive(1);
|
||||||
}else{
|
} else {
|
||||||
upData.setLive(0);
|
upData.setLive(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,18 +362,8 @@ public class Live implements ApplicationContextAware {
|
|||||||
BilibiliLiveData liveData = new BilibiliLiveData();
|
BilibiliLiveData liveData = new BilibiliLiveData();
|
||||||
String danmu;
|
String danmu;
|
||||||
GiftData giftData;
|
GiftData giftData;
|
||||||
Log.i(AppTools.getToDayTime(),roomId,json.toJSONString());
|
Log.i(AppTools.getToDayTime(), roomId, json.toJSONString());
|
||||||
switch (json.getString("cmd")) {
|
if (json.getString("cmd").startsWith("DANMU_MSG")) {//普通弹幕
|
||||||
case "INTERACT_WORD"://普通用户进直播间
|
|
||||||
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
|
||||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
|
||||||
liveData.setType(LiveData.INTERACT_WORD);
|
|
||||||
liveData.setMsg(danmu);
|
|
||||||
liveData.setRoomid(roomId);
|
|
||||||
liveData.setSubtime(new Date());
|
|
||||||
service.addLiveData(liveData);
|
|
||||||
break;
|
|
||||||
case "DANMU_MSG"://普通弹幕
|
|
||||||
JSONArray infoData = json.getJSONArray("info");
|
JSONArray infoData = json.getJSONArray("info");
|
||||||
danmu = json.getJSONArray("info").getString(1);
|
danmu = json.getJSONArray("info").getString(1);
|
||||||
DanmuData danmuData = new DanmuData();
|
DanmuData danmuData = new DanmuData();
|
||||||
@ -379,6 +381,19 @@ public class Live implements ApplicationContextAware {
|
|||||||
danmuManager.addDanmu(danmuData);
|
danmuManager.addDanmu(danmuData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch (json.getString("cmd")) {
|
||||||
|
case "INTERACT_WORD"://普通用户进直播间
|
||||||
|
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
||||||
|
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||||
|
liveData.setType(LiveData.INTERACT_WORD);
|
||||||
|
liveData.setMsg(danmu);
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "DANMU_MSG":
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "SEND_GIFT"://送礼
|
case "SEND_GIFT"://送礼
|
||||||
data = json.getJSONObject("data");
|
data = json.getJSONObject("data");
|
||||||
@ -530,7 +545,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
//com.yutou.bilibili.Tools.Log.i(msg);
|
//com.yutou.bilibili.Tools.Log.i(msg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
com.yutou.bilibili.Tools.Log.i("["+roomId+"]"+msg);
|
Log.i("[" + roomId + "]" + msg);
|
||||||
liveData = new BilibiliLiveData();
|
liveData = new BilibiliLiveData();
|
||||||
liveData.setType(LiveData.UNKNOWN_MESSAGE);
|
liveData.setType(LiveData.UNKNOWN_MESSAGE);
|
||||||
liveData.setUid(-1);
|
liveData.setUid(-1);
|
||||||
@ -539,6 +554,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
liveData.setSubtime(new Date());
|
liveData.setSubtime(new Date());
|
||||||
service.addLiveData(liveData);
|
service.addLiveData(liveData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class BilibiliApplication {
|
public class BilibiliApplication {
|
||||||
|
|
||||||
public static String version="0.7.4.5";
|
public static String version="0.7.4.7";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
QQBotManager.getInstance().init();
|
QQBotManager.getInstance().init();
|
||||||
|
@ -58,6 +58,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
private final static String QQ_LIVE_TO_DAY_DATE = "!今日数据";
|
private final static String QQ_LIVE_TO_DAY_DATE = "!今日数据";
|
||||||
private final static String QQ_LIVE_DATE = "!数据";
|
private final static String QQ_LIVE_DATE = "!数据";
|
||||||
private final static String QQ_LIVE_USE_SAVE = "!启动录播";
|
private final static String QQ_LIVE_USE_SAVE = "!启动录播";
|
||||||
|
private final static String QQ_LIVE_RELINK="!relink";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static QQBotManager botManager = null;
|
private static QQBotManager botManager = null;
|
||||||
@ -308,6 +309,11 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
getInstance().sendMessage(builder.toString());
|
getInstance().sendMessage(builder.toString());
|
||||||
break;
|
break;
|
||||||
|
case QQCommands.QQ_LIVE_RELINK:
|
||||||
|
for (Live live : Live.lives.values()) {
|
||||||
|
live.stop();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (msg.startsWith(QQCommands.QQ_LIVE_TO_DAY_DATE)) {
|
if (msg.startsWith(QQCommands.QQ_LIVE_TO_DAY_DATE)) {
|
||||||
try {
|
try {
|
||||||
|
@ -33,26 +33,30 @@ public class BilibiliLiveInfo implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPopular() {
|
public Integer getPopular() {
|
||||||
if(popular==null)
|
if(popular==null) {
|
||||||
popular=0;
|
popular=0;
|
||||||
|
}
|
||||||
return popular;
|
return popular;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getUserindex() {
|
public Integer getUserindex() {
|
||||||
if(userindex==null)
|
if(userindex==null) {
|
||||||
userindex=0;
|
userindex=0;
|
||||||
|
}
|
||||||
return userindex;
|
return userindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getVipuserindex() {
|
public Integer getVipuserindex() {
|
||||||
if(vipuserindex==null)
|
if(vipuserindex==null) {
|
||||||
vipuserindex=0;
|
vipuserindex=0;
|
||||||
|
}
|
||||||
return vipuserindex;
|
return vipuserindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getGiftuser() {
|
public Integer getGiftuser() {
|
||||||
if(giftuser==null)
|
if(giftuser==null) {
|
||||||
giftuser=0;
|
giftuser=0;
|
||||||
|
}
|
||||||
return giftuser;
|
return giftuser;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user