add 视频页面
update 用户管理
This commit is contained in:
@@ -12,6 +12,7 @@ import com.yutou.biliapi.net.BiliCookieManager;
|
||||
import com.yutou.biliapi.net.BiliLoginNetApiManager;
|
||||
import com.yutou.biliapi.net.BiliUserNetApiManager;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.datas.ReturnCode;
|
||||
import com.yutou.bilibili.services.LiveLoginService;
|
||||
import com.yutou.common.okhttp.HttpBody;
|
||||
import com.yutou.common.okhttp.HttpCallback;
|
||||
@@ -49,14 +50,14 @@ public class BiliUserController {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("uid", bean.getUserInfo().getMid());
|
||||
json.put("uname", bean.getUserInfo().getUname());
|
||||
json.put("face",bean.getUserInfo().getFace());
|
||||
json.put("sql_time",bean.getSql_time());
|
||||
json.put("face", bean.getUserInfo().getFace());
|
||||
json.put("sql_time", bean.getSql_time());
|
||||
try {
|
||||
CheckCookieBean cookie = api.checkCookie().execute().body().getData();
|
||||
if (cookie == null) {
|
||||
json.put("status", "无效");
|
||||
} else {
|
||||
json.put("status", cookie.isRefresh()?"待刷新":"正常");
|
||||
json.put("status", cookie.isRefresh() ? "待刷新" : "正常");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(e);
|
||||
@@ -72,11 +73,23 @@ public class BiliUserController {
|
||||
public JSONObject login(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
Object loginToken = session.getAttribute("loginToken");
|
||||
ReturnCode returnCode;
|
||||
if (loginToken == null) {
|
||||
loginToken = UUID.randomUUID().toString();
|
||||
returnCode = ReturnCode.RC301;
|
||||
session.setAttribute("loginToken", loginToken);
|
||||
return ResultData.success(loginToken.toString(), -1, returnCode);
|
||||
} else {
|
||||
returnCode = ReturnCode.RC300;
|
||||
}
|
||||
return ResultData.success(login(loginToken.toString()));
|
||||
JSONObject login = login(loginToken.toString());
|
||||
if (login != null && login.containsKey("qrcode")) {
|
||||
return ResultData.success(login, -1, returnCode);
|
||||
} else if (login != null) {
|
||||
return ResultData.success(ReturnCode.RC302);
|
||||
}
|
||||
returnCode = ReturnCode.RC301;
|
||||
return ResultData.success(loginToken.toString(), -1, returnCode);
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +125,7 @@ public class BiliUserController {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
RedisTools.set(loginToken, json.toString(), 60 * 60);
|
||||
RedisTools.set(loginToken, json.toString(), 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +137,7 @@ public class BiliUserController {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LiveLoginService loginService = new LiveLoginService();
|
||||
// LiveLoginService loginService = new LiveLoginService();
|
||||
/* List<LoginUserDatabaseBean> allUser = loginService.getAllUser();
|
||||
for (LoginUserDatabaseBean user : allUser) {
|
||||
System.out.println(user.getUserInfo().getMid());
|
||||
@@ -141,7 +154,9 @@ public class BiliUserController {
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
HttpLoggingInterceptor.setLog(true);
|
||||
BiliCookieManager.resetCookie(loginService.getCookie("96300"));
|
||||
// HttpLoggingInterceptor.setLog(true);
|
||||
// BiliCookieManager.resetCookie(loginService.getCookie("3493115839121644"));
|
||||
RedisTools.set("test", "test", 10000);
|
||||
System.out.println(RedisTools.get("test"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class LiveDanmuController {
|
||||
@ResponseBody
|
||||
@RequestMapping("/live/danmu/stop")
|
||||
public JSONObject stopLiveDanmu(String roomId) {
|
||||
service.stop(roomId,true);
|
||||
service.stop(roomId, true);
|
||||
return ResultData.success(ReturnCode.RC100);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,10 @@ public class LiveDanmuController {
|
||||
public JSONObject getDanmuList(String roomId) {
|
||||
return ResultData.success(ReturnCode.RC100);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/live/danmu/get")
|
||||
public JSONObject getDanmu(String roomId,String videoId,String startTimer,long step) {
|
||||
return ResultData.success(ReturnCode.RC100);
|
||||
public JSONObject getDanmu(String roomId, String videoId) {
|
||||
return ResultData.success(service.getDanmu(roomId, videoId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,14 @@ public class ResultData<T> {
|
||||
public static <T> JSONObject success(T data) {
|
||||
return success(data, -1);
|
||||
}
|
||||
|
||||
public static <T> JSONObject success(T data, int count) {
|
||||
return success(data, count, ReturnCode.RC100);
|
||||
}
|
||||
|
||||
public static <T> JSONObject success(T data, int count,ReturnCode returnCode) {
|
||||
ResultData<T> resultData = new ResultData<>();
|
||||
resultData.setStatus(ReturnCode.RC100.getCode());
|
||||
resultData.setMessage(ReturnCode.RC100.getMessage());
|
||||
resultData.setStatus(returnCode.getCode());
|
||||
resultData.setMessage(returnCode.getMessage());
|
||||
resultData.setData(data);
|
||||
if (data instanceof Collection<?>) {
|
||||
resultData.count = ((Collection<?>) data).size();
|
||||
|
||||
@@ -24,6 +24,13 @@ public enum ReturnCode {
|
||||
RC401(401,"匿名用户访问无权限资源时的异常"),
|
||||
/**服务异常**/
|
||||
RC500(500,"系统异常,请稍后重试"),
|
||||
/**B站扫码**/
|
||||
RC300(300,"获取二维码成功"),
|
||||
/**B站扫码**/
|
||||
RC301(301,"扫码中"),
|
||||
/**B站扫码登陆成功**/
|
||||
RC302(302,"登录成功"),
|
||||
RC303(303,"登录失败"),
|
||||
|
||||
INVALID_TOKEN(2001,"访问令牌不合法"),
|
||||
ACCESS_DENIED(2003,"没有权限访问该资源"),
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.yutou.bilibili.datas.web;
|
||||
|
||||
import com.yutou.biliapi.bean.live.database.LiveSuperChatDatabaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class LiveVideoDanmu {
|
||||
|
||||
List<Danmu> danmu = new ArrayList<>();
|
||||
List<SuperChat> superChat = new ArrayList<>();
|
||||
|
||||
|
||||
@Data
|
||||
public static class Addition {
|
||||
private int grade = 2;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Danmu {
|
||||
public static final String DANMU_TYPE_SCROLL = "scroll";
|
||||
public static final String DANMU_TYPE_TOP = "top";
|
||||
public static final String DANMU_TYPE_BOTTOM = "bottom";
|
||||
private String id;
|
||||
private String barrageType = DANMU_TYPE_SCROLL;
|
||||
private long time;
|
||||
private String text;
|
||||
private int fontSize = 25;
|
||||
private int lineHeight = 1;
|
||||
private String color = "#ffffff";
|
||||
private Addition addition = new Addition();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SuperChat {
|
||||
private int id;
|
||||
private long price;
|
||||
private String uid;
|
||||
private long start_time;
|
||||
private long duration;
|
||||
private String message;
|
||||
private String message_trans;
|
||||
private String message_font_color;
|
||||
private String backgroundBottomColor;
|
||||
private String userName;
|
||||
private String userNameColor;
|
||||
private String userAvatar;
|
||||
|
||||
public SuperChat(long videoTime, LiveSuperChatDatabaseBean bean) {
|
||||
this.id = bean.getId();
|
||||
this.price = bean.getPrice();
|
||||
this.uid = bean.getUid();
|
||||
this.start_time = (bean.getSql_time().getTime() - videoTime) / 1000;
|
||||
this.duration = bean.getEnd_time() - bean.getStart_time();
|
||||
this.message = bean.getMessage();
|
||||
this.message_trans = bean.getMessage_trans();
|
||||
this.message_font_color = bean.getMessage_font_color();
|
||||
this.backgroundBottomColor = bean.getBackgroundBottomColor();
|
||||
this.userName = bean.getUserName();
|
||||
this.userAvatar = bean.getUserAvatar();
|
||||
this.userNameColor=bean.getUserNameColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
||||
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
|
||||
import com.yutou.biliapi.bean.live.database.LiveDanmuDatabaseBean;
|
||||
import com.yutou.biliapi.bean.live.database.LiveSuperChatDatabaseBean;
|
||||
import com.yutou.biliapi.bean.live.database.LiveVideoDatabaseBean;
|
||||
import com.yutou.biliapi.bean.websocket.live.WSData;
|
||||
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
||||
@@ -13,39 +14,44 @@ import com.yutou.biliapi.net.WebSocketManager;
|
||||
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) {
|
||||
public void start(String roomId, boolean isUser) {
|
||||
WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), isUser);
|
||||
}
|
||||
|
||||
public boolean check(String roomId) {
|
||||
LiveRoomConfig roomConfig = new LiveRoomConfig();
|
||||
roomConfig.setRoomId(roomId);
|
||||
return WebSocketManager.getInstance().checkRoom(roomConfig);
|
||||
}
|
||||
|
||||
public void stop(String roomId,boolean isUser) {
|
||||
public void stop(String roomId, boolean isUser) {
|
||||
WebSocketManager.getInstance().stopRoom(roomId, isUser);
|
||||
}
|
||||
|
||||
public JSONArray getLiveRoomList() {
|
||||
return WebSocketManager.getInstance().getLiveRoomList();
|
||||
}
|
||||
public void clearUserList(){
|
||||
|
||||
public void clearUserList() {
|
||||
WebSocketManager.getInstance().clearUserStopList();
|
||||
}
|
||||
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
BiliLiveConfigDatabase configDatabase=new BiliLiveConfigDatabase();
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
|
||||
LiveConfigDatabaseBean bean = configDatabase.getConfig(roomId);
|
||||
configDatabase.close();
|
||||
return Tools.scanFile(new File(bean.getRecordPath() + File.separator + bean.getAnchorName()));
|
||||
@@ -77,8 +83,62 @@ public class LiveDanmuService {
|
||||
return String.format("%d小时%d分钟%d秒", hours, minutes, finalRemainingSeconds);
|
||||
}
|
||||
|
||||
public LiveVideoDanmu getDanmu(String roomId, String videoId) {
|
||||
LiveVideoDanmu danmus = new LiveVideoDanmu();
|
||||
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId));
|
||||
LiveVideoDatabaseBean videoBean = null;
|
||||
for (LiveVideoDatabaseBean info : liveDatabase.getLiveInfos()) {
|
||||
System.out.println(videoId + " " + info.getSql_time().getTime());
|
||||
if (videoId.trim().equals(String.valueOf(info.getSql_time().getTime()))) {
|
||||
videoBean = info;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (videoBean == null) {
|
||||
return new LiveVideoDanmu();
|
||||
}
|
||||
File videoFile = new File(videoBean.getPath().replace(".flv", ".mp4"));
|
||||
if (!videoFile.exists()) {
|
||||
videoFile = new File(videoBean.getPath());
|
||||
}
|
||||
long videoTime = FFmpegUtils.getVideoTime(videoFile);
|
||||
long startTime = Long.parseLong(videoId);
|
||||
long endTime = Long.parseLong(videoId) + videoTime;
|
||||
List<LiveDanmuDatabaseBean> danmuList = liveDatabase.getOfTime(DateFormatUtils.format(startTime), DateFormatUtils.format(endTime), LiveDanmuDatabaseBean.class);
|
||||
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(DateFormatUtils.format(startTime), DateFormatUtils.format(endTime), LiveSuperChatDatabaseBean.class);
|
||||
for (LiveDanmuDatabaseBean bean : danmuList) {
|
||||
LiveVideoDanmu.Danmu danmu = createDanmu(bean, startTime);
|
||||
danmus.getDanmu().add(danmu);
|
||||
}
|
||||
for (LiveSuperChatDatabaseBean bean : superChatList) {
|
||||
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime,bean);
|
||||
danmus.getSuperChat().add(superChat);
|
||||
}
|
||||
|
||||
liveDatabase.close();
|
||||
return danmus;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static LiveVideoDanmu.Danmu createDanmu(LiveDanmuDatabaseBean bean, long startTime) {
|
||||
LiveVideoDanmu.Danmu danmu = new LiveVideoDanmu.Danmu();
|
||||
danmu.setId(bean.getId() + "");
|
||||
danmu.setText(bean.getDanmu());
|
||||
danmu.setColor("#" + bean.getFontColor());
|
||||
danmu.setFontSize(bean.getFontSize());
|
||||
danmu.setTime(bean.getTime() - startTime);
|
||||
if (bean.getModel() < 4) {
|
||||
danmu.setBarrageType(LiveVideoDanmu.Danmu.DANMU_TYPE_SCROLL);
|
||||
} else if (bean.getModel() == 4) {
|
||||
danmu.setBarrageType(LiveVideoDanmu.Danmu.DANMU_TYPE_BOTTOM);
|
||||
} else if (bean.getModel() == 5) {
|
||||
danmu.setBarrageType(LiveVideoDanmu.Danmu.DANMU_TYPE_TOP);
|
||||
}
|
||||
return danmu;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLiveDatabase database = new BiliLiveDatabase(LiveRoomConfig.buildConfig("17961"));
|
||||
BiliLiveDatabase database = new BiliLiveDatabase(LiveRoomConfig.buildConfig("17961"));
|
||||
for (LiveVideoDatabaseBean info : database.getLiveInfos()) {
|
||||
System.out.println(info);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yutou.bilibili.services;
|
||||
|
||||
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
||||
import com.yutou.biliapi.bean.live.database.LiveDanmuDatabaseBean;
|
||||
import com.yutou.biliapi.bean.live.database.LiveVideoDatabaseBean;
|
||||
import com.yutou.biliapi.databases.BiliLiveDatabase;
|
||||
import com.yutou.bilibili.datas.web.LiveVideoDanmu;
|
||||
import com.yutou.common.utils.FFmpegUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LiveVideoDanmuService {
|
||||
|
||||
|
||||
}
|
||||
@@ -376,7 +376,11 @@ public class LiveVideoDownloadService {
|
||||
}
|
||||
liveDatabase.close();
|
||||
if(videoInfo != null) {
|
||||
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, new File(videoInfo.getPath()), ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
|
||||
File videoFile = new File(videoInfo.getPath().replace(".flv", ".mp4"));
|
||||
if(!videoFile.exists()){
|
||||
videoFile=new File(videoInfo.getPath());
|
||||
}
|
||||
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath,videoFile , ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
|
||||
System.out.println(ffmpeg.getCommand());
|
||||
ffmpeg.start(new DownloadInterface() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user