增加弹幕推送数据包 ROOM_RANK

This commit is contained in:
czp3009 2018-05-24 16:32:05 +08:00
parent 31b1762ebb
commit ad2aabb7fb
6 changed files with 125 additions and 6 deletions

View File

@ -13,7 +13,7 @@
# 添加依赖
## Gradle
compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.13'
compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.14'
# 名词解释
B站不少参数都是瞎取的, 并且不统一, 经常混用, 以下给出一些常见参数对应的含义
@ -335,6 +335,7 @@ API 文档
| RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 |
| RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 |
| RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 |
| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 |
| RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 |
| RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 |
| RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 |

View File

@ -1,5 +1,5 @@
group = 'com.hiczp'
version = '0.0.13'
version = '0.0.14'
description = 'Bilibili android client API library written in Java'
apply plugin: 'idea'
@ -19,13 +19,13 @@ dependencies {
// https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson
compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.4.0'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.4'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
// https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor
compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.10.0'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// https://mvnrepository.com/artifact/io.netty/netty-all
compile group: 'io.netty', name: 'netty-all', version: '4.1.24.Final'
compile group: 'io.netty', name: 'netty-all', version: '4.1.25.Final'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '25.0-jre'
}

View File

@ -0,0 +1,10 @@
{
"cmd": "ROOM_RANK",
"data": {
"roomid": 1241012,
"rank_desc": "小时榜 182",
"color": "#FB7299",
"h5_url": "https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid\u003d35577726",
"timestamp": 1527148082
}
}

View File

@ -0,0 +1,92 @@
package com.hiczp.bilibili.api.live.socket.entity;
import com.google.gson.annotations.SerializedName;
public class RoomRankEntity implements DataEntity {
/**
* cmd : ROOM_RANK
* data : {"roomid":1241012,"rank_desc":"小时榜 182","color":"#FB7299","h5_url":"https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid=35577726","timestamp":1527148082}
*/
@SerializedName("cmd")
private String cmd;
@SerializedName("data")
private Data data;
public String getCmd() {
return cmd;
}
public void setCmd(String cmd) {
this.cmd = cmd;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public static class Data {
/**
* roomid : 1241012
* rank_desc : 小时榜 182
* color : #FB7299
* h5_url : https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid=35577726
* timestamp : 1527148082
*/
@SerializedName("roomid")
private long roomId;
@SerializedName("rank_desc")
private String rankDescription;
@SerializedName("color")
private String color;
@SerializedName("h5_url")
private String h5Url;
@SerializedName("timestamp")
private long timestamp;
public long getRoomId() {
return roomId;
}
public void setRoomId(long roomId) {
this.roomId = roomId;
}
public String getRankDescription() {
return rankDescription;
}
public void setRankDescription(String rankDescription) {
this.rankDescription = rankDescription;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getH5Url() {
return h5Url;
}
public void setH5Url(String h5Url) {
this.h5Url = h5Url;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
}

View File

@ -0,0 +1,10 @@
package com.hiczp.bilibili.api.live.socket.event;
import com.hiczp.bilibili.api.live.socket.LiveClient;
import com.hiczp.bilibili.api.live.socket.entity.RoomRankEntity;
public class RoomRankPackageEvent extends ReceiveDataPackageEvent<RoomRankEntity> {
public RoomRankPackageEvent(LiveClient source, RoomRankEntity entity) {
super(source, entity);
}
}

View File

@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@ -68,11 +69,12 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
JsonObject jsonObject;
String cmd;
try {
jsonObject = JSON_PARSER.parse(new InputStreamReader(new ByteArrayInputStream(msg.getContent())))
//强制使用 UTF-8, 避免在 NT 平台可能出现的乱码问题
jsonObject = JSON_PARSER.parse(new InputStreamReader(new ByteArrayInputStream(msg.getContent()), StandardCharsets.UTF_8))
.getAsJsonObject();
cmd = jsonObject.get("cmd").getAsString();
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) {
LOGGER.error("Receive invalid json: \n{}", new String(msg.getContent()));
LOGGER.error("Receive invalid json: \n{}", new String(msg.getContent(), StandardCharsets.UTF_8));
e.printStackTrace();
break;
}
@ -171,6 +173,10 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
eventCreationExpression = () -> new TVEndPackageEvent(liveClient, GSON.fromJson(jsonObject, TVEndEntity.class));
}
break;
case "ROOM_RANK": {
eventCreationExpression = () -> new RoomRankPackageEvent(liveClient, GSON.fromJson(jsonObject, RoomRankEntity.class));
}
break;
//欢迎(活动)
case "WELCOME_ACTIVITY": {
eventCreationExpression = () -> new WelcomeActivityPackageEvent(liveClient, GSON.fromJson(jsonObject, WelcomeActivityEntity.class));