Skip to content

[建议] 可以用 protobuf 来替代手动 parse #1015

@XXXXRT666

Description

@XXXXRT666

此处代码 可以改为如下 protobuf

protobuf
syntax = "proto3";

package danmaku;

message DmColorful {
    DmColorfulType type = 1; // 颜色类型
    string src          = 2; //
}

enum DmColorfulType {
    NoneType        = 0;     // 无
    VipGradualColor = 60001; // 渐变色
}


message DanmakuFlag {
    // 弹幕dmid
    int64 dmid = 1;
    // 评分
    uint32 flag = 2;
}

message DanmakuAIFlag {
    // 弹幕ai云屏蔽条目
    repeated DanmakuFlag dm_flags = 1;
}
message DanmakuSegReply {
  repeated DanmakuElem elems = 1;

  int32 state = 2;
  DanmakuAIFlag ai_flag = 3;
  repeated DmColorful colorfulSrc = 5;
}


message DanmakuElem {
    // 弹幕dmid
    int64 id = 1;
    // 弹幕出现位置(单位ms)
    int32 progress = 2;
    // 弹幕类型 1 2 3:普通弹幕 4:底部弹幕 5:顶部弹幕 6:逆向弹幕 7:高级弹幕 8:代码弹幕 9:BAS弹幕(pool必须为2)
    int32 mode = 3;
    // 弹幕字号
    int32 fontsize = 4;
    // 弹幕颜色
    uint32 color = 5;
    // 发送者mid hash
    string midHash = 6;
    // 弹幕正文
    string content = 7;
    // 发送时间
    int64 ctime = 8;
    // 权重 用于屏蔽等级 区间:[1,10]
    int32 weight = 9;
    // 动作
    string action = 10;
    // 弹幕池 0:普通池 1:字幕池 2:特殊池(代码/BAS弹幕)
    int32 pool = 11;
    // 弹幕dmid str
    string idStr = 12;
    // 弹幕属性位(bin求AND)
    // bit0:保护 bit1:直播 bit2:高赞
    int32 attr = 13;

    int64 uid = 14;
    //
    string animation = 22;
    // 大会员专属颜色
    DmColorfulType colorful = 24;
}

我拉了一个直播回放测试是可以正常parse的, 代码主要参考 bilibili-API-collect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions