完善web一些功能

This commit is contained in:
2024-11-27 17:39:02 +08:00
parent 48a15c8769
commit e8cceef419
12 changed files with 647 additions and 143 deletions

View File

@@ -66,5 +66,9 @@ public interface LiveApi {
@POST("/room/v1/Room/get_status_info_by_uids")
Call<HttpBody<Map<String,LiveAnchorInfo>>> getLiveRoomStatus(@Body
JSONObject uids);
@GET("/xlive/web-ucenter/v1/xfetter/GetWebList")
Call<HttpBody<FollowLive>> getUserFollowLive(
@Query("hit_ab")boolean hit_ab,
@Query("_")long time
);
}

View File

@@ -0,0 +1,107 @@
package com.yutou.biliapi.bean.live;
import com.alibaba.fastjson2.annotation.JSONField;
import com.yutou.common.okhttp.BaseBean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class FollowLive extends BaseBean {
@JSONField(name = "rooms")
List<Room> rooms;
@JSONField(name = "list")
List<Room> list;
@lombok.Data
public static class Room {
@JSONField(name = "title")
private String title;
@JSONField(name = "room_id")
private String roomId;
@JSONField(name = "uid")
private int uid;
@JSONField(name = "online")
private int online;
@JSONField(name = "live_time")
private String liveTime;
@JSONField(name = "live_status")
private int liveStatus;
@JSONField(name = "short_id")
private int shortId;
@JSONField(name = "area")
private int area;
@JSONField(name = "area_name")
private String areaName;
@JSONField(name = "area_v2_id")
private int areaV2Id;
@JSONField(name = "area_v2_name")
private String areaV2Name;
@JSONField(name = "area_v2_parent_name")
private String areaV2ParentName;
@JSONField(name = "area_v2_parent_id")
private int areaV2ParentId;
@JSONField(name = "uname")
private String uname;
@JSONField(name = "face")
private String face;
@JSONField(name = "tag_name")
private String tagName;
@JSONField(name = "tags")
private String tags;
@JSONField(name = "cover_from_user")
private String coverFromUser;
@JSONField(name = "keyframe")
private String keyframe;
@JSONField(name = "lock_till")
private String lockTill;
@JSONField(name = "hidden_till")
private String hiddenTill;
@JSONField(name = "broadcast_type")
private int broadcastType;
@JSONField(name = "is_encrypt")
private boolean isEncrypt;
@JSONField(name = "link")
private String link;
@JSONField(name = "nickname")
private String nickname;
@JSONField(name = "roomname")
private String roomName;
@JSONField(name = "roomid")
private String roomId2;
@JSONField(name = "liveTime")
private long liveTimeLong;
}
}

View File

