完善机器人功能
使用缓存来存储直播信息,防止频繁请求导致412问题
This commit is contained in:
parent
ab6bfbfd42
commit
9b7633e8a9
2
.mvn/wrapper/MavenWrapperDownloader.java
vendored
2
.mvn/wrapper/MavenWrapperDownloader.java
vendored
@ -90,7 +90,7 @@ public class MavenWrapperDownloader {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
com.yutou.bilibili.Tools.Log.i("- Error downloading");
|
com.yutou.bilibili.Tools.Log.i("- Error downloading");
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.yutou.bilibili.BiliBili.Live;
|
|||||||
import com.yutou.bilibili.BiliBili.LiveUtils;
|
import com.yutou.bilibili.BiliBili.LiveUtils;
|
||||||
import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService;
|
import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService;
|
||||||
import com.yutou.bilibili.Tools.AppTools;
|
import com.yutou.bilibili.Tools.AppTools;
|
||||||
|
import com.yutou.bilibili.Tools.Log;
|
||||||
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliLiveInfo;
|
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliLiveInfo;
|
||||||
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -28,7 +29,7 @@ public class RealTimeDataController {
|
|||||||
IBiliBiliLiveService service;
|
IBiliBiliLiveService service;
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("get/query.do")
|
@RequestMapping("get/query.do")
|
||||||
public JSONObject queryToDayLiveData(int roomid,Date startTime,Date endTime) throws ParseException {
|
public JSONObject queryToDayLiveData(int roomid,Date startTime,Date endTime){
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
BilibiliUpInfo info = new BilibiliUpInfo();
|
BilibiliUpInfo info = new BilibiliUpInfo();
|
||||||
info.setRoomid(roomid);
|
info.setRoomid(roomid);
|
||||||
|
@ -38,6 +38,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
|
|
||||||
|
|
||||||
public static List<Live> lives = new ArrayList<>();
|
public static List<Live> lives = new ArrayList<>();
|
||||||
|
public static List<String> liveOfRoomId = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
private int roomId;
|
private int roomId;
|
||||||
@ -119,6 +120,10 @@ public class Live implements ApplicationContextAware {
|
|||||||
* @throws Exception 发生异常
|
* @throws Exception 发生异常
|
||||||
*/
|
*/
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
if(liveOfRoomId.contains(roomId+"")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
liveOfRoomId.add(roomId+"");
|
||||||
run = true;
|
run = true;
|
||||||
if (LiveUtils.isLivePlayer(roomId)) {
|
if (LiveUtils.isLivePlayer(roomId)) {
|
||||||
upData.setLive(1);
|
upData.setLive(1);
|
||||||
@ -196,6 +201,8 @@ public class Live implements ApplicationContextAware {
|
|||||||
public void onClosing(int code, String reason, boolean remote) {
|
public void onClosing(int code, String reason, boolean remote) {
|
||||||
super.onClosing(code, reason, remote);
|
super.onClosing(code, reason, remote);
|
||||||
com.yutou.bilibili.Tools.Log.i("code = " + code + ", reason = " + reason + ", remote = " + remote);
|
com.yutou.bilibili.Tools.Log.i("code = " + code + ", reason = " + reason + ", remote = " + remote);
|
||||||
|
run = false;
|
||||||
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -214,6 +221,9 @@ public class Live implements ApplicationContextAware {
|
|||||||
if (danmuManager != null) {
|
if (danmuManager != null) {
|
||||||
danmuManager.close();
|
danmuManager.close();
|
||||||
}
|
}
|
||||||
|
if(liveOfRoomId.contains(roomId+"")){
|
||||||
|
liveOfRoomId.remove(roomId+"");
|
||||||
|
}
|
||||||
if (SaveLive.getInstance().checkLive(roomId)) {
|
if (SaveLive.getInstance().checkLive(roomId)) {
|
||||||
SaveLive.getInstance().stop(roomId);
|
SaveLive.getInstance().stop(roomId);
|
||||||
}
|
}
|
||||||
@ -318,7 +328,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
* @param msg 数据json
|
* @param msg 数据json
|
||||||
* @param bytes 原始hex数据
|
* @param bytes 原始hex数据
|
||||||
*/
|
*/
|
||||||
public void processData(String msg, byte[] bytes) {
|
public synchronized void processData(String msg, byte[] bytes) {
|
||||||
try {
|
try {
|
||||||
JSONObject json = JSONObject.parseObject(msg);
|
JSONObject json = JSONObject.parseObject(msg);
|
||||||
JSONObject data;
|
JSONObject data;
|
||||||
@ -328,8 +338,8 @@ public class Live implements ApplicationContextAware {
|
|||||||
|
|
||||||
switch (json.getString("cmd")) {
|
switch (json.getString("cmd")) {
|
||||||
case "INTERACT_WORD"://普通用户进直播间
|
case "INTERACT_WORD"://普通用户进直播间
|
||||||
// com.yutou.bilibili.Tools.Log.i(json.getJSONObject("data").getString("uname") + " 进入到直播间");
|
|
||||||
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
||||||
|
//com.yutou.bilibili.Tools.Log.i(danmu);
|
||||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||||
liveData.setType(LiveData.INTERACT_WORD);
|
liveData.setType(LiveData.INTERACT_WORD);
|
||||||
liveData.setMsg(danmu);
|
liveData.setMsg(danmu);
|
||||||
@ -460,17 +470,13 @@ public class Live implements ApplicationContextAware {
|
|||||||
info.setGiftuser(info.getGiftuser() + 1);
|
info.setGiftuser(info.getGiftuser() + 1);
|
||||||
service.addLiveData(liveData);
|
service.addLiveData(liveData);
|
||||||
break;
|
break;
|
||||||
case "SUPER_CHAT_MESSAGE_JPN":
|
|
||||||
case "NOTICE_MSG":
|
|
||||||
case "HOT_RANK_CHANGED"://榜单更新等无用信息
|
|
||||||
case "ONLINE_RANK_COUNT":
|
|
||||||
case "ONLINE_RANK_V2":
|
|
||||||
case "ONLINE_RANK_TOP3":
|
|
||||||
case "ROOM_REAL_TIME_MESSAGE_UPDATE":
|
|
||||||
case "WIDGET_BANNER"://鬼知道是啥
|
|
||||||
case "HOT_RANK_SETTLEMENT":
|
|
||||||
case "LIVE"://开始直播,不过有在心跳包上做检测了,所以也无所谓?
|
case "LIVE"://开始直播,不过有在心跳包上做检测了,所以也无所谓?
|
||||||
JSONObject liveInfo = LiveUtils.getLiveInfo(roomId);
|
if (upData.getLive() == 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
upData.setLive(1);
|
||||||
|
LiveUtils.LiveInfoManager.getInstance().check(roomId);
|
||||||
|
JSONObject liveInfo = LiveUtils.LiveInfoManager.getInstance().getInfo(roomId);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(upData.getName()).append("开播了!").append("\n");
|
builder.append(upData.getName()).append("开播了!").append("\n");
|
||||||
builder.append(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("title"));
|
builder.append(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("title"));
|
||||||
@ -482,6 +488,19 @@ public class Live implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "PREPARING":
|
||||||
|
upData.setLive(0);
|
||||||
|
QQBotManager.getInstance().sendMessage(upData.getName() + " 已下播");
|
||||||
|
break;
|
||||||
|
case "SUPER_CHAT_MESSAGE_JPN":
|
||||||
|
case "NOTICE_MSG":
|
||||||
|
case "HOT_RANK_CHANGED"://榜单更新等无用信息
|
||||||
|
case "ONLINE_RANK_COUNT":
|
||||||
|
case "ONLINE_RANK_V2":
|
||||||
|
case "ONLINE_RANK_TOP3":
|
||||||
|
case "ROOM_REAL_TIME_MESSAGE_UPDATE":
|
||||||
|
case "WIDGET_BANNER"://鬼知道是啥
|
||||||
|
case "HOT_RANK_SETTLEMENT":
|
||||||
case "PK_BATTLE_SETTLE_V2":
|
case "PK_BATTLE_SETTLE_V2":
|
||||||
case "PK_BATTLE_END":
|
case "PK_BATTLE_END":
|
||||||
case "PK_BATTLE_SETTLE":
|
case "PK_BATTLE_SETTLE":
|
||||||
|
@ -49,7 +49,7 @@ public class LiveController {
|
|||||||
live.add(data.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
live.add(data.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
||||||
live.start();
|
live.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService;
|
import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService;
|
||||||
|
import com.yutou.bilibili.BiliBili.Tools.SaveLive;
|
||||||
import com.yutou.bilibili.Tools.AppTools;
|
import com.yutou.bilibili.Tools.AppTools;
|
||||||
import com.yutou.bilibili.Tools.Log;
|
import com.yutou.bilibili.Tools.Log;
|
||||||
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
||||||
@ -66,7 +67,7 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
output = o.toByteArray();
|
output = o.toByteArray();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
// com.yutou.bilibili.Tools.Log.e(e);
|
||||||
try {
|
try {
|
||||||
JSONObject json = JSONObject.parseObject(new String(data, StandardCharsets.UTF_8));
|
JSONObject json = JSONObject.parseObject(new String(data, StandardCharsets.UTF_8));
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@ -81,7 +82,7 @@ public class LiveUtils {
|
|||||||
try {
|
try {
|
||||||
o.close();
|
o.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ public class LiveUtils {
|
|||||||
list.add(new String(bytes, StandardCharsets.UTF_8));
|
list.add(new String(bytes, StandardCharsets.UTF_8));
|
||||||
return list;
|
return list;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
datas.clear();
|
datas.clear();
|
||||||
@ -161,6 +162,7 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public static String createCookie(){
|
/* public static String createCookie(){
|
||||||
String bid="AUTO"+AppTools.randomString(16,new String[]{AppTools.numbers});
|
String bid="AUTO"+AppTools.randomString(16,new String[]{AppTools.numbers});
|
||||||
bid="AUTO6616152607312876";
|
bid="AUTO6616152607312876";
|
||||||
@ -174,16 +176,17 @@ public class LiveUtils {
|
|||||||
,UUID.randomUUID().toString()
|
,UUID.randomUUID().toString()
|
||||||
,AppTools.randomCommon(0,9,1)[0]);
|
,AppTools.randomCommon(0,9,1)[0]);
|
||||||
}*/
|
}*/
|
||||||
private static long oldBiliBiliHttpTime=0;
|
private static long oldBiliBiliHttpTime = 0;
|
||||||
|
|
||||||
public static JSONObject http_get(String url) {
|
public static JSONObject http_get(String url) {
|
||||||
try {
|
try {
|
||||||
if(System.currentTimeMillis()-oldBiliBiliHttpTime<1000){
|
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
oldBiliBiliHttpTime=System.currentTimeMillis();
|
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
HttpURLConnection connection = getBiliHttpGet(url, getCookie());
|
HttpURLConnection connection = getBiliHttpGet(url, getCookie());
|
||||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||||
@ -210,21 +213,22 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//e.printStackTrace();
|
//com.yutou.bilibili.Tools.Log.e(e);
|
||||||
Log.i("412 in "+url);
|
Log.e(e);
|
||||||
|
Log.i("412 in " + url);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject http_post(String url, String body) {
|
public static JSONObject http_post(String url, String body) {
|
||||||
try {
|
try {
|
||||||
if(System.currentTimeMillis()-oldBiliBiliHttpTime<1000){
|
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
oldBiliBiliHttpTime=System.currentTimeMillis();
|
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
HttpURLConnection connection = getBiliHttpPost(url, getCookie());
|
HttpURLConnection connection = getBiliHttpPost(url, getCookie());
|
||||||
OutputStream connectionOutputStream = null;
|
OutputStream connectionOutputStream = null;
|
||||||
@ -260,19 +264,19 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpURLConnection getBiliHttpPost(String url, String cookie) throws Exception {
|
public static HttpURLConnection getBiliHttpPost(String url, String cookie) throws Exception {
|
||||||
if(System.currentTimeMillis()-oldBiliBiliHttpTime<1000){
|
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
oldBiliBiliHttpTime=System.currentTimeMillis();
|
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
@ -290,13 +294,13 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static HttpURLConnection getBiliHttpGet(String url, String cookie) throws IOException {
|
public static HttpURLConnection getBiliHttpGet(String url, String cookie) throws IOException {
|
||||||
if(System.currentTimeMillis()-oldBiliBiliHttpTime<1000){
|
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
oldBiliBiliHttpTime=System.currentTimeMillis();
|
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
@ -340,34 +344,46 @@ public class LiveUtils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public static JSONObject getLiveInfo(int roomId){
|
|
||||||
|
private 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
public static String getLiveTitle(int roomId){
|
|
||||||
JSONObject json=getLiveInfo(roomId);
|
public static String getLiveTitle(int roomId) {
|
||||||
if(json!=null){
|
JSONObject json = LiveInfoManager.getInstance().getInfo(roomId);
|
||||||
|
if (json != null) {
|
||||||
return json.getJSONObject("data").getJSONObject("room_info").getString("title");
|
return json.getJSONObject("data").getJSONObject("room_info").getString("title");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLivePlayer(int roomId) {
|
public static boolean isLivePlayer(int roomId) {
|
||||||
JSONObject json =getLiveInfo(roomId);
|
JSONObject json = LiveInfoManager.getInstance().getInfo(roomId);
|
||||||
if (json == null)
|
if (json == null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
BilibiliUpInfo upData = new BilibiliUpInfo();
|
BilibiliUpInfo upData = new BilibiliUpInfo();
|
||||||
upData.setRoomid(roomId);
|
upData.setRoomid(roomId);
|
||||||
checkLiveSave(roomId);
|
//Log.i("直播检测:" + roomId + " > " + (json.getJSONObject("data").getJSONObject("room_info").getInteger("live_status") == 1) + " 录播器:" + liveContains(upData));
|
||||||
Log.i("直播检测:" + roomId + " > " + (json.getJSONObject("data").getJSONObject("room_info").getInteger("live_status") == 1) + " 录播器:" + liveContains(upData));
|
|
||||||
return json.getJSONObject("data").getJSONObject("room_info").getInteger("live_status") == 1;
|
return json.getJSONObject("data").getJSONObject("room_info").getInteger("live_status") == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkLiveSave(int roomId) {
|
private static void checkLiveSave(int roomId) {
|
||||||
BilibiliUpInfo upData = new BilibiliUpInfo();
|
BilibiliUpInfo upData = new BilibiliUpInfo();
|
||||||
upData.setRoomid(roomId);
|
upData.setRoomid(roomId);
|
||||||
Live live=liveContains(upData);
|
Live live = liveContains(upData);
|
||||||
if(live!=null){
|
if (live == null) {
|
||||||
live.checkLive();
|
live = new Live();
|
||||||
|
live.add(roomId, !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
||||||
|
try {
|
||||||
|
live.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!SaveLive.getInstance().checkLive(roomId)) {
|
||||||
|
SaveLive.getInstance().addLive(roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -408,5 +424,45 @@ public class LiveUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LiveInfoManager {
|
||||||
|
private static LiveInfoManager manager;
|
||||||
|
private Map<Integer, JSONObject> infoMap;
|
||||||
|
|
||||||
|
public static LiveInfoManager getInstance() {
|
||||||
|
if (manager == null) {
|
||||||
|
manager = new LiveInfoManager();
|
||||||
|
}
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LiveInfoManager() {
|
||||||
|
infoMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void check(List<BilibiliUpInfo> list) {
|
||||||
|
for (BilibiliUpInfo upInfo : list) {
|
||||||
|
JSONObject json = getLiveInfo(upInfo.getRoomid());
|
||||||
|
if (json != null) {
|
||||||
|
infoMap.put(upInfo.getRoomid(), json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void check(int roomId) {
|
||||||
|
JSONObject json = getLiveInfo(roomId);
|
||||||
|
if (json != null) {
|
||||||
|
Log.i("登记直播:"+roomId);
|
||||||
|
infoMap.put(roomId, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized JSONObject getInfo(int roomId) {
|
||||||
|
if (!infoMap.containsKey(roomId)) {
|
||||||
|
//check(roomId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return infoMap.get(roomId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,12 @@ public class SaveLive {
|
|||||||
public void addLive(Live live) {
|
public void addLive(Live live) {
|
||||||
addLive(live.geData().getRoomid());
|
addLive(live.geData().getRoomid());
|
||||||
}
|
}
|
||||||
public void startLive(int roomId){
|
|
||||||
saveList.add(roomId + "");
|
public void startLive(int roomId) {
|
||||||
start(roomId);
|
start(roomId);
|
||||||
QQBotManager.getInstance().sendMessage(roomId+" 已启动录制");
|
saveList.add(roomId + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLive(int roomId) {
|
public void addLive(int roomId) {
|
||||||
if (saveList.contains(roomId + "")) {
|
if (saveList.contains(roomId + "")) {
|
||||||
return;
|
return;
|
||||||
@ -48,15 +49,15 @@ public class SaveLive {
|
|||||||
if (!LiveUtils.isLivePlayer(roomId)) {
|
if (!LiveUtils.isLivePlayer(roomId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveList.add(roomId + "");
|
|
||||||
start(roomId);
|
start(roomId);
|
||||||
QQBotManager.getInstance().sendMessage(roomId+" 已启动录制");
|
saveList.add(roomId + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkLive(int roomId) {
|
public boolean checkLive(int roomId) {
|
||||||
return saveList.contains(roomId + "");
|
return saveList.contains(roomId + "");
|
||||||
}
|
}
|
||||||
public File getLiveFile(int roomId){
|
|
||||||
|
public File getLiveFile(int roomId) {
|
||||||
return downloads.get(roomId).liveFile;
|
return downloads.get(roomId).liveFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +76,14 @@ public class SaveLive {
|
|||||||
heartbeats.get(roomId).cancel();
|
heartbeats.get(roomId).cancel();
|
||||||
heartbeats.remove(roomId);
|
heartbeats.remove(roomId);
|
||||||
}
|
}
|
||||||
|
LiveUtils.LiveInfoManager.getInstance().check(roomId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void start(int roomId) {
|
private void start(int roomId) {
|
||||||
|
if (checkLive(roomId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
timer = System.currentTimeMillis();
|
timer = System.currentTimeMillis();
|
||||||
DownloadThread thread = new DownloadThread(roomId);
|
DownloadThread thread = new DownloadThread(roomId);
|
||||||
downloads.put(roomId, thread);
|
downloads.put(roomId, thread);
|
||||||
@ -118,6 +123,7 @@ public class SaveLive {
|
|||||||
String url = getLiveUrl(roomId);
|
String url = getLiveUrl(roomId);
|
||||||
try {
|
try {
|
||||||
com.yutou.bilibili.Tools.Log.i("开始录制:" + roomId);
|
com.yutou.bilibili.Tools.Log.i("开始录制:" + roomId);
|
||||||
|
QQBotManager.getInstance().sendMessage(roomId + " 已启动录制");
|
||||||
HttpURLConnection connection = LiveUtils.getBiliHttpGet(url, LiveUtils.getCookie());
|
HttpURLConnection connection = LiveUtils.getBiliHttpGet(url, LiveUtils.getCookie());
|
||||||
heartbeat = new Timer();
|
heartbeat = new Timer();
|
||||||
//Heartbeat beat = new Heartbeat();
|
//Heartbeat beat = new Heartbeat();
|
||||||
@ -146,7 +152,7 @@ public class SaveLive {
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
com.yutou.bilibili.Tools.Log.i("录制完成:" + roomId + " save = " + isSave + " len = " + len);
|
com.yutou.bilibili.Tools.Log.i("录制完成:" + roomId + " save = " + isSave + " len = " + len);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
SaveLive.this.stop(roomId);
|
SaveLive.this.stop(roomId);
|
||||||
|
|
||||||
@ -173,7 +179,7 @@ public class SaveLive {
|
|||||||
hearBeat = LiveUtils.http_post("https://api.live.bilibili.com/User/userOnlineHeart", HttpTools.toUrlParams(userHear));
|
hearBeat = LiveUtils.http_post("https://api.live.bilibili.com/User/userOnlineHeart", HttpTools.toUrlParams(userHear));
|
||||||
com.yutou.bilibili.Tools.Log.i("[" + AppTools.getToDayNowTimeToString() + "]" + hearBeat);
|
com.yutou.bilibili.Tools.Log.i("[" + AppTools.getToDayNowTimeToString() + "]" + hearBeat);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ public class BilibiliApplication {
|
|||||||
public static String version="0.6";
|
public static String version="0.6";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(BilibiliApplication.class, args);
|
|
||||||
QQBotManager.getInstance().init();
|
QQBotManager.getInstance().init();
|
||||||
|
SpringApplication.run(BilibiliApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.yutou.bilibili.Controllers;
|
package com.yutou.bilibili.Controllers;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.yutou.bilibili.QQBot.QQBotManager;
|
||||||
import com.yutou.bilibili.Services.ISystemConfigService;
|
import com.yutou.bilibili.Services.ISystemConfigService;
|
||||||
import com.yutou.bilibili.Tools.Config;
|
import com.yutou.bilibili.Tools.Config;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -84,4 +85,13 @@ public class SystemConfigController {
|
|||||||
json.put("data",data);
|
json.put("data",data);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/system/qq/login.do")
|
||||||
|
public JSONObject loginQQ(){
|
||||||
|
QQBotManager.getInstance().init();
|
||||||
|
JSONObject json=new JSONObject();
|
||||||
|
json.put("code",0);
|
||||||
|
json.put("msg","ok");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,7 @@ import com.yutou.bilibili.BiliBili.Live;
|
|||||||
import com.yutou.bilibili.BiliBili.LiveUtils;
|
import com.yutou.bilibili.BiliBili.LiveUtils;
|
||||||
import com.yutou.bilibili.BiliBili.Tools.SaveLive;
|
import com.yutou.bilibili.BiliBili.Tools.SaveLive;
|
||||||
import com.yutou.bilibili.BilibiliApplication;
|
import com.yutou.bilibili.BilibiliApplication;
|
||||||
import com.yutou.bilibili.Tools.AppTools;
|
import com.yutou.bilibili.Tools.*;
|
||||||
import com.yutou.bilibili.Tools.HttpTools;
|
|
||||||
import com.yutou.bilibili.Tools.Log;
|
|
||||||
import com.yutou.bilibili.Tools.Tools;
|
|
||||||
import com.yutou.bilibili.interfaces.DownloadInterface;
|
import com.yutou.bilibili.interfaces.DownloadInterface;
|
||||||
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
|
||||||
import net.mamoe.mirai.Bot;
|
import net.mamoe.mirai.Bot;
|
||||||
@ -54,7 +51,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
private final static String QQ_HELP = "!help";
|
private final static String QQ_HELP = "!help";
|
||||||
private final static String QQ_GET_IP = "!ip";
|
private final static String QQ_GET_IP = "!ip";
|
||||||
private final static String QQ_GET_VERSION = "!version";
|
private final static String QQ_GET_VERSION = "!version";
|
||||||
private final static String QQ_LIVE_LIST = "!直播列表";
|
private final static String QQ_LIVE_LIST = "!列表";
|
||||||
private final static String QQ_LIVE_SAVE = "!录播列表";
|
private final static String QQ_LIVE_SAVE = "!录播列表";
|
||||||
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 = "!数据";
|
||||||
@ -63,31 +60,32 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
|
|
||||||
private static QQBotManager botManager = null;
|
private static QQBotManager botManager = null;
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
private static final long qqGroup = 891655174L;
|
private static long qqGroup ;
|
||||||
private boolean isLogin = false;
|
private boolean isLogin = false;
|
||||||
private static boolean isInit = false;
|
private static boolean isInit = false;
|
||||||
private static final boolean debug = true;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
RealTimeDataController realTimeDataController;
|
RealTimeDataController realTimeDataController;
|
||||||
|
|
||||||
|
|
||||||
private QQBotManager() {
|
private QQBotManager() {
|
||||||
|
qqGroup = Long.parseLong((String) ConfigTools.load(ConfigTools.CONFIG, "qq_group"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
if(!((boolean) ConfigTools.load(ConfigTools.CONFIG,"qq_bot"))){
|
||||||
|
return;
|
||||||
|
}
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long qq = 3620756944L;
|
long qq = Long.parseLong((String) ConfigTools.load(ConfigTools.CONFIG, "qq_number"));
|
||||||
String password = "UAs6YBYMyxJU";
|
String password = (String) ConfigTools.load(ConfigTools.CONFIG, "qq_password");
|
||||||
System.out.println("调用机器人");
|
|
||||||
bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() {
|
bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() {
|
||||||
{
|
{
|
||||||
setProtocol(MiraiProtocol.ANDROID_PAD);
|
setProtocol(MiraiProtocol.ANDROID_PAD);
|
||||||
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
||||||
if (debug) {
|
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "qq_debug"))) {
|
||||||
noBotLog();
|
noBotLog();
|
||||||
noNetworkLog();
|
noNetworkLog();
|
||||||
}
|
}
|
||||||
@ -95,9 +93,9 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
});
|
});
|
||||||
//Events.registerEvents(bot, new MessageListener());
|
//Events.registerEvents(bot, new MessageListener());
|
||||||
GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
|
GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
|
||||||
System.out.println("准备登陆");
|
Log.i("准备登陆");
|
||||||
bot.login();
|
bot.login();
|
||||||
System.out.println("登陆成功");
|
Log.i("登陆成功");
|
||||||
isLogin = true;
|
isLogin = true;
|
||||||
isInit = true;
|
isInit = true;
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@ -106,7 +104,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
String str = sendMessage("姬妻酱上线拉~");
|
String str = sendMessage("姬妻酱上线拉~");
|
||||||
Log.i(str);
|
Log.i(str);
|
||||||
@ -148,7 +146,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
try {
|
try {
|
||||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
@ -159,7 +157,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
try {
|
try {
|
||||||
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
|
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
@ -184,7 +182,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(builder.asMessageChain()).toString();
|
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(builder.asMessageChain()).toString();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
@ -225,10 +223,8 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
@Override
|
@Override
|
||||||
public void accept(GroupMessageEvent event) {
|
public void accept(GroupMessageEvent event) {
|
||||||
String msg = event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
switch (event.getGroup().getId() + "") {
|
if (qqGroup == event.getGroup().getId()) {
|
||||||
case qqGroup + "":
|
|
||||||
myGroup(msg);
|
myGroup(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +247,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
builder.append("当前正在记录数据的直播间:");
|
builder.append("当前正在记录数据的直播间:");
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
for (Live live : Live.lives) {
|
for (Live live : Live.lives) {
|
||||||
JSONObject liveJson = LiveUtils.getLiveInfo(live.getInfo().getRoomid());
|
JSONObject liveJson = LiveUtils.LiveInfoManager.getInstance().getInfo(live.getInfo().getRoomid());
|
||||||
builder
|
builder
|
||||||
.append("名字:").append(live.geData().getName()).append(" ")
|
.append("名字:").append(live.geData().getName()).append(" ")
|
||||||
.append(" roomId:").append(live.geData().getRoomid()).append(" ");
|
.append(" roomId:").append(live.geData().getRoomid()).append(" ");
|
||||||
@ -271,7 +267,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
data.setRoomid(Integer.parseInt(roomId));
|
data.setRoomid(Integer.parseInt(roomId));
|
||||||
Live live = LiveUtils.liveContains(data);
|
Live live = LiveUtils.liveContains(data);
|
||||||
if (live != null) {
|
if (live != null) {
|
||||||
File file = SaveLive.getInstance().getLiveFile(_roomId);
|
File file = SaveLive.getInstance().getLiveFile(Integer.parseInt(roomId));
|
||||||
builder
|
builder
|
||||||
.append("名字:").append(live.geData().getName()).append(" ")
|
.append("名字:").append(live.geData().getName()).append(" ")
|
||||||
.append("文件大小(字节):").append(file.length()).append(" ")
|
.append("文件大小(字节):").append(file.length()).append(" ")
|
||||||
@ -287,13 +283,13 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
builder.append(field.get(null)).append("\n");
|
builder.append(field.get(null)).append("\n");
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getInstance().sendMessage(builder.toString());
|
getInstance().sendMessage(builder.toString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(msg.startsWith(QQCommands.QQ_LIVE_TO_DAY_DATE)){
|
if (msg.startsWith(QQCommands.QQ_LIVE_TO_DAY_DATE)) {
|
||||||
try {
|
try {
|
||||||
cmd = msg.split(" ");
|
cmd = msg.split(" ");
|
||||||
_roomId = Integer.parseInt(cmd[1]);
|
_roomId = Integer.parseInt(cmd[1]);
|
||||||
@ -302,7 +298,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getInstance().sendMessage("参数错误。\n使用方式: " + QQCommands.QQ_LIVE_TO_DAY_DATE + "+空格+roomId");
|
getInstance().sendMessage("参数错误。\n使用方式: " + QQCommands.QQ_LIVE_TO_DAY_DATE + "+空格+roomId");
|
||||||
}
|
}
|
||||||
}else if(msg.startsWith(QQCommands.QQ_LIVE_DATE)){
|
} else if (msg.startsWith(QQCommands.QQ_LIVE_DATE)) {
|
||||||
try {
|
try {
|
||||||
cmd = msg.split(" ");
|
cmd = msg.split(" ");
|
||||||
_roomId = Integer.parseInt(cmd[1]);
|
_roomId = Integer.parseInt(cmd[1]);
|
||||||
@ -316,7 +312,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
"\n时间格式:年-月-日_时:分:秒 例:2021-4-1_12:00:00" +
|
"\n时间格式:年-月-日_时:分:秒 例:2021-4-1_12:00:00" +
|
||||||
"\n时分秒不可省略");
|
"\n时分秒不可省略");
|
||||||
}
|
}
|
||||||
}else if(msg.startsWith(QQCommands.QQ_LIVE_USE_SAVE)){
|
} else if (msg.startsWith(QQCommands.QQ_LIVE_USE_SAVE)) {
|
||||||
try {
|
try {
|
||||||
cmd = msg.split(" ");
|
cmd = msg.split(" ");
|
||||||
_roomId = Integer.parseInt(cmd[1]);
|
_roomId = Integer.parseInt(cmd[1]);
|
||||||
@ -332,7 +328,7 @@ public class QQBotManager implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendGiftData(int roomId, Date startTime, Date endTime) throws ParseException {
|
public void sendGiftData(int roomId, Date startTime, Date endTime) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
if (startTime == null) {
|
if (startTime == null) {
|
||||||
startTime = AppTools.getToDayStartTime();
|
startTime = AppTools.getToDayStartTime();
|
||||||
|
@ -55,7 +55,7 @@ public class APIFilter implements Filter {
|
|||||||
try {
|
try {
|
||||||
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
|
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
com.yutou.bilibili.Tools.Log.i("无权限请求:"+tmp);
|
com.yutou.bilibili.Tools.Log.i("无权限请求:"+tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class AppTools {
|
|||||||
writer.close();
|
writer.close();
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ public class AppTools {
|
|||||||
digest.update(data.getBytes());
|
digest.update(data.getBytes());
|
||||||
return DatatypeConverter.printHexBinary(digest.digest());
|
return DatatypeConverter.printHexBinary(digest.digest());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -297,10 +297,10 @@ public class AppTools {
|
|||||||
in.close();
|
in.close();
|
||||||
return true;
|
return true;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
live.add(data.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
live.add(data.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
||||||
live.start();
|
live.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +96,7 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
saveData(time);
|
saveData(time);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
LiveUtils.LiveInfoManager.getInstance().check(service.getUpInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkLive() {
|
private void checkLive() {
|
||||||
@ -110,7 +111,7 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
live.start();
|
live.start();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
86
src/main/java/com/yutou/bilibili/Tools/ConfigTools.java
Normal file
86
src/main/java/com/yutou/bilibili/Tools/ConfigTools.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package com.yutou.bilibili.Tools;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置和参数
|
||||||
|
*/
|
||||||
|
public class ConfigTools {
|
||||||
|
public static final String CONFIG="config.json";
|
||||||
|
public static final String DATA="data.json";
|
||||||
|
public static final String SQLITE="sqlite.json";
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
File file=new File(CONFIG);
|
||||||
|
if(!file.exists()){
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
file=new File(DATA);
|
||||||
|
if(!file.exists()){
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
file=null;
|
||||||
|
}catch (Exception e){
|
||||||
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public static Object load(String type,String key){
|
||||||
|
File file=new File(type);
|
||||||
|
//com.yutou.nas.utils.Log.i(type+"配置文件地址:"+file.getAbsolutePath());
|
||||||
|
String src=readFile(file);
|
||||||
|
if(src!=null){
|
||||||
|
try {
|
||||||
|
JSONObject json=JSONObject.parseObject(src);
|
||||||
|
if(json==null){
|
||||||
|
json=new JSONObject();
|
||||||
|
saveFile(file,json.toJSONString());
|
||||||
|
}
|
||||||
|
return json.getOrDefault(key, "");
|
||||||
|
}catch (Exception e){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
public static boolean save(String type,String key,Object data){
|
||||||
|
File file=new File(type);
|
||||||
|
String src=readFile(file);
|
||||||
|
if(src==null){
|
||||||
|
src="{}";
|
||||||
|
}
|
||||||
|
JSONObject json=JSONObject.parseObject(src);
|
||||||
|
json.put(key,data);
|
||||||
|
saveFile(file,json.toJSONString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean saveFile(File file,String data){
|
||||||
|
try {
|
||||||
|
FileWriter writer=new FileWriter(file);
|
||||||
|
writer.write(data);
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String readFile(File file){
|
||||||
|
try {
|
||||||
|
BufferedReader reader=new BufferedReader(new FileReader(file));
|
||||||
|
String tmp;
|
||||||
|
StringBuilder str= new StringBuilder();
|
||||||
|
while ((tmp=reader.readLine())!=null){
|
||||||
|
str.append(tmp);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return str.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -117,7 +117,7 @@ public class ExcelUtils implements ApplicationContextAware {
|
|||||||
file.renameTo(new File("excel"+File.separator+fileName));
|
file.renameTo(new File("excel"+File.separator+fileName));
|
||||||
return file;
|
return file;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -54,7 +54,7 @@ public class FFmpegUtils {
|
|||||||
file.delete();
|
file.delete();
|
||||||
new File(out.getAbsolutePath()+File.separator+file.getName()).delete();
|
new File(out.getAbsolutePath()+File.separator+file.getName()).delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
nowFFmpegList.remove(file);
|
nowFFmpegList.remove(file);
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ public class FFmpegUtils {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(300);
|
Thread.sleep(300);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
com.yutou.bilibili.Tools.Log.i("转码完成");
|
com.yutou.bilibili.Tools.Log.i("转码完成");
|
||||||
|
@ -28,7 +28,7 @@ public class HttpTools {
|
|||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
return str.toString();
|
return str.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ public class HttpTools {
|
|||||||
try {
|
try {
|
||||||
networkInterface.httpGetData(str.toString(), connection.getResponseCode());
|
networkInterface.httpGetData(str.toString(), connection.getResponseCode());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
networkInterface.onCookie(connection.getHeaderField("Set-Cookie"));
|
networkInterface.onCookie(connection.getHeaderField("Set-Cookie"));
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class HttpTools {
|
|||||||
try {
|
try {
|
||||||
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), "UTF-8"));
|
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), "UTF-8"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
try {
|
try {
|
||||||
string.append("&").append(URLEncoder.encode(key, "UTF-8")).append("=");
|
string.append("&").append(URLEncoder.encode(key, "UTF-8")).append("=");
|
||||||
// string += "&" + key + "=";
|
// string += "&" + key + "=";
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.yutou.bilibili.Tools;
|
package com.yutou.bilibili.Tools;
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
public static void i(Object log){
|
public static void i(Object log) {
|
||||||
if(true)
|
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logout")))
|
||||||
return;
|
return;
|
||||||
System.out.printf("[%s]%s%n",
|
System.out.printf("[%s]%s%n",
|
||||||
AppTools.getToDayNowTimeToString(),
|
AppTools.getToDayNowTimeToString(),
|
||||||
@ -10,9 +10,10 @@ public class Log {
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void e(Exception e){
|
|
||||||
if(true)
|
public static void e(Exception e) {
|
||||||
|
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logout")))
|
||||||
return;
|
return;
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class ServiceTools implements ApplicationContextAware {
|
|||||||
try {
|
try {
|
||||||
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
|
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
com.yutou.bilibili.Tools.Log.i("无权限请求:" + tmp);
|
com.yutou.bilibili.Tools.Log.i("无权限请求:" + tmp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class TestMain {
|
|||||||
|
|
||||||
com.yutou.bilibili.Tools.Log.i("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat);
|
com.yutou.bilibili.Tools.Log.i("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int byteArrayToInt(byte[] bytes) {
|
public static int byteArrayToInt(byte[] bytes) {
|
||||||
|
@ -111,7 +111,7 @@ public class Tools {
|
|||||||
inputStream.close();
|
inputStream.close();
|
||||||
downloadInterface.onDownload(file);
|
downloadInterface.onDownload(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
downloadInterface.onError(e);
|
downloadInterface.onError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ public class Tools {
|
|||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return bytesToHexString(digest.digest());
|
return bytesToHexString(digest.digest());
|
||||||
|
@ -51,7 +51,7 @@ public class BiliBiliLiveDatabasesManager extends SQLiteManager {
|
|||||||
statement.execute(sql);
|
statement.execute(sql);
|
||||||
statement.closeOnCompletion();
|
statement.closeOnCompletion();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class BiliBiliLiveDatabasesManager extends SQLiteManager {
|
|||||||
set.close();
|
set.close();
|
||||||
statement.closeOnCompletion();;
|
statement.closeOnCompletion();;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class SQLiteManager {
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class SQLiteManager {
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void close(){
|
public void close(){
|
||||||
@ -42,7 +42,7 @@ public class SQLiteManager {
|
|||||||
try {
|
try {
|
||||||
conn.commit();
|
conn.commit();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class SQLiteManager {
|
|||||||
sql.delete();
|
sql.delete();
|
||||||
conn = DriverManager.getConnection(url + sql.getAbsolutePath());
|
conn = DriverManager.getConnection(url + sql.getAbsolutePath());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
startBatch();
|
startBatch();
|
||||||
JSONArray array=json.getJSONArray("table");
|
JSONArray array=json.getJSONArray("table");
|
||||||
@ -102,7 +102,7 @@ public class SQLiteManager {
|
|||||||
statement.execute(sql.toString().replace(",);", ");"));
|
statement.execute(sql.toString().replace(",);", ");"));
|
||||||
statement.closeOnCompletion();
|
statement.closeOnCompletion();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ public class SQLiteManager {
|
|||||||
conn = DriverManager.getConnection(url + sql.getAbsolutePath());
|
conn = DriverManager.getConnection(url + sql.getAbsolutePath());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ public class SQLiteManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
com.yutou.bilibili.Tools.Log.e(e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@
|
|||||||
;
|
;
|
||||||
</select>
|
</select>
|
||||||
<select id="queryPriceTimeGroup" resultType="map">
|
<select id="queryPriceTimeGroup" resultType="map">
|
||||||
select sum(price)as price,group_concat(distinct DATE_FORMAT(subtime,'%d/%H')) as `time` from DDOB_db.bilibili_live_data
|
select sum(price)as price,group_concat(distinct DATE_FORMAT(subtime,'%d/%H')) as `time` from `bilibili_live_data`
|
||||||
<where>
|
<where>
|
||||||
<if test="roomid!=-1">
|
<if test="roomid!=-1">
|
||||||
roomid=#{roomid,jdbcType=INTEGER}
|
roomid=#{roomid,jdbcType=INTEGER}
|
||||||
@ -370,7 +370,7 @@
|
|||||||
group by subtime-subtime%(2.8*60*60);
|
group by subtime-subtime%(2.8*60*60);
|
||||||
</select>
|
</select>
|
||||||
<select id="queryGiftTimeGroup" resultType="map">
|
<select id="queryGiftTimeGroup" resultType="map">
|
||||||
select sum(giftIndex) as price,group_concat(distinct giftName) as giftName ,group_concat(distinct DATE_FORMAT(subtime,'%d/%H')) as `time` from DDOB_db.bilibili_live_data
|
select sum(giftIndex) as price,group_concat(distinct giftName) as giftName ,group_concat(distinct DATE_FORMAT(subtime,'%d/%H')) as `time` from `bilibili_live_data`
|
||||||
<where>
|
<where>
|
||||||
<if test="roomid!=-1">
|
<if test="roomid!=-1">
|
||||||
roomid=#{roomid,jdbcType=INTEGER}
|
roomid=#{roomid,jdbcType=INTEGER}
|
||||||
|
Loading…
Reference in New Issue
Block a user