From 44272a609f903052108eae61f94ebf5a7bc11e96 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 1 Apr 2021 21:11:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=B1=BB=20=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E4=B8=8D=E7=BB=BF=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mvn/wrapper/MavenWrapperDownloader.java | 16 ++-- Web/html/_old_header.html | 81 ------------------- Web/html/body/bilibili/upInfo.html | 1 + .../Controllers/BiliVideoController.java | 2 +- .../Controllers/OverviewController.java | 4 +- .../Controllers/UpInfoController.java | 14 ++-- .../com/yutou/bilibili/BiliBili/Live.java | 47 ++++++----- .../yutou/bilibili/BiliBili/LiveUtils.java | 22 +++-- .../impl/BiliBiliLiveServiceImpl.java | 2 +- .../bilibili/BiliBili/Tools/BiliTools.java | 6 +- .../yutou/bilibili/BiliBili/Tools/LiveT.java | 4 +- .../bilibili/BiliBili/Tools/SaveLive.java | 14 ++-- .../com/yutou/bilibili/Tools/APIFilter.java | 2 +- .../com/yutou/bilibili/Tools/AppTools.java | 4 +- .../com/yutou/bilibili/Tools/ExcelUtils.java | 12 +-- .../com/yutou/bilibili/Tools/FFmpegUtils.java | 6 +- .../com/yutou/bilibili/Tools/HttpTools.java | 4 +- .../java/com/yutou/bilibili/Tools/Log.java | 11 +++ .../yutou/bilibili/Tools/ServiceTools.java | 2 +- .../com/yutou/bilibili/Tools/TestMain.java | 2 +- .../sqlite/BiliBiliLiveDatabasesManager.java | 4 +- .../yutou/bilibili/sqlite/SQLiteManager.java | 2 +- 22 files changed, 102 insertions(+), 160 deletions(-) delete mode 100644 Web/html/_old_header.html create mode 100644 src/main/java/com/yutou/bilibili/Tools/Log.java diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java index a45eb6b..e8786e7 100644 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -47,9 +47,9 @@ public class MavenWrapperDownloader { private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; public static void main(String args[]) { - System.out.println("- Downloader started"); + com.yutou.bilibili.Tools.Log.i("- Downloader started"); File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + com.yutou.bilibili.Tools.Log.i("- Using base directory: " + baseDirectory.getAbsolutePath()); // If the maven-wrapper.properties exists, read it and check if it contains a custom // wrapperUrl parameter. @@ -63,7 +63,7 @@ public class MavenWrapperDownloader { mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + com.yutou.bilibili.Tools.Log.i("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); } finally { try { if (mavenWrapperPropertyFileInputStream != null) { @@ -74,22 +74,22 @@ public class MavenWrapperDownloader { } } } - System.out.println("- Downloading from: " + url); + com.yutou.bilibili.Tools.Log.i("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); if (!outputFile.getParentFile().exists()) { if (!outputFile.getParentFile().mkdirs()) { - System.out.println( + com.yutou.bilibili.Tools.Log.i( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + com.yutou.bilibili.Tools.Log.i("- Downloading to: " + outputFile.getAbsolutePath()); try { downloadFileFromURL(url, outputFile); - System.out.println("Done"); + com.yutou.bilibili.Tools.Log.i("Done"); System.exit(0); } catch (Throwable e) { - System.out.println("- Error downloading"); + com.yutou.bilibili.Tools.Log.i("- Error downloading"); e.printStackTrace(); System.exit(1); } diff --git a/Web/html/_old_header.html b/Web/html/_old_header.html deleted file mode 100644 index 0681419..0000000 --- a/Web/html/_old_header.html +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - DD监视器 - - - -
- -
- - - - - \ No newline at end of file diff --git a/Web/html/body/bilibili/upInfo.html b/Web/html/body/bilibili/upInfo.html index b27c25a..3613aa4 100644 --- a/Web/html/body/bilibili/upInfo.html +++ b/Web/html/body/bilibili/upInfo.html @@ -202,6 +202,7 @@ } for (let i in json.data.live) { $('#' + json.data.live[i].roomid).css('color', '#8FE18F') + console.log('绿了:'+json.data.live[i].roomid) } $.post('/user/get/test.do',function (json) { diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/BiliVideoController.java b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/BiliVideoController.java index ea99b62..b916546 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/BiliVideoController.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/BiliVideoController.java @@ -110,7 +110,7 @@ public class BiliVideoController { File file = new File("ffmpeg_out" + File.separator + time + File.separator + fileName); if (!file.exists()) file = new File("live" + File.separator + time + File.separator + fileName); - System.out.println(file.getAbsolutePath()); + com.yutou.bilibili.Tools.Log.i(file.getAbsolutePath()); return AppTools.getFile(file); } @ResponseBody diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/OverviewController.java b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/OverviewController.java index 0451fd4..39dc890 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/OverviewController.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/OverviewController.java @@ -40,7 +40,7 @@ public class OverviewController { , LiveData.GUARD_BUY})); data.put("price", manager.queryPriceSize(upData.getRoomid(), startTime, endTime)); long h = (endTime.getTime() - startTime.getTime()) % (1000 * 24 * 60 * 60) / (1000 * 60 * 60); - System.out.println("相差:" + h + "小时"); + com.yutou.bilibili.Tools.Log.i("相差:" + h + "小时"); try { data.put("hprice", data.getInteger("price") / h); } catch (Exception e) { @@ -52,7 +52,7 @@ public class OverviewController { List infos=manager.queryLiveInfo(upData,startTime,endTime); int maxUser=0; for (BilibiliLiveInfo info : infos) { - System.out.println(info); + com.yutou.bilibili.Tools.Log.i(info); maxUser+=info.getUserindex()+info.getVipuserindex(); JSONObject item=new JSONObject(); String nowTime = new SimpleDateFormat("HH").format(info.getSubtime()); diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/UpInfoController.java b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/UpInfoController.java index 6134443..b76e345 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Controllers/UpInfoController.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Controllers/UpInfoController.java @@ -10,6 +10,7 @@ import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService; import com.yutou.bilibili.BiliBili.Tools.BiliTools; import com.yutou.bilibili.Services.IUserService; import com.yutou.bilibili.Tools.AppTools; +import com.yutou.bilibili.Tools.Log; import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo; import com.yutou.bilibili.mybatis.model.UUser; import org.springframework.stereotype.Controller; @@ -41,7 +42,7 @@ public class UpInfoController { return json; } List upDataList =service.getUpInfo(user.getId(),user.getPower()); - System.out.println("UP用户数:" + upDataList.size()); + com.yutou.bilibili.Tools.Log.i("UP用户数:" + upDataList.size()); json.put("code", 0); json.put("data", JSONArray.toJSON(upDataList)); return json; @@ -54,7 +55,7 @@ public class UpInfoController { if (BiliTools.checkout(upData) != null) { upData.setEnable(0); upData = BiliTools.checkout(upData); - System.out.println(upData); + com.yutou.bilibili.Tools.Log.i(upData); boolean flag = service.addUpInfo(upData); if (flag) { json.put("code", 0); @@ -74,7 +75,7 @@ public class UpInfoController { @RequestMapping("/upinfo/set/update.do") public JSONObject update(BilibiliUpInfo upData) { JSONObject json = new JSONObject(); - System.out.println("old data ="+upData); + com.yutou.bilibili.Tools.Log.i("old data ="+upData); BilibiliUpInfo old = service.queryUp(upData); if (!old.getUrl().equals(upData.getUrl())) { upData = BiliTools.checkout(upData); @@ -84,7 +85,7 @@ public class UpInfoController { upData.setOfflinelistening(0); } } - System.out.println("save data = "+upData); + com.yutou.bilibili.Tools.Log.i("save data = "+upData); boolean flag = service.updateUpInfo(upData); if (flag) { LiveController.getInstance().updateUpInfo(upData); @@ -101,7 +102,7 @@ public class UpInfoController { @RequestMapping("/upinfo/set/delete.do") public JSONObject delete(BilibiliUpInfo upData) { JSONObject json = new JSONObject(); - System.out.println(upData); + com.yutou.bilibili.Tools.Log.i(upData); boolean flag = service.deleteUp(upData); if (flag) { json.put("code", 0); @@ -124,7 +125,6 @@ public class UpInfoController { @RequestMapping("/upinfo/get/liveInfo.do") public JSONObject liveInfo() { List list = service.getUpInfo(); - List lives=Live.lives; JSONObject json = new JSONObject(); JSONObject data = new JSONObject(); JSONArray info = new JSONArray(); @@ -141,7 +141,7 @@ public class UpInfoController { info.add(JSON.toJSON(up)); } } - for (Live live : lives) { + for (Live live : Live.lives) { if(live.geData().getLive()==1){ liveArray.add(JSON.toJSON(live.geData())); } diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index 2718dba..11eb790 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -78,12 +78,13 @@ public class Live implements ApplicationContextAware { info.setUserindex(0); Live.lives.add(this); updateUpInfo(); - System.out.println("roomId = " + roomId + ", isLogin = " + isLogin); + com.yutou.bilibili.Tools.Log.i("roomId = " + roomId + ", isLogin = " + isLogin); } private void updateUpInfo() { try { upData = service.queryUp(upData); + upData.setLive(1); } catch (Exception e) { e.printStackTrace(); } @@ -102,6 +103,10 @@ public class Live implements ApplicationContextAware { upData.setLive(1); } String url = LiveUtils.getLiveUrl(roomId); + if(url==null){ + stop(); + return; + } HashMap header = new HashMap(); header.put("Sec-WebSocket-Extensions", "permessage-deflate; client_max_window_bits"); header.put("Sec-WebSocket-Key", "tORCZd8AI6xIyvqvgvI1Vw=="); @@ -120,7 +125,7 @@ public class Live implements ApplicationContextAware { @Override public void onOpen(ServerHandshake serverHandshake) { time = System.currentTimeMillis(); - System.out.println("ws: ok"); + com.yutou.bilibili.Tools.Log.i("ws: ok"); try { likeLive(); } catch (Exception e) { @@ -147,7 +152,7 @@ public class Live implements ApplicationContextAware { @Override public void onClose(int i, String s, boolean b) { - System.out.println("连接时间:" + (System.currentTimeMillis() - time)); + com.yutou.bilibili.Tools.Log.i("连接时间:" + (System.currentTimeMillis() - time)); if (upData.getOfflinelistening() == 1) { System.err.println(roomId + " 断开连接,重连..."); try { @@ -169,7 +174,7 @@ public class Live implements ApplicationContextAware { @Override public void onClosing(int code, String reason, boolean remote) { super.onClosing(code, reason, remote); - System.out.println("code = " + code + ", reason = " + reason + ", remote = " + remote); + com.yutou.bilibili.Tools.Log.i("code = " + code + ", reason = " + reason + ", remote = " + remote); } @Override @@ -189,7 +194,7 @@ public class Live implements ApplicationContextAware { SaveLive.getInstance().stop(roomId); } Live.lives.remove(this); - System.out.printf("退出%d直播间%n", roomId); + com.yutou.bilibili.Tools.Log.i("退出"+roomId+"直播间"); } /** @@ -221,7 +226,7 @@ public class Live implements ApplicationContextAware { json.put("clientver", "2.6.36"); json.put("type", 2); json.put("key", http.getJSONObject("data").getString("token")); - System.out.println(json.toJSONString()); + com.yutou.bilibili.Tools.Log.i(json.toJSONString()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(LiveUtils.toLH(json.toJSONString().length() + 16)); outputStream.write(new byte[]{0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1}); @@ -251,19 +256,18 @@ public class Live implements ApplicationContextAware { } else { try { JSONObject json = JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8)); - System.out.println(json); + com.yutou.bilibili.Tools.Log.i(json.toJSONString()); } catch (Exception e) { popular = LiveUtils.bytesToInt2(bytes, 0); info.setPopular(popular); } } - checkLive(); } catch (Exception e) { e.printStackTrace(); - System.out.println("----------ERROR----------"); - System.out.println(new String(data, StandardCharsets.UTF_8)); + com.yutou.bilibili.Tools.Log.i("----------ERROR----------"); + com.yutou.bilibili.Tools.Log.i(new String(data, StandardCharsets.UTF_8)); LiveUtils.printHex(LiveUtils.dec(data)); - System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date())); + com.yutou.bilibili.Tools.Log.i(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date())); } } @@ -293,7 +297,7 @@ public class Live implements ApplicationContextAware { switch (json.getString("cmd")) { case "INTERACT_WORD"://普通用户进直播间 - // System.out.println(json.getJSONObject("data").getString("uname") + " 进入到直播间"); + // com.yutou.bilibili.Tools.Log.i(json.getJSONObject("data").getString("uname") + " 进入到直播间"); danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间"; liveData.setUid(json.getJSONObject("data").getInteger("uid")); liveData.setType(LiveData.INTERACT_WORD); @@ -317,7 +321,7 @@ public class Live implements ApplicationContextAware { } danmuManager.addLiveData(liveData);*/ } - System.out.println(json); + // com.yutou.bilibili.Tools.Log.i(json.toJSONString()); break; case "SEND_GIFT"://送礼 data = json.getJSONObject("data"); @@ -376,7 +380,7 @@ public class Live implements ApplicationContextAware { service.addLiveData(liveData); break; case "ENTRY_EFFECT"://舰长进直播间 - // System.out.println("[舰长]" + json.getJSONObject("data").getString("uid") + " 进入到直播间"); + // com.yutou.bilibili.Tools.Log.i("[舰长]" + json.getJSONObject("data").getString("uid") + " 进入到直播间"); info.setVipuserindex(info.getVipuserindex() + 1); danmu = "[舰长]" + json.getJSONObject("data").getString("uid") + " 进入到直播间"; liveData.setUid(json.getJSONObject("data").getInteger("uid")); @@ -439,10 +443,10 @@ public class Live implements ApplicationContextAware { case "PK_BATTLE_PRE": - //System.out.println(msg); + //com.yutou.bilibili.Tools.Log.i(msg); break; default: - System.out.println(msg); + com.yutou.bilibili.Tools.Log.i(msg); liveData = new BilibiliLiveData(); liveData.setType(LiveData.UNKNOWN_MESSAGE); liveData.setUid(-1); @@ -458,9 +462,8 @@ public class Live implements ApplicationContextAware { processData(new String(bytes, StandardCharsets.UTF_8), null); } catch (Exception e2) { e2.printStackTrace(); - System.out.println(msg); - System.out.println("---------ERROR !!-----"); - System.out.println(); + com.yutou.bilibili.Tools.Log.i(msg); + com.yutou.bilibili.Tools.Log.i("---------ERROR !!-----"); LiveUtils.printHex(bytes); } @@ -516,7 +519,7 @@ public class Live implements ApplicationContextAware { stop(); } try { - // System.out.println("-------发送心跳--------"); + // com.yutou.bilibili.Tools.Log.i("-------发送心跳--------"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(LiveUtils.toLH("[object Object]".length() + 16)); outputStream.write(new byte[]{0, 16, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1}); @@ -525,8 +528,8 @@ public class Live implements ApplicationContextAware { client.send(outputStream.toByteArray()); } catch (Exception e) { e.printStackTrace(); - System.out.println(client.isClosed()); - System.out.println(client.isOpen()); + com.yutou.bilibili.Tools.Log.i(client.isClosed()); + com.yutou.bilibili.Tools.Log.i(client.isOpen()); } diff --git a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java index cb1d81f..2d80b39 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java @@ -1,11 +1,13 @@ package com.yutou.bilibili.BiliBili; +import com.yutou.bilibili.BiliBili.Datas.BiliBiliUpData; import com.yutou.bilibili.BiliBili.Datas.GiftData; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService; import com.yutou.bilibili.Tools.AppTools; +import com.yutou.bilibili.Tools.Log; import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo; import org.springframework.util.StringUtils; @@ -20,7 +22,7 @@ import java.util.*; import java.util.zip.Inflater; public class LiveUtils { - private static String cookie=null; + private static String cookie = null; public LiveUtils() { @@ -29,19 +31,21 @@ public class LiveUtils { public static String getLiveUrl(int roomId) { JSONObject json = http_get("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=" + roomId + "&type=0"); - return "wss://" + json.getJSONObject("data").getJSONArray("host_list").getJSONObject(0).getString("host") + "/sub"; + if (json != null) + return "wss://" + json.getJSONObject("data").getJSONArray("host_list").getJSONObject(0).getString("host") + "/sub"; + return null; } public static void printHex(byte[] bytes) { String str = DatatypeConverter.printHexBinary(bytes); for (int i = 0; i < str.length(); i = i + 4) { if (i % 32 == 0 && i != 0) { - System.out.println(); + com.yutou.bilibili.Tools.Log.i("\n"); } if (str.length() - i > 4) { System.out.print(str.substring(i, i + 4)); } else { - System.out.println(str.substring(i)); + com.yutou.bilibili.Tools.Log.i(str.substring(i)); } System.out.print(" "); } @@ -100,7 +104,7 @@ public class LiveUtils { list.add(new String(datas.array(), StandardCharsets.UTF_8)); } else { try { - // System.out.println("datas size = " + size); + // com.yutou.bilibili.Tools.Log.i("datas size = " + size); if (size > 1000000000) { try { JSONObject.parseObject(new String(bytes)); @@ -201,7 +205,7 @@ public class LiveUtils { } catch (IOException e) { e.printStackTrace(); } - return new JSONObject(); + return null; } public static JSONObject http_post(String url, String body) { @@ -307,7 +311,11 @@ public class LiveUtils { public static boolean isLivePlayer(int roomId) { JSONObject json = http_get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + roomId); - System.out.println("直播检测:" + roomId+" > "+(json.getJSONObject("data").getJSONObject("room_info").getInteger("live_status") == 1)); + if (json == null) + return false; + BilibiliUpInfo upData = new BilibiliUpInfo(); + upData.setRoomid(roomId); + 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; } diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Services/impl/BiliBiliLiveServiceImpl.java b/src/main/java/com/yutou/bilibili/BiliBili/Services/impl/BiliBiliLiveServiceImpl.java index 4cc09d6..8c0ecc5 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Services/impl/BiliBiliLiveServiceImpl.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Services/impl/BiliBiliLiveServiceImpl.java @@ -60,7 +60,7 @@ public class BiliBiliLiveServiceImpl implements IBiliBiliLiveService { return upInfos; } upInfos = upInfoDao.queryToRoomIds(ids); - System.out.println("list = " + upInfos.size()); + com.yutou.bilibili.Tools.Log.i("list = " + upInfos.size()); return upInfos; } diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Tools/BiliTools.java b/src/main/java/com/yutou/bilibili/BiliBili/Tools/BiliTools.java index b91a576..ed48fc8 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Tools/BiliTools.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Tools/BiliTools.java @@ -28,11 +28,11 @@ public class BiliTools { } BilibiliUpInfo upData = new BilibiliUpInfo(); JSONObject json = LiveUtils.http_get("https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + url.replace("https://live.bilibili.com/", "").split("\\?")[0]); - System.out.println(json); + com.yutou.bilibili.Tools.Log.i(json); String roomId = json.getJSONObject("data").getJSONObject("room_info").getInteger("room_id") + ""; String name = json.getJSONObject("data").getJSONObject("anchor_info").getJSONObject("base_info").getString("uname"); - System.out.println(roomId); - System.out.println(name); + com.yutou.bilibili.Tools.Log.i(roomId); + com.yutou.bilibili.Tools.Log.i(name); upData.setRoomid(Integer.parseInt(roomId)); upData.setName(name); upData.setUrl(url); diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Tools/LiveT.java b/src/main/java/com/yutou/bilibili/BiliBili/Tools/LiveT.java index 34dc030..619b61c 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Tools/LiveT.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Tools/LiveT.java @@ -26,11 +26,11 @@ public class LiveT implements ApplicationContextAware { @PostConstruct public void init() { - System.out.println("初始化2"); + com.yutou.bilibili.Tools.Log.i("初始化2"); } public LiveT() { - System.out.println("初始化"); + com.yutou.bilibili.Tools.Log.i("初始化"); } public void add(int a){ diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Tools/SaveLive.java b/src/main/java/com/yutou/bilibili/BiliBili/Tools/SaveLive.java index c542f24..b04b5eb 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Tools/SaveLive.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Tools/SaveLive.java @@ -54,7 +54,7 @@ public class SaveLive { private long timer = 0; public void stop(int roomId) { - System.out.println("t停止录播:" + roomId + " time=" + (System.currentTimeMillis() - timer)); + com.yutou.bilibili.Tools.Log.i("t停止录播:" + roomId + " time=" + (System.currentTimeMillis() - timer)); saveList.remove(roomId + ""); if(downloads.containsKey(roomId)){ @@ -107,7 +107,7 @@ public class SaveLive { super.run(); String url = getLiveUrl(roomId); try { - System.out.println("开始录制:" + roomId); + com.yutou.bilibili.Tools.Log.i("开始录制:" + roomId); HttpURLConnection connection = LiveUtils.getBiliHttpGet(url, LiveUtils.getCookie()); heartbeat = new Timer(); //Heartbeat beat = new Heartbeat(); @@ -134,7 +134,7 @@ public class SaveLive { } outputStream.close(); inputStream.close(); - System.out.println("录制完成:" + roomId + " save = " + isSave + " len = " + len); + com.yutou.bilibili.Tools.Log.i("录制完成:" + roomId + " save = " + isSave + " len = " + len); } catch (Exception e) { e.printStackTrace(); } finally { @@ -151,16 +151,16 @@ public class SaveLive { JSONObject userHear = new JSONObject(); JSONObject cookie = JSONObject.parseObject(LiveUtils.getFile("cookies.json")); hearBeat = LiveUtils.http_get("https://api.live.bilibili.com/relation/v1/Feed/heartBeat"); - System.out.printf(hearBeat+" \t"); + com.yutou.bilibili.Tools.Log.i(hearBeat+" \t"); hearBeat = LiveUtils.http_get(String.format("https://live-trace.bilibili.com/xlive/rdata-interface/v1/heartbeat/webHeartBeat?hb=%s&pf=web", URLEncoder.encode(new String(Base64.getEncoder().encode(String.format("%d|%d|1|0",nextInterval, roomId).getBytes(StandardCharsets.UTF_8))), "UTF-8"))); - System.out.printf(hearBeat+"\t"); + com.yutou.bilibili.Tools.Log.i(hearBeat+"\t"); nextInterval=hearBeat.getJSONObject("data").getInteger("next_interval"); - System.out.println("next = "+nextInterval); + com.yutou.bilibili.Tools.Log.i("next = "+nextInterval); userHear.put("csrf_token",cookie.getString("bili_jct")); userHear.put("csrf",cookie.getString("bili_jct")); userHear.put("visit_id",""); hearBeat=LiveUtils.http_post("https://api.live.bilibili.com/User/userOnlineHeart", HttpTools.toUrlParams(userHear)); - System.out.println("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat); + com.yutou.bilibili.Tools.Log.i("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/yutou/bilibili/Tools/APIFilter.java b/src/main/java/com/yutou/bilibili/Tools/APIFilter.java index a2ba58a..4a1f23c 100644 --- a/src/main/java/com/yutou/bilibili/Tools/APIFilter.java +++ b/src/main/java/com/yutou/bilibili/Tools/APIFilter.java @@ -56,7 +56,7 @@ public class APIFilter implements Filter { url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0]; } catch (Exception e) { e.printStackTrace(); - System.out.println("无权限请求:"+tmp); + com.yutou.bilibili.Tools.Log.i("无权限请求:"+tmp); return; } JSONArray powers = JSONArray.parseArray(user.getPower()); diff --git a/src/main/java/com/yutou/bilibili/Tools/AppTools.java b/src/main/java/com/yutou/bilibili/Tools/AppTools.java index 01ae95b..006874e 100644 --- a/src/main/java/com/yutou/bilibili/Tools/AppTools.java +++ b/src/main/java/com/yutou/bilibili/Tools/AppTools.java @@ -163,7 +163,7 @@ public class AppTools { public static String deleteCookie(HttpServletRequest request, HttpServletResponse response, String key) { for (Cookie cookie : request.getCookies()) { if (cookie.getName().equals(key)) { - System.out.println("删除key=" + key); + com.yutou.bilibili.Tools.Log.i("删除key=" + key); cookie.setMaxAge(0); cookie.setPath("/"); cookie.setValue(null); @@ -273,7 +273,7 @@ public class AppTools { }else{ if(srcFileName.equals("Activity.smali")){ - System.out.println("文件夹已存在:"+destFileName); + com.yutou.bilibili.Tools.Log.i("文件夹已存在:"+destFileName); } } diff --git a/src/main/java/com/yutou/bilibili/Tools/ExcelUtils.java b/src/main/java/com/yutou/bilibili/Tools/ExcelUtils.java index d7b46f9..5c5b2ee 100644 --- a/src/main/java/com/yutou/bilibili/Tools/ExcelUtils.java +++ b/src/main/java/com/yutou/bilibili/Tools/ExcelUtils.java @@ -28,10 +28,10 @@ public class ExcelUtils implements ApplicationContextAware { public static File getInstance(int roomId, Date startTime, Date endTime,String fileName) { ExcelUtils utils = new ExcelUtils(); long timer=System.currentTimeMillis(); - System.out.println("开始注入bean"); + com.yutou.bilibili.Tools.Log.i("开始注入bean"); utils.dataDao = getBean(BilibiliLiveDataDao.class); utils.infoDao = getBean(BilibiliLiveInfoDao.class); - System.out.println("注入完毕:"+(System.currentTimeMillis()-timer)); + com.yutou.bilibili.Tools.Log.i("注入完毕:"+(System.currentTimeMillis()-timer)); return utils.initTable(roomId, startTime, endTime,fileName); } @@ -41,7 +41,7 @@ public class ExcelUtils implements ApplicationContextAware { private File initTable(int roomId, Date startTime, Date endTime,String fileName) { long timer=System.currentTimeMillis(); - System.out.println("进入统计:"+timer); + com.yutou.bilibili.Tools.Log.i("进入统计:"+timer); Workbook workbook = new XSSFWorkbook(); Sheet liveData = workbook.createSheet("直播数据"); Sheet liveInfo = workbook.createSheet("小时统计"); @@ -66,7 +66,7 @@ public class ExcelUtils implements ApplicationContextAware { createCell(infoRow.createCell(5), "送礼人数"); createCell(infoRow.createCell(6), "记录时间"); - System.out.println("表头插入完毕:"+(System.currentTimeMillis()-timer)); + com.yutou.bilibili.Tools.Log.i("表头插入完毕:"+(System.currentTimeMillis()-timer)); List dataList = dataDao.queryLiveData(roomId, startTime, endTime, new String[]{ INTERACT_WORD, ENTRY_EFFECT, @@ -104,7 +104,7 @@ public class ExcelUtils implements ApplicationContextAware { createCell(infoRow.createCell(5), info.getGiftuser()); createCell(infoRow.createCell(6), AppTools.getToDayTimeToString(info.getSubtime())); } - System.out.println("数据填充完毕:"+(System.currentTimeMillis()-timer)); + com.yutou.bilibili.Tools.Log.i("数据填充完毕:"+(System.currentTimeMillis()-timer)); try { if(!new File("excel").exists()){ new File("excel").mkdirs(); @@ -113,7 +113,7 @@ public class ExcelUtils implements ApplicationContextAware { FileOutputStream fileOutputStream = new FileOutputStream(file); workbook.write(fileOutputStream); workbook.close(); - System.out.println("文件写入完毕:"+(System.currentTimeMillis()-timer)); + com.yutou.bilibili.Tools.Log.i("文件写入完毕:"+(System.currentTimeMillis()-timer)); file.renameTo(new File("excel"+File.separator+fileName)); return file; } catch (Exception e) { diff --git a/src/main/java/com/yutou/bilibili/Tools/FFmpegUtils.java b/src/main/java/com/yutou/bilibili/Tools/FFmpegUtils.java index 88052de..b697e6a 100644 --- a/src/main/java/com/yutou/bilibili/Tools/FFmpegUtils.java +++ b/src/main/java/com/yutou/bilibili/Tools/FFmpegUtils.java @@ -39,7 +39,7 @@ public class FFmpegUtils { ffmpeg, file.getAbsolutePath(), out.getAbsolutePath() + File.separator + file.getName()); - System.out.println(exec); + com.yutou.bilibili.Tools.Log.i(exec); Process process = Runtime.getRuntime().exec(new String[]{ "cmd", "/c", @@ -67,13 +67,13 @@ public class FFmpegUtils { int i = -1; while (i != 1) { i = add("D:\\ffmpeg-4.3.1-2020-11-19-full_build\\bin\\ffmpeg.exe", file.getAbsoluteFile(), new File("ffmpeg_out")); - System.out.println(i); + com.yutou.bilibili.Tools.Log.i(i); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } - System.out.println("转码完成"); + com.yutou.bilibili.Tools.Log.i("转码完成"); } } diff --git a/src/main/java/com/yutou/bilibili/Tools/HttpTools.java b/src/main/java/com/yutou/bilibili/Tools/HttpTools.java index 74e3be5..bae889f 100644 --- a/src/main/java/com/yutou/bilibili/Tools/HttpTools.java +++ b/src/main/java/com/yutou/bilibili/Tools/HttpTools.java @@ -64,7 +64,7 @@ public class HttpTools { str.append(tmp); } - // System.out.println( "[" + url + "?" + new String(body,StandardCharsets.UTF_8) + "]body:" + str + " (" + connection.getResponseCode() + ")"); + // com.yutou.bilibili.Tools.Log.i( "[" + url + "?" + new String(body,StandardCharsets.UTF_8) + "]body:" + str + " (" + connection.getResponseCode() + ")"); if (networkInterface != null) { try { networkInterface.httpGetData(str.toString(), connection.getResponseCode()); @@ -130,7 +130,7 @@ public class HttpTools { } }); }*/ - System.out.println(url); + com.yutou.bilibili.Tools.Log.i(url); //String str=get(url); } } diff --git a/src/main/java/com/yutou/bilibili/Tools/Log.java b/src/main/java/com/yutou/bilibili/Tools/Log.java new file mode 100644 index 0000000..d1176c4 --- /dev/null +++ b/src/main/java/com/yutou/bilibili/Tools/Log.java @@ -0,0 +1,11 @@ +package com.yutou.bilibili.Tools; + +public class Log { + public static void i(Object log){ + System.out.printf("[%s]%s%n", + AppTools.getToDayNowTimeToString(), + log + ); + + } +} diff --git a/src/main/java/com/yutou/bilibili/Tools/ServiceTools.java b/src/main/java/com/yutou/bilibili/Tools/ServiceTools.java index 6c94627..a087d79 100644 --- a/src/main/java/com/yutou/bilibili/Tools/ServiceTools.java +++ b/src/main/java/com/yutou/bilibili/Tools/ServiceTools.java @@ -37,7 +37,7 @@ public class ServiceTools implements ApplicationContextAware { url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0]; } catch (Exception e) { e.printStackTrace(); - System.out.println("无权限请求:" + tmp); + com.yutou.bilibili.Tools.Log.i("无权限请求:" + tmp); return false; } JSONArray powers = JSONArray.parseArray(user.getPower()); diff --git a/src/main/java/com/yutou/bilibili/Tools/TestMain.java b/src/main/java/com/yutou/bilibili/Tools/TestMain.java index 472879c..d7cd2aa 100644 --- a/src/main/java/com/yutou/bilibili/Tools/TestMain.java +++ b/src/main/java/com/yutou/bilibili/Tools/TestMain.java @@ -46,7 +46,7 @@ public class TestMain { } String str = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);*/ - System.out.println("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat); + com.yutou.bilibili.Tools.Log.i("["+AppTools.getToDayNowTimeToString()+"]"+hearBeat); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/yutou/bilibili/sqlite/BiliBiliLiveDatabasesManager.java b/src/main/java/com/yutou/bilibili/sqlite/BiliBiliLiveDatabasesManager.java index 15e9c3c..2d2f638 100644 --- a/src/main/java/com/yutou/bilibili/sqlite/BiliBiliLiveDatabasesManager.java +++ b/src/main/java/com/yutou/bilibili/sqlite/BiliBiliLiveDatabasesManager.java @@ -181,7 +181,7 @@ public class BiliBiliLiveDatabasesManager extends SQLiteManager { + ", " + (upData.isEnable() ? 1 : 0) + ", " + (upData.isSaveDanmu() ? 1 : 0) + ");"; - System.out.println(sql); + com.yutou.bilibili.Tools.Log.i(sql); statement.execute(sql); statement.closeOnCompletion(); return true; @@ -257,7 +257,7 @@ public class BiliBiliLiveDatabasesManager extends SQLiteManager { return true; } catch (Exception e) { e.printStackTrace(); - System.out.println(sql); + com.yutou.bilibili.Tools.Log.i(sql); } return false; } diff --git a/src/main/java/com/yutou/bilibili/sqlite/SQLiteManager.java b/src/main/java/com/yutou/bilibili/sqlite/SQLiteManager.java index 2876c1c..c096370 100644 --- a/src/main/java/com/yutou/bilibili/sqlite/SQLiteManager.java +++ b/src/main/java/com/yutou/bilibili/sqlite/SQLiteManager.java @@ -53,7 +53,7 @@ public class SQLiteManager { startBatch(); JSONArray array=json.getJSONArray("table"); for (Object o : array) { - System.out.println("创建表:"+((JSONObject)o).getString("name")); + com.yutou.bilibili.Tools.Log.i("创建表:"+((JSONObject)o).getString("name")); createSqlOfTable((JSONObject) o); } closeBatch();