{"id":13431582,"url":"https://github.com/iyear/biligo-live","last_synced_at":"2025-03-25T23:32:24.117Z","repository":{"id":40316802,"uuid":"424256010","full_name":"iyear/biligo-live","owner":"iyear","description":"🚀 BiliBili Live WebSocket Protocol SDK in Golang","archived":false,"fork":false,"pushed_at":"2024-07-15T03:15:20.000Z","size":103,"stargazers_count":32,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"v0","last_synced_at":"2025-03-24T04:54:02.690Z","etag":null,"topics":["bilibili","bilibili-api","bilibili-helper","bilibili-live","websocket"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/iyear/biligo-live","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iyear.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-03T14:26:17.000Z","updated_at":"2024-12-12T16:40:01.000Z","dependencies_parsed_at":"2024-06-18T22:49:59.433Z","dependency_job_id":"4808aff0-e760-4bfe-94f6-4790455dbe99","html_url":"https://github.com/iyear/biligo-live","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyear%2Fbiligo-live","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyear%2Fbiligo-live/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyear%2Fbiligo-live/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyear%2Fbiligo-live/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iyear","download_url":"https://codeload.github.com/iyear/biligo-live/tar.gz/refs/heads/v0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245562263,"owners_count":20635896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bilibili","bilibili-api","bilibili-helper","bilibili-live","websocket"],"created_at":"2024-07-31T02:01:04.253Z","updated_at":"2025-03-25T23:32:22.226Z","avatar_url":"https://github.com/iyear.png","language":"Go","funding_links":[],"categories":["开发"],"sub_categories":["直播脚本"],"readme":"\u003cimg src=\"./img/logo.png\" alt=\"logo\" width=\"130\" height=\"130\" align=\"left\" /\u003e\n\n\u003ch1\u003eBiliGO-LIVE\u003c/h1\u003e\n\n\u003e BiliBili Live WebSocket Protocol SDK in Golang\n\n\u003cbr/\u003e\n\n![](https://img.shields.io/github/go-mod/go-version/iyear/biligo-live?style=flat-square)\n![](https://img.shields.io/badge/license-GPL-lightgrey.svg?style=flat-square)\n![](https://img.shields.io/github/v/release/iyear/biligo-live?color=red\u0026style=flat-square)\n![](https://img.shields.io/github/last-commit/iyear/biligo-live?style=flat-square)\n[![Go Reference](https://pkg.go.dev/badge/github.com/iyear/biligo-live.svg)](https://pkg.go.dev/github.com/iyear/biligo-live)\n\n## 简介\n\n**v0版本不保证对外函数、结构的不变性，请勿大规模用于生产环境**\n\n哔哩哔哩直播 `WebSocket` 协议的 `Golang` 封装\n\n### 特性\n- 良好的设计，自定义程度高\n- 代码、结构体注释完善，开箱即用\n- 功能简单，封装程度高\n### 说明\n\n- 该项目永远不会编写直接涉及滥用的接口\n- 该项目仅供学习，请勿用于商业用途。任何使用该项目造成的后果由开发者自行承担\n\n### 参考\n\n## 快速开始\n### 安装\n\n```shell\ngo get -u github.com/iyear/biligo-live\n```\n\n```go\nimport \"github.com/iyear/biligo-live\"\n```\n\n### 使用\n\u003cdetails\u003e\n\u003csummary\u003e查看代码\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/gorilla/websocket\"\n\t\"github.com/iyear/biligo-live\"\n\t\"log\"\n\t\"time\"\n)\n\n// 同 README.md 的快速开始\n\nfunc main() {\n\tconst room int64 = 48743\n\n\t// 获取一个Live实例\n\t// debug: debug模式，输出一些额外的信息\n\t// heartbeat: 心跳包发送间隔。不发送心跳包，70 秒之后会断开连接，通常每 30 秒发送 1 次\n\t// cache: Rev channel 的缓存\n\t// recover: panic recover后的操作函数\n\tl := live.NewLive(true, 30*time.Second, 0, func(err error) {\n\t\tlog.Println(\"panic:\", err)\n\t\t// do something...\n\t})\n\n\t// 连接ws服务器\n\t// dialer: ws dialer\n\t// host: bilibili live ws host\n\tif err := l.Conn(websocket.DefaultDialer, live.WsDefaultHost); err != nil {\n\t\tlog.Fatal(err)\n\t\treturn\n\t}\n\n\tctx, stop := context.WithCancel(context.Background())\n\n\tgo func() {\n\t\t// 进入房间\n\t\t// room: room id(真实ID，短号需自行转换)\n\t\t// key: 用户标识，可留空\n\t\t// uid: 用户UID，可随机生成\n\t\tif err := l.Enter(ctx, room, \"\", 12345678); err != nil {\n\t\t\tlog.Fatal(err)\n\t\t\treturn\n\t\t}\n\t}()\n\n\tgo rev(ctx, l)\n\n\t// 15s的演示\n\tafter := time.NewTimer(15 * time.Second)\n\tdefer after.Stop()\n\t\u003c-after.C\n\tfmt.Println(\"I want to stop\")\n\t// 关闭ws连接与相关协程\n\tstop()\n\t// 为了使安全退出效果可见，进行阻塞，真实场景中可以移除\n\tselect {}\n}\nfunc rev(ctx context.Context, l *live.Live) {\n\tfor {\n\t\tselect {\n\t\tcase tp := \u003c-l.Rev:\n\t\t\tif tp.Error != nil {\n\t\t\t\t// do something...\n\t\t\t\tlog.Println(tp.Error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\thandle(tp.Msg)\n\t\tcase \u003c-ctx.Done():\n\t\t\tlog.Println(\"rev func stopped\")\n\t\t\treturn\n\t\t}\n\t}\n}\nfunc handle(msg live.Msg) {\n\t// 使用 msg.(type) 进行事件跳转和处理，常见事件基本都完成了解析(Parse)功能，不常见的功能有一些实在太难抓取\n\t// 更多注释和说明等待添加\n\tswitch msg := msg.(type) {\n\t// 心跳回应直播间人气值\n\tcase *live.MsgHeartbeatReply:\n\t\tlog.Printf(\"hot: %d\\n\", msg.GetHot())\n\t// 弹幕消息  \n\tcase *live.MsgDanmaku:\n\t\tdm, err := msg.Parse()\n\t\tif err != nil {\n\t\t\tlog.Println(err)\n\t\t\treturn\n\t\t}\n\t\tfmt.Printf(\"弹幕: %s (%d:%s) 【%s】| %d\\n\", dm.Content, dm.MID, dm.Uname, dm.MedalName, dm.Time)\n\t// 礼物消息 \n\tcase *live.MsgSendGift:\n\t\tg, err := msg.Parse()\n\t\tif err != nil {\n\t\t\tlog.Println(err)\n\t\t\treturn\n\t\t}\n\t\tfmt.Printf(\"%s: %s %d个%s\\n\", g.Action, g.Uname, g.Num, g.GiftName)\n\t// 直播间粉丝数变化消息 \n\tcase *live.MsgFansUpdate:\n\t\tf, err := msg.Parse()\n\t\tif err != nil {\n\t\t\tlog.Println(err)\n\t\t\treturn\n\t\t}\n\t\tfmt.Printf(\"room: %d,fans: %d,fansClub: %d\\n\", f.RoomID, f.Fans, f.FansClub)\n\t// case:......\n\n\t// General 表示live未实现的CMD命令，请自行处理raw数据。也可以提issue更新这个CMD\n\tcase *live.MsgGeneral:\n\t\tfmt.Println(\"unknown msg type|raw:\", string(msg.Raw()))\n\t}\n}\n\n```\n\u003c/details\u003e\n\n## LICENSE\n\nGPLv3","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyear%2Fbiligo-live","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiyear%2Fbiligo-live","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyear%2Fbiligo-live/lists"}