Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
fixed page offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ha2ryZhang committed May 14, 2020
1 parent cb01e4b commit 905d33f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ docker run --rm -it -d --name alltv -p 8888:8888 harryzhang6/alltv
- [ ] 增加其他平台获取弹幕(websocket)

### AllTV app(努力中)别忘了点star哦
![testwebsocket](./images/alltv.jpeg)
![alltv_flutter](./images/alltv.jpeg)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@Api(tags = "综合各个平台")
Expand All @@ -19,7 +20,8 @@ public TopController(DouYuService douYuService) {
}
@GetMapping("live/{cid}")
public Result<List<LiveRoom>> getTopRooms(@PathVariable("cid") String cid, @RequestParam(defaultValue = "0") Integer pageNum){
List<LiveRoom> rooms = douYuService.getTopRoomsByCid(cid, 10, pageNum);
List<LiveRoom> rooms = douYuService.getTopRoomsByCid(cid, 20, pageNum);
Collections.sort(rooms);
return Result.success(rooms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum BilibiliOpenApi {
//统一后面+roomId
SERVER_CONFIG("https://api.live.bilibili.com/room/v1/Danmu/getConf?id="),
ROOM_INIT("https://api.live.bilibili.com/room/v1/Room/room_init?id="),
PLAY_URL("https://api.live.bilibili.com/room/v1/Room/playUrl?cid=")
PLAY_URL("https://api.live.bilibili.com/room/v1/Room/playUrl?cid="),
RANK("https://api.live.bilibili.com/room/v1/RoomRecommend/biliIndexRecList")
;

private String url;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/debugers/alltv/model/LiveRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Date;

@Data
public class LiveRoom {
public class LiveRoom implements Comparable<LiveRoom> {
private String roomId;
private String com;//哪个平台
private String cateId;
Expand All @@ -18,4 +18,9 @@ public class LiveRoom {
private String avatar;
private Long online; //热度
private String realUrl; //真是直播地址

@Override
public int compareTo(LiveRoom room) {
return (int) (room.getOnline()-online);
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/debugers/alltv/service/DouYuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,17 @@ public DouYuDTO getRoomInfo(String roomId) {
return getDTO(response.getBodyJson());
}

/**
* 获取斗鱼推荐直播间
*
* @param cid 分类id
* @param pageSize 页数大小
* @param pageNum 页数
* @return liveRoom
*/
public List<LiveRoom> getTopRoomsByCid(String cid, Integer pageSize, Integer pageNum) {
HttpResponse response = HttpRequest.create(DouYuOpenApi.TOP_ROOM + cid)
.appendParameter("offset", pageNum)
.appendParameter("offset", (pageNum - 1) * pageSize)
.appendParameter("limit", pageSize)
.setContentType(HttpContentType.FORM).get();
if (404 == response.getCode())
Expand All @@ -221,7 +229,6 @@ private LiveRoom convertToLiveRoom(DouYuDTO douYuDTO) {
liveRoom.setCom("douyu");
return liveRoom;
}

private DouYuDTO getDTO(JSONObject jsonObject) {
JSONObject data = jsonObject.getJSONObject("data");
DouYuDTO douYuDTO = new DouYuDTO();
Expand Down

0 comments on commit 905d33f

Please sign in to comment.