aardio 文档

aardio 范例: 入门

//入门
import console;
console.showLoading(" 正在下载 dm.proto");

import protobuf.parser.github;
protobuf.parser.github(false,"SocialSisterYi/bilibili-API-collect/blob/master/grpc_api/bilibili/community/service/dm/v1/dm.proto")
/***
protobuf.parser.github 等价于执行下面的代码:
var proto = web.rest.github.getContent(user,repos,path,branch);
protobuf.parser().parse(proto,,false/*如果应用根目录不是工程目录在应用根目录生成库*/);
***/

//导入 protobuf.parser 生成的 aardio 库
import bilibili.community.service.dm.v1.DmSegMobileReply;

import web.rest.client; 
var http = web.rest.client();  
http.parseResponseResult = function(resp){

    //自动解析服务器响应数据为 Protobuf 消息对象
    var dmSeg = bilibili.community.service.dm.v1.DmSegMobileReply();
    dmSeg.parseFromString(resp);
    return dmSeg;
}

//发送请求
var dmSeg = http.get("https://api.bilibili.com/x/v2/dm/web/seg.so",{
  "oid":"36570401","pid":"76459310","type":1,"segment_index":1
})

//显示弹幕数据
for(i=1;#dmSeg.elems){
    var elem = dmSeg.elems[i];
    console.log(elem.idStr,elem.content);
    //console.more(1000);
}

import web.json;

//不需要任何封装,所有 Protobuf 消息对象都可以直接转换为 json
var json = web.json.stringify(dmSeg);

//Protobuf 消息对象可通过 table.parseValue 转换为纯 table 对象
var tab = table.parseValue(dmSeg) 

console.pause(true); 
Markdown 格式