update 调整弹幕按批次加载,防止过多
This commit is contained in:
@@ -34,6 +34,8 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
private boolean isRecordLive;
|
||||
@JSONField(name = "recordDanmu")
|
||||
private boolean isRecordDanmu;
|
||||
@JSONField(name = "syncDanmuForLive")
|
||||
private boolean isSyncDanmuForLive;
|
||||
@JSONField(name = "keyword")
|
||||
private List<String> keywordList;
|
||||
@JSONField(name = "weeks")
|
||||
|
||||
@@ -8,6 +8,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@@ -23,7 +24,7 @@ public class LiveDanmuDatabaseBean extends AbsDatabasesBean {
|
||||
@JSONField(name = "color")
|
||||
private String fontColor;
|
||||
@JSONField(name = "time")
|
||||
private long time;
|
||||
private Date time;
|
||||
@JSONField(name = "uid")
|
||||
private String uid;
|
||||
@JSONField(name = "uname")
|
||||
@@ -40,7 +41,7 @@ public class LiveDanmuDatabaseBean extends AbsDatabasesBean {
|
||||
model = danmu.getModel();
|
||||
fontSize = danmu.getFontSize();
|
||||
fontColor = danmu.getFontColor();
|
||||
time = danmu.getTime();
|
||||
time = new Date(danmu.getTime());
|
||||
uid = danmu.getUid();
|
||||
uname = danmu.getUname();
|
||||
}
|
||||
@@ -52,7 +53,7 @@ public class LiveDanmuDatabaseBean extends AbsDatabasesBean {
|
||||
data.setModel(model);
|
||||
data.setFontSize(fontSize);
|
||||
data.setFontColor(fontColor);
|
||||
data.setTime(time);
|
||||
data.setTime(time.getTime());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +207,39 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
return super.get(tableName, where, clazz);
|
||||
}
|
||||
|
||||
public <T extends AbsDatabasesBean> List<T> getOfTime(Long startTime, Long endTime, int page,int pageSize, Class<T> clazz) {
|
||||
String tableName = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String where = null;
|
||||
if (startTime != null) {
|
||||
sb.append(" `sql_time` >= ").append("\"").append(startTime).append("\"");
|
||||
}
|
||||
if (endTime != null) {
|
||||
if (!sb.isEmpty()) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
sb.append(" `sql_time` <= ").append("\"").append(endTime).append("\"");
|
||||
}
|
||||
sb.append("ORDER BY `sql_time` LIMIT ").append(page).append("*").append(pageSize).append(",").append(pageSize);
|
||||
if (!sb.isEmpty()) {
|
||||
where = sb.toString();
|
||||
}
|
||||
for (AbsDatabasesBean bean : getDataBean()) {
|
||||
if (bean.getClass() == clazz) {
|
||||
tableName = bean.getTableName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.get(tableName, where, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount(String table) {
|
||||
return super.getCount(table);
|
||||
}
|
||||
|
||||
public LiveVideoDatabaseBean getVideo(String videoId) {
|
||||
for (LiveVideoDatabaseBean info : getLiveInfos()) {
|
||||
System.out.println(videoId + " " + info.getSql_time().getTime());
|
||||
if (videoId.trim().equals(String.valueOf(info.getSql_time().getTime()))) {
|
||||
return info;
|
||||
}
|
||||
@@ -241,8 +271,8 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("7688602"));
|
||||
biliLiveDatabase.resetSQL();
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("33989"));
|
||||
// biliLiveDatabase.resetSQL();
|
||||
biliLiveDatabase.resetData();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.yutou.biliapi.bean.websocket.WebSocketHeader;
|
||||
import com.yutou.biliapi.bean.websocket.live.WSData;
|
||||
import com.yutou.biliapi.databases.BiliBiliLoginDatabase;
|
||||
import com.yutou.biliapi.databases.BiliLiveDatabase;
|
||||
import com.yutou.biliapi.utils.BiliUserUtils;
|
||||
import com.yutou.biliapi.utils.BytesUtils;
|
||||
import com.yutou.common.okhttp.HttpBody;
|
||||
import com.yutou.common.okhttp.HttpCallback;
|
||||
@@ -39,20 +38,20 @@ import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WebSocketManager {
|
||||
public class WebSocketClientManager {
|
||||
ThreadPoolExecutor executor;
|
||||
private static WebSocketManager instance;
|
||||
private static WebSocketClientManager instance;
|
||||
Map<LiveRoomConfig, DanmuTask> roomMap;
|
||||
private final List<String> userStopList = new ArrayList<>();//手动停止列表
|
||||
|
||||
private WebSocketManager() {
|
||||
private WebSocketClientManager() {
|
||||
roomMap = new HashMap<>();
|
||||
executor = new ThreadPoolExecutor(2, 4, Long.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
|
||||
}
|
||||
|
||||
public static WebSocketManager getInstance() {
|
||||
public static WebSocketClientManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new WebSocketManager();
|
||||
instance = new WebSocketClientManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -105,7 +104,7 @@ public class WebSocketManager {
|
||||
|
||||
public DanmuTask(LiveRoomConfig config) {
|
||||
this.roomConfig = config;
|
||||
WebSocketManager.getInstance().roomMap.put(roomConfig, this);
|
||||
WebSocketClientManager.getInstance().roomMap.put(roomConfig, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,7 +117,7 @@ public class WebSocketManager {
|
||||
roomConfig.setRoomInfo(execute.body() != null ? execute.body().getData() : null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||
WebSocketClientManager.getInstance().roomMap.remove(roomConfig);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
api.getLiveRoomDanmuInfo(String.valueOf(roomConfig.getRoomId())).enqueue(new HttpCallback<LiveDanmuInfo>() {
|
||||
@@ -132,7 +131,7 @@ public class WebSocketManager {
|
||||
roomConfig.setLiveInfo(response);
|
||||
client = new WebSocketClientTh(new URI(url), roomConfig);
|
||||
} catch (URISyntaxException e) {
|
||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||
WebSocketClientManager.getInstance().roomMap.remove(roomConfig);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -140,7 +139,7 @@ public class WebSocketManager {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||
WebSocketClientManager.getInstance().roomMap.remove(roomConfig);
|
||||
Log.e(throwable);
|
||||
}
|
||||
});
|
||||
@@ -152,10 +151,9 @@ public class WebSocketManager {
|
||||
}
|
||||
|
||||
private static class WebSocketClientTh extends WebSocketClient {
|
||||
private LiveRoomConfig roomConfig;
|
||||
private HeartbeatTask heartbeatTask;
|
||||
private final LiveRoomConfig roomConfig;
|
||||
private final HeartbeatTask heartbeatTask;
|
||||
BiliLiveDatabase liveDatabase;
|
||||
private boolean itTmp = true;
|
||||
|
||||
public WebSocketClientTh(URI serverUri, LiveRoomConfig roomId) {
|
||||
super(serverUri);
|
||||
@@ -192,7 +190,7 @@ public class WebSocketManager {
|
||||
@Override
|
||||
public void onClose(int i, String s, boolean b) {
|
||||
Log.e("WebSocketClientTh.onClose", "i = " + i + ", s = " + s + ", b = " + b, roomConfig.getRoomId(), heartbeatTask.socket.isOpen());
|
||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||
WebSocketClientManager.getInstance().roomMap.remove(roomConfig);
|
||||
liveDatabase.close();
|
||||
heartbeatTask.cancel();
|
||||
}
|
||||
@@ -201,7 +199,7 @@ public class WebSocketManager {
|
||||
public void onError(Exception e) {
|
||||
Log.i("WebSocketClientTh.onError", roomConfig.getRoomId());
|
||||
Log.e(e);
|
||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||
WebSocketClientManager.getInstance().roomMap.remove(roomConfig);
|
||||
liveDatabase.close();
|
||||
heartbeatTask.cancel();
|
||||
}
|
||||
@@ -285,30 +283,25 @@ public class WebSocketManager {
|
||||
}
|
||||
LoginCookieDatabaseBean cookie = BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid());
|
||||
Log.d("cookie:", cookie, "RoomId:" + roomConfig);
|
||||
String buvid = BiliUserUtils.getBuvid(cookie);
|
||||
if (buvid != null) {
|
||||
try {
|
||||
json.put("roomid", new BigInteger(roomConfig.getRoomId()));
|
||||
json.put("protover", 3);
|
||||
json.put("buvid", buvid);
|
||||
json.put("platform", "web");
|
||||
json.put("type", 2);
|
||||
json.put("key", roomConfig.getLiveInfo().getToken());
|
||||
byte[] bytes = {0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1};
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
json.put("roomid", new BigInteger(roomConfig.getRoomId()));
|
||||
json.put("protover", 3);
|
||||
json.put("platform", "web");
|
||||
json.put("type", 2);
|
||||
json.put("key", roomConfig.getLiveInfo().getToken());
|
||||
byte[] bytes = {0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1};
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
// Log.i("bytes.length = " + bytes.length);
|
||||
Log.i(json);
|
||||
outputStream.write(BytesUtils.toLH(json.toString().length() + 16));
|
||||
outputStream.write(bytes);
|
||||
outputStream.write(json.toJSONString().getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
Log.i(json);
|
||||
outputStream.write(BytesUtils.toLH(json.toString().length() + 16));
|
||||
outputStream.write(bytes);
|
||||
outputStream.write(json.toJSONString().getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
// BytesUtils.printHex(outputStream.toByteArray());
|
||||
Log.i(socket.isOpen(), json.toString());
|
||||
socket.send(outputStream.toByteArray());
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
Log.i(socket.isOpen(), json.toString());
|
||||
socket.send(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user