@@ -2,9 +2,11 @@ package com.yutou.bilibili.Controllers;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.biliapi.bean.live.FollowLive;
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
import com.yutou.biliapi.bean.login.LoginUserDatabaseBean;
import com.yutou.biliapi.bean.user.UserFollowingsBean;
import com.yutou.bilibili.Tools.DateFormatUtils;
import com.yutou.bilibili.Tools.Tools;
import com.yutou.bilibili.datas.ResultData;
import com.yutou.bilibili.datas.ReturnCode;
@@ -17,13 +19,13 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/live/config/")
@@ -46,6 +48,17 @@ public class LiveConfigController {
return ResultData.success(bean, bean.getTotal());
}
@ResponseBody
@RequestMapping("followLive")
public JSONObject getFollowLive(String userId) {
List<FollowLive.Room> followLive = userService.getUserFollowLive(userId);
if (followLive == null) {
return ResultData.fail(ReturnCode.RC999);
}
followLive.forEach(item -> item.setLiveTime(DateFormatUtils.getInstance().convertSeconds(Long.parseLong(item.getLiveTime()))));
return ResultData.success(followLive, followLive.size());
}
@ResponseBody
@RequestMapping("follow/add")
public JSONObject addFollow(String uid, String anchorId) {
@@ -79,7 +92,21 @@ public class LiveConfigController {
follow.setUname(jsonObject.getString("uname"));
return follow;
}).toList();
return ResultData.success(userService.followAll(uid,list));
return ResultData.success(userService.followAll(uid, list));
}
@ResponseBody
@RequestMapping("follow/roomId/addList")
public JSONObject addFollowListToRoomId(String array) {
if (!StringUtils.hasText(array)) {
return ResultData.fail(ReturnCode.RC500);
}
JSONArray jsonArray = JSONArray.parseArray(array);
List<LiveConfigDatabaseBean> list = jsonArray.stream().map(o -> {
JSONObject jsonObject = (JSONObject) o;
return configService.addConfig(jsonObject.getString("roomId"), new LiveConfigDatabaseBean());
}).toList();
return ResultData.success(list, list.size());
}
@ResponseBody
@@ -110,6 +137,41 @@ public class LiveConfigController {
return ResultData.success(ReturnCode.RC100);
}
@RequestMapping(value = "set/array", method = RequestMethod.POST)
@ResponseBody
public JSONObject addArrayConfig(@RequestBody JSONObject jsonObject) {
LiveConfigDatabaseBean bean = jsonObject.getJSONObject("config").to(LiveConfigDatabaseBean.class);
if (!bean.verifyLiveTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "视频录制时间格式错误");
}
if (!bean.verifyDanmuTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "弹幕录制时间格式错误");
}
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();
return ResultData.success("成功配置" + (list.size() - countNull) + "个直播间");
}
@RequestMapping(value = "delete/array", method = RequestMethod.POST)
@ResponseBody
public JSONObject deleteArrayConfig(@RequestBody JSONArray jsonArray) {
List<Boolean> list = jsonArray.stream().map(roomId -> configService.deleteConfig(roomId.toString())).toList();
int countNull = list.stream().filter(it -> !it).toList().size();
return ResultData.success("成功删除" + (list.size() - countNull) + "个直播间");
}
@RequestMapping(value = "delete/all", method = RequestMethod.GET)
@ResponseBody
public JSONObject deleteAllConfig() {
for (LiveConfigDatabaseBean bean : configService.getAllConfig()) {
configService.deleteConfig(bean.getRoomId());
}
if(configService.getAllConfig().isEmpty()) {
return ResultData.success("成功删除");
}else{
return ResultData.fail(-1,"删除失败,剩余:"+configService.getAllConfig().size()+"个直播间");
}
}
@RequestMapping(value = "set", method = RequestMethod.POST)
@ResponseBody

View File

@@ -76,6 +76,17 @@ public class DateFormatUtils {
Date time = parse(date, format);
return format(time, format);
}
public String convertSeconds(long totalSeconds) {
// 计算总小时数
long hours = totalSeconds / 3600;
// 剩余的秒数
long remainingSecondsAfterHours = totalSeconds % 3600;
// 计算分钟数
long minutes = remainingSecondsAfterHours / 60;
// 最后剩余的秒数
long seconds = remainingSecondsAfterHours % 60;
return String.format("%d小时%d分%d秒", hours, minutes, seconds);
}
public String formatMillis(long millis) {
Duration duration = Duration.ofMillis(millis);
int seconds = (int) (duration.getSeconds() % 60);

View File

@@ -1,7 +1,7 @@
package com.yutou.bilibili.services;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.biliapi.api.UserApi;
import com.yutou.biliapi.bean.live.FollowLive;
import com.yutou.biliapi.bean.live.SpiBean;
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
@@ -9,7 +9,7 @@ import com.yutou.biliapi.bean.user.UserFollowingsBean;
import com.yutou.biliapi.bean.user.UserHomeInfoBean;
import com.yutou.biliapi.bean.user.UserInfoBean;
import com.yutou.biliapi.databases.BiliBiliLoginDatabase;
import com.yutou.biliapi.net.BiliCookieManager;
import com.yutou.biliapi.net.BiliLiveNetApiManager;
import com.yutou.biliapi.net.BiliUserNetApiManager;
import com.yutou.biliapi.net.WebSignManager;
import com.yutou.bilibili.datas.ResultData;
@@ -34,6 +34,14 @@ public class LiveUserService {
@Resource
LiveConfigService configService;
public List<FollowLive.Room> getUserFollowLive(String userId) {
try {
FollowLive followLive = BiliLiveNetApiManager.getInstance().getApi(userId).getUserFollowLive(true, System.currentTimeMillis()).execute().body().getData();
return followLive.getRooms();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public UserFollowingsBean getUserFollowings(String userId, int page, int num) {
LoginCookieDatabaseBean cookie = userLoginService.getCookie(userId);
UserApi api = BiliUserNetApiManager.getInstance().getUserApi(cookie);