GithubHelp home page GithubHelp logo

drelf2018 / biligo-live-ws-postgresql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eric2788/biligo-live-ws

1.0 1.0 0.0 7.03 MB

免 binary 处理,包装成 Websocket 的可利用 PostgreSQL 保存 B站直播 pubsub 监控服务器

Go 88.75% Dockerfile 0.47% Python 10.78%

biligo-live-ws-postgresql's Introduction

biligo-live-ws

bili-go 为核心, 基于 JSON string 序列化 的 B站 WebSocket 监控服务器。

简介

根据个人开发经验,每次开发与B站直播WS相关的项目时,都要烦恼自己所使用的编程语言有没有相关的B站WS处理库,如果没有的话更要自己实作一个,当中的 binary 处理和解压程序可谓相当麻烦。

连线即用

打开后,透过 POST 请求输入你的订阅房间列表,然后连入WS后即可开始接收JSON数据,无需binary处理

你也可以连入 WebSocket 之后才输入你的订阅

即时增减

可以透过 PUT 请求即时新增和删除批量房间号,此举不需要透过重连 WebSocket 来刷新

无需后端

透过直接存取公共 API 地址,可直接在前端获取B站直播数据而无需自架或开发后端。

直接使用

目前的公共 API 地址:

执行 GET / 后 显示

{
  "status": "working"
}

则代表服务正常运行。

可供测试的前端地址: https://eric2788.github.io/biligo-live-ws

使用方式

头规格

Header Value
Content-Type application/x-www-form-urlencoded
Authorization 非必填,辨识ID,一个IP多程序用的时候防止混淆;不填则用 anonymous

注意

如果标明了 Authorization,则连入 websocket 时需要传入 query string ?id={辨识ID}

假设你设置订阅时传入头

{
  "Content-Type": "application/x-www-form-urlencoded",
  "Authorization": "abc"
}

连入 WS 则需要使用

wss://blive.ericlamm.xyz/ws?id=abc

此外,现在已新增全局的websocket接口,无需订阅和传入ID,直接传送所有正在监控的房间资料,可使用

wss://blive.ericlamm.xyz/ws/global

但将无法设置订阅。

步骤

  1. 透过 POST /subscribe 透过 subscribes key 递交你的订阅列表 (数组)

    例如

    subscribes=545&subscribes=114514

    成功后将返回成功订阅(无效的房间会被忽略)的真实房间号列表 (数组)

    [
      573893
    ]

    注意,如果订阅后五分钟内没有连入 WebSocket, 将会自动清除订阅列表数据(断线后也会开始计时)

  2. 透过 POST /validate 检查是否一切准备就绪(非必要)

    此请求会检查你的订阅列表是否为空,如果为空将返回 400 错误,否则返回 200

  3. 开始透过 后缀为 /ws 的请求连入 WebSocket

    如果成功订阅,连入 WebSocket 的几秒后将会开始接收已经 JSON 序列化的 B站直播 数据

API 参考

Path 路径 Method 方法 Payload 传入 Response(200) 返回 Error 错误
/ GET 程序是否运行
/subscribe GET 目前的订阅列表(数组)
/subscribe POST 订阅列表(数组) 成功的订阅列表(数组) 400 如果輸入列表为空或缺少数值
/subscribe DELETE 删除订阅列表
/validate POST 400 如果准备未就绪
/subscribe/add PUT 要新增的批量订阅(数组) 目前的订阅列表(数组) 400 如果輸入列表为空或缺少数值
/subscribe/remove PUT 要删除的批量订阅(数组) 目前的订阅列表(数组) 400 如果輸入列表为空或缺少数值/之前尚未递交订阅
/listening GET 目前正在监控的所有房间号和总数
/listening/:房间号 GET 获取该房间号的直播资讯

B站直播数据解析

格式如下

key 数值 类型
command 直播数据指令 string
live_info 直播房间资讯 详见下方
content 直播数据原始内容(已转换为json) object

直播房间资讯

key 数值 类型
room_id 直播房间号 int64
uid 直播用户ID int64
title 直播标题 int64
name 直播名称 string
cover 直播封面网址 string
user_face 直播用户头像网址 string
user_description 直播用户简介 string

每次开播时都会自动刷新一次直播房间资讯

备注

  • 指令为 HEARTBEAT_REPLY直播数据原始内容已被序列化为格式

    {
       "popularity": 999999
    }

    (999999为人气值)

  • 直播数据原始内容(content) 如果转换 object 失败,将自动转为 string

  • 为了防止 B站 API 调用过度频繁,调用 /subscribe/subscribe/add 时可以傳入 query ?validate=false 来取消验证房间讯息

私人部署

Docker

docker.io 或 详见 Dockerfile

Linux / Windows

详见 Releases

运行参数(非必要)

./biligo-live-ws --port 端口 --release
  • port: 不填则 8080
  • release: 添加此参数即等同设置环境参数中 GIN_MODErelease (即 production mode)

鸣谢

bili-go 作者

biligo-live-ws-postgresql's People

Contributors

eric2788 avatar drelf2018 avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.