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);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.yutou.bilibili.services.LiveConfigService;
|
||||
import com.yutou.bilibili.services.LiveLoginService;
|
||||
import com.yutou.bilibili.services.LiveUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -154,6 +153,9 @@ public class LiveConfigController {
|
||||
if("on".equals(config.getString("recordLive"))){
|
||||
bean.setRecordLive(true);
|
||||
}
|
||||
if("on".equals(config.getString("syncDanmuForLive"))){
|
||||
bean.setSyncDanmuForLive(true);
|
||||
}
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("array");
|
||||
List<LiveConfigDatabaseBean> list = jsonArray.stream().map(roomId -> configService.addConfig(roomId.toString(), bean)).toList();
|
||||
int countNull = list.stream().filter(Objects::isNull).toList().size();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.yutou.bilibili.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
||||
import com.yutou.biliapi.net.WebSocketManager;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.datas.ReturnCode;
|
||||
import com.yutou.bilibili.services.LiveDanmuService;
|
||||
@@ -44,7 +42,7 @@ public class LiveDanmuController {
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/live/danmu/get")
|
||||
public JSONObject getDanmu(String roomId, String videoId) {
|
||||
return ResultData.success(service.getDanmu(roomId, videoId));
|
||||
public JSONObject getDanmu(String roomId, String videoId, int page) {
|
||||
return ResultData.success(service.getDanmu(roomId, videoId, page));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ public class LiveVideoDanmu {
|
||||
|
||||
List<Danmu> danmu = new ArrayList<>();
|
||||
List<SuperChat> superChat = new ArrayList<>();
|
||||
|
||||
boolean isNextDanmu = false;
|
||||
long danmuCount = 0;
|
||||
|
||||
@Data
|
||||
public static class Addition {
|
||||
@@ -60,7 +61,7 @@ public class LiveVideoDanmu {
|
||||
this.backgroundBottomColor = bean.getBackgroundBottomColor();
|
||||
this.userName = bean.getUserName();
|
||||
this.userAvatar = bean.getUserAvatar();
|
||||
this.userNameColor=bean.getUserNameColor();
|
||||
this.userNameColor = bean.getUserNameColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,44 +10,44 @@ import com.yutou.biliapi.bean.live.database.LiveVideoDatabaseBean;
|
||||
import com.yutou.biliapi.bean.websocket.live.WSData;
|
||||
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
||||
import com.yutou.biliapi.databases.BiliLiveDatabase;
|
||||
import com.yutou.biliapi.net.WebSocketManager;
|
||||
import com.yutou.biliapi.net.WebSocketClientManager;
|
||||
import com.yutou.bilibili.Tools.AssTools;
|
||||
import com.yutou.bilibili.Tools.DateFormatUtils;
|
||||
import com.yutou.bilibili.Tools.Tools;
|
||||
import com.yutou.bilibili.datas.web.LiveVideoDanmu;
|
||||
import com.yutou.common.utils.FFmpegUtils;
|
||||
import com.yutou.common.utils.Log;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LiveDanmuService {
|
||||
|
||||
public void start(String roomId, boolean isUser) {
|
||||
WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), isUser);
|
||||
WebSocketClientManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), isUser);
|
||||
}
|
||||
|
||||
public void start(LiveConfigDatabaseBean roomId, boolean isUser) {
|
||||
WebSocketClientManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId.getRoomId()), isUser);
|
||||
}
|
||||
|
||||
public boolean check(String roomId) {
|
||||
LiveRoomConfig roomConfig = new LiveRoomConfig();
|
||||
roomConfig.setRoomId(roomId);
|
||||
return WebSocketManager.getInstance().checkRoom(roomConfig);
|
||||
return WebSocketClientManager.getInstance().checkRoom(roomConfig);
|
||||
}
|
||||
|
||||
public void stop(String roomId, boolean isUser) {
|
||||
WebSocketManager.getInstance().stopRoom(roomId, isUser);
|
||||
WebSocketClientManager.getInstance().stopRoom(roomId, isUser);
|
||||
}
|
||||
|
||||
public JSONArray getLiveRoomList() {
|
||||
return WebSocketManager.getInstance().getLiveRoomList();
|
||||
return WebSocketClientManager.getInstance().getLiveRoomList();
|
||||
}
|
||||
|
||||
public void clearUserList() {
|
||||
WebSocketManager.getInstance().clearUserStopList();
|
||||
WebSocketClientManager.getInstance().clearUserStopList();
|
||||
}
|
||||
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
@@ -86,21 +86,33 @@ public class LiveDanmuService {
|
||||
return String.format("%d小时%d分钟%d秒", hours, minutes, finalRemainingSeconds);
|
||||
}
|
||||
|
||||
public LiveVideoDanmu getDanmu(String roomId, String videoId) {
|
||||
public LiveVideoDanmu getDanmu(String roomId, String videoId, int page) {
|
||||
LiveVideoDanmu danmus = new LiveVideoDanmu();
|
||||
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId));
|
||||
LiveVideoDatabaseBean videoBean = liveDatabase.getVideo(videoId);
|
||||
if (videoBean == null) {
|
||||
return new LiveVideoDanmu();
|
||||
}
|
||||
long startTime = Long.parseLong(videoId);
|
||||
long startTime = videoBean.getStartTime().getTime();
|
||||
long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime();
|
||||
List<LiveDanmuDatabaseBean> danmuList = liveDatabase.getOfTime(startTime, endTime, LiveDanmuDatabaseBean.class);
|
||||
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class);
|
||||
for (LiveDanmuDatabaseBean bean : danmuList) {
|
||||
LiveVideoDanmu.Danmu danmu = createDanmu(bean, startTime);
|
||||
danmus.getDanmu().add(danmu);
|
||||
|
||||
long count = liveDatabase.getCount(new LiveDanmuDatabaseBean().getTableName());
|
||||
int pageSize = 10000;
|
||||
int pageCount = (int) Math.ceil((double) count / pageSize);
|
||||
|
||||
List<LiveVideoDanmu.Danmu> danmuList = liveDatabase.getOfTime(startTime, endTime, page, pageSize, LiveDanmuDatabaseBean.class)
|
||||
.stream()
|
||||
.map(item -> createDanmu(item, startTime))
|
||||
.filter(item-> item.getTime()>=0)
|
||||
.toList();
|
||||
danmus.getDanmu().addAll(danmuList);
|
||||
danmus.setDanmuCount(count);
|
||||
if (page < pageCount) {
|
||||
danmus.setNextDanmu(true);
|
||||
}
|
||||
|
||||
|
||||
for (LiveSuperChatDatabaseBean bean : superChatList) {
|
||||
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean);
|
||||
danmus.getSuperChat().add(superChat);
|
||||
@@ -117,7 +129,7 @@ public class LiveDanmuService {
|
||||
danmu.setText(bean.getDanmu());
|
||||
danmu.setColor("#" + bean.getFontColor());
|
||||
danmu.setFontSize(bean.getFontSize());
|
||||
danmu.setTime(bean.getTime() - startTime);
|
||||
danmu.setTime(bean.getTime().getTime() - startTime);
|
||||
if (bean.getModel() < 4) {
|
||||
danmu.setBarrageType(LiveVideoDanmu.Danmu.DANMU_TYPE_SCROLL);
|
||||
} else if (bean.getModel() == 4) {
|
||||
|
||||
@@ -18,11 +18,9 @@ import com.yutou.biliapi.enums.LiveVideoCodec;
|
||||
import com.yutou.biliapi.enums.LiveVideoDefinition;
|
||||
import com.yutou.biliapi.enums.LiveVideoFormat;
|
||||
import com.yutou.biliapi.net.BiliLiveNetApiManager;
|
||||
import com.yutou.biliapi.net.WebSignManager;
|
||||
import com.yutou.biliapi.net.WebSocketClientManager;
|
||||
import com.yutou.bilibili.Tools.DateFormatUtils;
|
||||
import com.yutou.bilibili.Tools.FileServerUtils;
|
||||
import com.yutou.bilibili.Tools.LiveInfoNfoTools;
|
||||
import com.yutou.bilibili.Tools.ProcessUtils;
|
||||
import com.yutou.bilibili.datas.VideoFilePath;
|
||||
import com.yutou.bilibili.interfaces.DownloadInterface;
|
||||
import com.yutou.common.okhttp.HttpCallback;
|
||||
@@ -32,13 +30,14 @@ import com.yutou.common.utils.ConfigTools;
|
||||
import com.yutou.common.utils.FFmpegUtils;
|
||||
import com.yutou.common.utils.Log;
|
||||
import okhttp3.Headers;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -65,16 +64,16 @@ public class LiveVideoDownloadService {
|
||||
}
|
||||
|
||||
public void start(LiveConfigDatabaseBean bean, boolean isUser) {
|
||||
if (!isUser && userStopList.contains(bean.getRoomId().toString())) {
|
||||
if (!isUser && userStopList.contains(bean.getRoomId())) {
|
||||
return;
|
||||
}
|
||||
if (isUser) {
|
||||
userStopList.remove(bean.getRoomId().toString());
|
||||
userStopList.remove(bean.getRoomId());
|
||||
}
|
||||
if (videoRecord.check(bean.getRoomId().toString())) {
|
||||
if (videoRecord.check(bean.getRoomId())) {
|
||||
return;
|
||||
}
|
||||
BiliLiveNetApiManager.getInstance().getApi(bean.getRecordUid()).getRoomInfo(bean.getRoomId().toString()).enqueue(new HttpCallback<LiveRoomInfo>() {
|
||||
BiliLiveNetApiManager.getInstance().getApi(bean.getRecordUid()).getRoomInfo(bean.getRoomId()).enqueue(new HttpCallback<LiveRoomInfo>() {
|
||||
@Override
|
||||
public void onResponse(Headers headers, int code, String status, LiveRoomInfo response, String rawResponse) {
|
||||
if (response.getLiveStatus() == 1) {
|
||||
@@ -178,20 +177,9 @@ public class LiveVideoDownloadService {
|
||||
config.setRoomInfo(roomInfo);
|
||||
config.setRootPath(bean.getRecordPath());
|
||||
database = new BiliLiveDatabase(config);
|
||||
try {
|
||||
var keyframe = roomInfo.getKeyframe();
|
||||
if (!StringUtils.hasText(keyframe)) {
|
||||
keyframe = roomInfo.getUserCover();
|
||||
}
|
||||
HttpDownloadUtils.download(new HttpDownloadUtils.Builder().setUrl(keyframe)
|
||||
.setPath(rootPath.getAbsolutePath())
|
||||
.setFileName("poster.jpg"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
saveLiveInfo(roomInfo);
|
||||
api.getLiveRoomPlayInfo(
|
||||
bean.getRoomId().toString(),
|
||||
bean.getRoomId(),
|
||||
LiveProtocol.getAll(),
|
||||
LiveVideoFormat.getAll(),
|
||||
LiveVideoCodec.getAll(),
|
||||
@@ -285,7 +273,7 @@ public class LiveVideoDownloadService {
|
||||
// .withNotSymbolParam("-loglevel", "error")
|
||||
// .withNotSymbolParam("-progress", "-")
|
||||
// .withNotSymbolParam("-fflags", "+genpts")
|
||||
.withNotSymbolParam("-threads", "8")
|
||||
// .withNotSymbolParam("-threads", "8")//看bili-go也没有加这个,改成设置好了
|
||||
// .withNotSymbolParam("-bufsize", "10M")
|
||||
.withNotSymbolParam("-f", "segment")
|
||||
.withNotSymbolParam("-segment_time", "60")
|
||||
@@ -301,7 +289,7 @@ public class LiveVideoDownloadService {
|
||||
if (ck != null) {
|
||||
// builder = builder.withParam("-cookies", cookie);
|
||||
}
|
||||
FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath.replace(".m3u8","-%04d.ts"));
|
||||
FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath.replace(".m3u8", "-%04d.ts"));
|
||||
Log.i(command.getCommandDecode());
|
||||
try {
|
||||
command.start(new DownloadInterface() {
|
||||
@@ -316,6 +304,7 @@ public class LiveVideoDownloadService {
|
||||
VideoTask.this.onStart();
|
||||
Log.i("启动录制:" + playInfo.getRoomId());
|
||||
task = null;
|
||||
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
@@ -333,11 +322,18 @@ public class LiveVideoDownloadService {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
try {
|
||||
FileUtils.deleteDirectory(rootPath);
|
||||
} catch (IOException e) {
|
||||
Log.i(rootPath.getAbsolutePath());
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
if (videoDatabaseBean != null) {
|
||||
videoDatabaseBean.setStopTime(new Date());
|
||||
database.addLiveInfo(videoDatabaseBean);
|
||||
}
|
||||
stopRecordDanmu();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -353,8 +349,21 @@ public class LiveVideoDownloadService {
|
||||
videoDatabaseBean.setRoomInfoJson(JSONObject.toJSONString(roomInfo));
|
||||
videoDatabaseBean.setStartTime(new Date());
|
||||
database.addLiveInfo(videoDatabaseBean);
|
||||
recordDanmu();
|
||||
// LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo"));
|
||||
}
|
||||
|
||||
//录制弹幕
|
||||
private void recordDanmu() {
|
||||
if (bean.isSyncDanmuForLive() && !WebSocketClientManager.getInstance().checkRoom(LiveRoomConfig.buildConfig(bean.getRoomId()))) {
|
||||
WebSocketClientManager.getInstance().addRoom(LiveRoomConfig.buildConfig(bean.getRoomId()), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopRecordDanmu() {
|
||||
if (bean.isSyncDanmuForLive() && WebSocketClientManager.getInstance().checkRoom(LiveRoomConfig.buildConfig(bean.getRoomId()))) {
|
||||
WebSocketClientManager.getInstance().stopRoom(bean.getRoomId(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,12 +54,20 @@ public class SystemService {
|
||||
}
|
||||
for (LiveConfigDatabaseBean bean : list) {
|
||||
try {
|
||||
if (bean.isRecordDanmu() && bean.checkRecordDanmuTime()) {
|
||||
// 如果bean需要录制弹幕,并且检查录制弹幕时间,并且不需要同步直播弹幕,则录制弹幕
|
||||
if (bean.isRecordDanmu() && bean.checkRecordDanmuTime() && !bean.isSyncDanmuForLive()) {
|
||||
recordDanmu(bean);
|
||||
} else if (!bean.checkRecordDanmuTime()) {
|
||||
} else if (!bean.checkRecordDanmuTime() && !bean.isSyncDanmuForLive()) {
|
||||
// 如果不在录制弹幕时间,并且不需要同步直播弹幕,则停止录制弹幕
|
||||
stopRecordDanmu(bean);
|
||||
}
|
||||
// 如果bean需要录制直播,并且检查录制直播时间
|
||||
if (bean.isRecordLive() && bean.checkRecordLiveTime()) {
|
||||
// 如果需要同步直播弹幕,则录制弹幕
|
||||
if (bean.isSyncDanmuForLive()) {
|
||||
recordDanmu(bean);
|
||||
}
|
||||
// 录制视频
|
||||
recordVideo(bean);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -83,7 +91,7 @@ public class SystemService {
|
||||
|
||||
// 录制弹幕
|
||||
private void recordDanmu(LiveConfigDatabaseBean bean) {
|
||||
danmuService.start(bean.getRoomId().toString(), false);
|
||||
danmuService.start(bean, false);
|
||||
}
|
||||
|
||||
// 录制视频
|
||||
|
||||
Reference in New Issue
Block a user