add 视频页面
update 用户管理
This commit is contained in:
@@ -33,9 +33,9 @@ public interface LoginApi {
|
||||
Call<FileBody<String>> getCorrespond(@Path("correspondPath") String correspondPath);
|
||||
|
||||
@GET("/x/passport-login/web/cookie/refresh")
|
||||
Call<HttpBody<LoginInfoBean>> refreshCookie(@Query("csrf") String csrf
|
||||
Call<HttpBody<LoginInfoBean>> refreshCookie(@Query("csrf") String bili_jct
|
||||
, @Query("refresh_csrf") String refresh_csrf
|
||||
, @Query("source") String source
|
||||
, @Query("refresh_token") String ac_time_value
|
||||
, @Query("refresh_token") String refresh_token
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ public class LiveSuperChatDatabaseBean extends AbsDatabasesBean {
|
||||
private String message_trans;
|
||||
@JSONField(name = "message_font_color")
|
||||
private String message_font_color;
|
||||
@JSONField(name = "background_bottom_color")
|
||||
private String backgroundBottomColor;
|
||||
@JSONField(name = "user_name_color")
|
||||
private String userNameColor;
|
||||
@JSONField(name ="user_name")
|
||||
private String userName;
|
||||
@JSONField(name ="user_avatar")
|
||||
@@ -40,9 +44,13 @@ public class LiveSuperChatDatabaseBean extends AbsDatabasesBean {
|
||||
uid = bean.getUid();
|
||||
start_time = bean.getStart_time();
|
||||
end_time = bean.getEnd_time();
|
||||
userName= bean.getUserName();
|
||||
userAvatar = bean.getUserAvatar();
|
||||
message = bean.getMessage();
|
||||
message_trans = bean.getMessage_trans();
|
||||
message_font_color = bean.getMessage_font_color();
|
||||
backgroundBottomColor=bean.getBackground_bottom_color();
|
||||
userNameColor=bean.getUserNameColor();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ public class WSSuperChatMessage extends WSData{
|
||||
private String message_trans;
|
||||
private String message_font_color;
|
||||
private String userName;
|
||||
private String userNameColor;
|
||||
private String userAvatar;
|
||||
private String background_bottom_color;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -42,5 +45,7 @@ public class WSSuperChatMessage extends WSData{
|
||||
setMessage_font_color(data.getString("message_font_color"));
|
||||
setUserName(data.getJSONObject("user_info").getString("uname"));
|
||||
setUserAvatar(data.getJSONObject("user_info").getString("face"));
|
||||
setUserNameColor(data.getJSONObject("user_info").getString("name_color"));
|
||||
setBackground_bottom_color(data.getString("background_bottom_color"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,17 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
public BiliBiliLoginDatabase initData(LoginCookieDatabaseBean cookie, LoginUserDatabaseBean user) {
|
||||
this.cookie = cookie;
|
||||
cookie.setTableName(getDataBean().get(0).getTableName());
|
||||
add(cookie);
|
||||
add(user);
|
||||
LoginCookieDatabaseBean old = getCookie(cookie.getDedeUserID());
|
||||
if (old == null) {
|
||||
add(cookie);
|
||||
add(user);
|
||||
}else{
|
||||
cookie.setSql_time(old.getSql_time());
|
||||
LoginUserDatabaseBean oldUser = getUser(cookie.getDedeUserID());
|
||||
user.setSql_time(oldUser.getSql_time());
|
||||
update(cookie);
|
||||
update(user);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -54,7 +63,8 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
|
||||
return null;
|
||||
}
|
||||
public List<LoginCookieDatabaseBean> getAllCookies(){
|
||||
|
||||
public List<LoginCookieDatabaseBean> getAllCookies() {
|
||||
return super.get(cookie.getTableName(), LoginCookieDatabaseBean.class);
|
||||
}
|
||||
|
||||
@@ -75,7 +85,7 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
JSONArray jsonArray = super.getJSONArray(new LoginUserDatabaseBean(null).getTableName());
|
||||
List<LoginUserDatabaseBean> list = new ArrayList<>();
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject json= (JSONObject) o;
|
||||
JSONObject json = (JSONObject) o;
|
||||
list.add(new LoginUserDatabaseBean(json.to(UserInfoBean.class)));
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -86,21 +86,32 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
}
|
||||
|
||||
private void addData(WSData bean) {
|
||||
addData(bean, null);
|
||||
}
|
||||
|
||||
private void addData(WSData bean, Long saveTime) {
|
||||
AbsDatabasesBean data = null;
|
||||
if (bean instanceof WSDanmuData) {
|
||||
add(new LiveDanmuDatabaseBean((WSDanmuData) bean));
|
||||
data = new LiveDanmuDatabaseBean((WSDanmuData) bean);
|
||||
} else if (bean instanceof WSInteractWord) {
|
||||
add(new LiveInteractWordDatabaseBean((WSInteractWord) bean));
|
||||
data = new LiveInteractWordDatabaseBean((WSInteractWord) bean);
|
||||
} else if (bean instanceof WSSendGift) {
|
||||
add(new LiveGiftDatabaseBean((WSSendGift) bean));
|
||||
data = new LiveGiftDatabaseBean((WSSendGift) bean);
|
||||
} else if (bean instanceof WSSuperChatMessage) {
|
||||
add(new LiveSuperChatDatabaseBean((WSSuperChatMessage) bean));
|
||||
data = new LiveSuperChatDatabaseBean((WSSuperChatMessage) bean);
|
||||
} else if (bean instanceof WSGuardBuy) {
|
||||
add(new LiveGuardBuyBean((WSGuardBuy) bean));
|
||||
data = new LiveGuardBuyBean((WSGuardBuy) bean);
|
||||
}
|
||||
if (saveTime != null && data != null) {
|
||||
data.setSql_time(new Date(saveTime));
|
||||
}
|
||||
if (data != null) {
|
||||
add(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSource(WSData bean) {
|
||||
Log.i("BiliLiveDatabase.addSource",config.getRoomId());
|
||||
Log.i("BiliLiveDatabase.addSource", config.getRoomId());
|
||||
add(new LiveSourceDatabaseBean(bean));
|
||||
addData(bean);
|
||||
}
|
||||
@@ -138,7 +149,8 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
}
|
||||
return super.get(tableName, where, clazz);
|
||||
}
|
||||
public void resetSQL(){
|
||||
|
||||
public void resetSQL() {
|
||||
List<AbsDatabasesBean> list = List.of(
|
||||
new LiveInfoDatabaseBean(),
|
||||
new LiveDanmuDatabaseBean(),
|
||||
@@ -152,16 +164,18 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
}
|
||||
recreateSql(list);
|
||||
}
|
||||
public void resetData(){
|
||||
|
||||
public void resetData() {
|
||||
List<LiveSourceDatabaseBean> list = get(new LiveSourceDatabaseBean().getTableName(), LiveSourceDatabaseBean.class);
|
||||
for (LiveSourceDatabaseBean item : list) {
|
||||
WSData data = WSData.parse(JSONObject.parseObject(item.getJson()));
|
||||
addData(data);
|
||||
addData(data, item.getSql_time().getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("5265"));
|
||||
// biliLiveDatabase.resetSQL();
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("7688602"));
|
||||
biliLiveDatabase.resetSQL();
|
||||
biliLiveDatabase.resetData();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.yutou.biliapi.net;
|
||||
|
||||
import com.yutou.biliapi.api.LoginApi;
|
||||
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
|
||||
import com.yutou.biliapi.bean.login.LoginInfoBean;
|
||||
import com.yutou.common.okhttp.FileBody;
|
||||
import com.yutou.common.okhttp.HttpBody;
|
||||
import com.yutou.common.utils.Log;
|
||||
import com.yutou.common.utils.WebClient;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -73,18 +75,26 @@ public class BiliCookieManager {
|
||||
return htmlContent;
|
||||
}
|
||||
|
||||
public static void resetCookie(LoginCookieDatabaseBean cookie) {
|
||||
public static boolean resetCookie(LoginCookieDatabaseBean cookie) {
|
||||
try {
|
||||
LoginApi api = BiliLoginNetApiManager.getInstance().getLoginApi(cookie.getDedeUserID());
|
||||
String correspondPath = getCorrespondPath(String.format("refresh_%d", System.currentTimeMillis()));
|
||||
System.out.println("correspondPath = " + correspondPath);
|
||||
Response<FileBody<String>> body = api.getCorrespond(correspondPath).execute();
|
||||
if(body.code()==404){
|
||||
return false;
|
||||
}
|
||||
System.out.println("body.code() = " + body.code());
|
||||
String string = IOUtils.toString(body.body().getInputStream(), StandardCharsets.UTF_8);
|
||||
String refreshCsrf = getRefreshCsrf(string);
|
||||
System.out.println("body = " + refreshCsrf);
|
||||
|
||||
Response<HttpBody<LoginInfoBean>> newCookie = api.refreshCookie(cookie.getBiliJct(), refreshCsrf, "main_web", cookie.getRefreshToken()).execute();
|
||||
LoginCookieDatabaseBean nc = BiliLoginNetApiManager.getInstance().getCookie(newCookie.headers(), newCookie.body());
|
||||
nc.setGourl(cookie.getGourl());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,46 +82,48 @@ public class BiliLoginNetApiManager extends BaseApi {
|
||||
|
||||
try {
|
||||
Response<HttpBody<LoginInfoBean>> response = loginApi.loginQRCode(oauthKey).execute();
|
||||
Headers headers = response.headers();
|
||||
HttpBody<LoginInfoBean> httpBody = response.body();
|
||||
if (httpBody.getData().getCode() == 0) {
|
||||
JSONObject ck = new JSONObject();
|
||||
List<String> list = headers.values("set-cookie");
|
||||
for (String cookie : list) {
|
||||
String[] split = cookie.split(";");
|
||||
for (String string : split) {
|
||||
if (!ck.containsKey(string) && StringUtils.hasText(string) && string.contains("=")) {
|
||||
String key = string.split("=")[0].trim();
|
||||
String value = string.split("=")[1].trim();
|
||||
if (key.contains("Expires")) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss z", Locale.ENGLISH);
|
||||
sdf.setTimeZone(TimeZone.getDefault());
|
||||
Date date = sdf.parse(value, new ParsePosition(0));
|
||||
value = String.valueOf(date.getTime() / 1000);
|
||||
}
|
||||
ck.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
ck.put("gourl", bd);
|
||||
LoginCookieDatabaseBean cookie = JSONObject.parseObject(ck.toString(), LoginCookieDatabaseBean.class);
|
||||
cookie.setRefreshToken(httpBody.getData().getRefresh_token());
|
||||
cancel();
|
||||
callback.onResponse(headers, LOGIN_SUCCESS, "ok", cookie, ck.toString());
|
||||
LoginCookieDatabaseBean cookie = getCookie(response.headers(), response.body());
|
||||
if (cookie != null) {
|
||||
cookie.setGourl(bd);
|
||||
cancel();
|
||||
callback.onResponse(response.headers(), LOGIN_SUCCESS, "ok", cookie, JSONObject.toJSONString(cookie));
|
||||
|
||||
} else {
|
||||
callback.onFailure(new RuntimeException("cookie为空"));
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (
|
||||
IOException e) {
|
||||
cancel();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}, 1000, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
public LoginCookieDatabaseBean getCookie(Headers headers, HttpBody<LoginInfoBean> httpBody) {
|
||||
if (httpBody.getData().getCode() == 0) {
|
||||
JSONObject ck = new JSONObject();
|
||||
List<String> list = headers.values("set-cookie");
|
||||
for (String cookie : list) {
|
||||
String[] split = cookie.split(";");
|
||||
for (String string : split) {
|
||||
if (!ck.containsKey(string) && StringUtils.hasText(string) && string.contains("=")) {
|
||||
String key = string.split("=")[0].trim();
|
||||
String value = string.split("=")[1].trim();
|
||||
if (key.contains("Expires")) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss z", Locale.ENGLISH);
|
||||
sdf.setTimeZone(TimeZone.getDefault());
|
||||
Date date = sdf.parse(value, new ParsePosition(0));
|
||||
value = String.valueOf(date.getTime() / 1000);
|
||||
}
|
||||
ck.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LoginCookieDatabaseBean cookie = JSONObject.parseObject(ck.toString(), LoginCookieDatabaseBean.class);
|
||||
cookie.setRefreshToken(httpBody.getData().getRefresh_token());
|
||||
return cookie;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -105,6 +105,7 @@ public class HttpDownloadUtils {
|
||||
.url(builder.url);
|
||||
if (StringUtils.hasText(builder.cookie)) {
|
||||
rb.addHeader("Set-Cookie", builder.cookie);
|
||||
rb.addHeader("Cookie", builder.cookie);
|
||||
}
|
||||
Request request = rb.build();
|
||||
return okHttpClient.newCall(request);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class RedisTools {
|
||||
//Properties properties = PropertyUtil.loadProperties("jedis.properties");
|
||||
//host = properties.getProperty("redis.host");
|
||||
//port = Integer.valueOf(properties.getProperty("redis.port"));
|
||||
host = "127.0.0.1";
|
||||
host = "172.21.35.118";
|
||||
port = 6379;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,12 @@ public class RedisTools {
|
||||
return set(0, key.toString(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @param timeout 过期时间,单位秒
|
||||
*/
|
||||
public static boolean set(String key, String value, int timeout) {
|
||||
try {
|
||||
if (isNotInstallRedis) {
|
||||
|
||||
Reference in New Issue
Block a user