{"id":13431512,"url":"https://github.com/Nemo2011/bilibili-api-ts","last_synced_at":"2025-03-16T11:31:50.168Z","repository":{"id":57828825,"uuid":"527419389","full_name":"Nemo2011/bilibili-api-ts","owner":"Nemo2011","description":"哔哩哔哩常用API调用。","archived":true,"fork":false,"pushed_at":"2023-08-05T10:12:29.000Z","size":144,"stargazers_count":15,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T21:53:54.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://nemo2011.github.io/bilibili-api-ts","language":"TypeScript","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/Nemo2011.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOGS/v12.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-22T05:08:52.000Z","updated_at":"2025-02-17T10:22:33.000Z","dependencies_parsed_at":"2023-01-17T00:30:33.531Z","dependency_job_id":null,"html_url":"https://github.com/Nemo2011/bilibili-api-ts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nemo2011%2Fbilibili-api-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nemo2011%2Fbilibili-api-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nemo2011%2Fbilibili-api-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nemo2011%2Fbilibili-api-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nemo2011","download_url":"https://codeload.github.com/Nemo2011/bilibili-api-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243863213,"owners_count":20360284,"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":[],"created_at":"2024-07-31T02:01:03.709Z","updated_at":"2025-03-16T11:31:49.773Z","avatar_url":"https://github.com/Nemo2011.png","language":"TypeScript","funding_links":[],"categories":["开发"],"sub_categories":["直播脚本"],"readme":"\u003cdiv align=\"center\"\u003e\r\n\r\n![bilibili-api logo](https://raw.githubusercontent.com/nemo2011/bilibili-api/main/design/logo-small.png)\r\n\r\n# bilibili-api **typescript** 分部\r\n\r\n\u003cimg src=\"https://cdn.iconscout.com/icon/free/png-512/typescript-1174965.png\" height=50 width=50\u003e\u003cimg src=\"https://logos-download.com/wp-content/uploads/2019/01/JavaScript_Logo.png\" height=50 width=50\u003e\u003cimg src=\"https://tse4-mm.cn.bing.net/th/id/OIP-C.bodQFDX6bpdw0aj11XxjrAHaCi?pid=ImgDet\u0026rs=1\" height=50\u003e\r\n\r\n\r\n\u003c/div\u003e\r\n\r\n# 简介\r\n\r\n这里是 Python 模块 [bilibili-api](https://github.com/nemo2011/bilibili-api) 的 Typescript 克隆，适用于 JS/TS\r\n\r\n**注意：本仓库全都是异步操作，而且是 `ajax`，就是那种代码跑完了结果你的结果才刚刚出来的那种，不 `await` 后果自负。**\r\n\r\n如果您是新手，请务必看完这个 `readme`，里面有许多重要的信息。\r\n\r\n## 特色\r\n\r\n- 全面支持 javascript 和 typescript\r\n- 可使用代理，绕过 b 站风控策略。\r\n- 全面支持 BV 号（bvid），同时也兼容 AV 号（aid）。\r\n- 调用简便，函数命名易懂，代码注释详细。\r\n- 依赖少，无需第三方命令行工具，装完即用，无需其他配置。\r\n- 更多的 API 敬请期待！\r\n\r\n# 快速上手\r\n\r\n首先，使用以下命令安装：\r\n\r\n```\r\n$ npm install bilibili-api-ts\r\n```\r\n\r\n或者在 `package.json` 中添加依赖。\r\n\r\n接下来让我们获取视频播放量等信息：\r\n\r\n``` javascript\r\nconst video = require(\"bilibili-api-ts/video.js\");\r\n\r\n// 实例化 Video 类\r\nvar v = new video.Video({\r\n    bvid: \"BV1uv411q7Mv\"\r\n});\r\n\r\n(async function(){\r\n    console.log(await v.get_info());\r\n})();\r\n```\r\n\r\n输出（已格式化，已省略部分）：\r\n\r\n```json\r\n{\r\n    \"bvid\": \"BV1uv411q7Mv\",\r\n    \"aid\": 243922477,\r\n    \"videos\": 1,\r\n    \"tid\": 17,\r\n    \"tname\": \"单机游戏\",\r\n    \"copyright\": 1,\r\n    \"pic\": \"http://i2.hdslb.com/bfs/archive/82e52df9d0221836c260c82f2890e3761a46716b.jpg\",\r\n    \"title\": \"爆肝９８小时！在 MC 中还原糖调小镇\",\r\n    \"pubdate\": 1595203214,\r\n    \"ctime\": 1595168654,\r\n    ...and more\r\n}\r\n```\r\n\r\n---\r\n\r\n如何给这个视频点赞？我们需要登录自己的账号。\r\n\r\n这里设计是传入一个 Credential 类，获取所需的信息参照：[获取 Credential 类所需信息][get-credential]\r\n\r\n下面的代码将会给视频点赞\r\n\r\n```javascript\r\nconst bilibili = require(\"bilibili-api-ts\");\r\nconst video = require(\"bilibili-api-ts/video.js\");\r\n\r\n// 实例化 Video 类\r\nvar v = new video.Video({\r\n    bvid: \"BVxxxxxxxxxx\", \r\n    credential: new  bilibili.Credential({\r\n        sessdata: \"xxx\", \r\n        bili_jct: \"xxx\", \r\n        dedeuserid: \"xxx\"\r\n    })\r\n});\r\n\r\n(async function(){\r\n    await v.like({\r\n        status: true\r\n    });\r\n})();\r\n```\r\n\r\n# FA♂Q\r\n\r\n**Q: 关于 API 调用的正确姿势是什么？**\r\n\r\nA: API 调用传参方式请看下面的举例：\r\n\r\n```typescript\r\n// 错误 1: 传参\r\n// 设 video.get_info 函数的参数是一个字典，字典的 bvid 项为稿件 BVID。\r\n// 函数定义：get_info({bvid}: {bvid: string})\r\n/** \r\n * 所有的参数传入请传入一个字典，这样子可以换传参顺序、指名传参。\r\n * 传参像这样：get_info({参数名1: 参数1, 参数名2: 参数2}) -\u003e get_info({bvid: 稿件 BVID})\r\n * 请不要直接传参数，参数需要放在字典里，而且需要表明好键，不能不标键。\r\n */ \r\n\r\n// 推荐\r\nvideo.get_info({bvid:\"BV1uv411q7Mv\"})\r\n\r\n// 当然也可以这样\r\nvideo.get_info({\"bvid\":\"BV1uv411q7Mv\"})\r\n\r\n// 不可以！\r\nvideo.get_info({\"BV1uv411q7Mv\"}) // 没有标明键(bvid)\r\n\r\n// 自己看 IntelliCode 的提示吧。\r\nvideo.get_info(\"BV1uv411q7Mv\") // 传入字典啊！\r\n// ----------------------------------------------------------\r\n// 错误 2: 每个函数都得传参\r\n// 设 video.Video.prototype.get_aid 函数操作不用传任何参数：\r\n// 函数定义：get_aid({}){...}，仍然加一个空字典当参数\r\n/*\r\n    因为 JS/TS 的迷惑设计，函数都不能指名传参。\r\n    因此这里的设计是每一个函数都传入一个字典，像这样：{参数名1: 参数1, 参数名2: 参数2}，不用传参的函数暂时也还没有加上一个字典当参数。\r\n    后来实在因为强迫症，把不用参数的函数都加了一个空字典当参数，原来 get_aid() 变成 get_aid({})，这样的确有个好处：随便传参不报错。\r\n*/\r\n\r\n// 可以\r\nvideo.get_aid({})\r\n\r\n// 不会错\r\nvideo.get_aid({bvid: \"我是个 SB\"})\r\n\r\n// 建议不要这么做\r\nvideo.get_aid()\r\n```\r\n\r\n\u003e如果有看不懂的地方，可以自己打一下示例代码(最好加上 IntelliCode 或在带实时提示的 Node REPL 下)，这样子自然而然就懂了。\r\n每一个函数请务必都传一下放着参数的字典。\r\n\r\n**Q: 为什么会提示 412 Precondition Failed ？**\r\n\r\nA: 你的请求速度太快了。造成请求速度过快的原因可能是你写了高并发的代码。\r\n\r\n这种情况下，你的 IP 会暂时被封禁而无法使用，你可以设置代理绕过。\r\n\r\n```typescript\r\nimport { set_proxy, Proxy } from \"bilibili-api-ts\"\r\nset_proxy(new Proxy({\r\n    host: \"代理网址\", \r\n    port: \"代理端口\", \r\n    username: \"用户名（可选）\", \r\n    password: \"密码（可选)\"\r\n}))\r\n```\r\n\r\n**Q: 怎么没有我想要的功能？**\r\n\r\nA: 你可以发 Issue 来提交你的需求，但是，最好的办法是自己写（懒）\r\n\r\n\u003cspan id=\"contribute\"\u003e**Q: 我有一个大胆的想法，如何给代码库贡献？**\u003c/span\u003e\r\n\r\nA: 请先 clone 本仓库一份，然后从 main 分支新建一个分支，在该分支上工作。\r\n如果你觉得已经可以了，请向项目仓库的 develop 分支发起 Pull request。\r\n如果你不明白这些操作的话，可以百度。完整指南：[CONTRIBUTING.md](https://github.com/nemo2011/bilibili-api/blob/javascript/.github/JAVASCRIPT.md)\r\n\r\n**Q: 稳定性怎么样？**\r\n\r\nA: 由于该模块比较特殊，是爬虫模块，如果 b 站的接口变更，可能会马上失效。因此请始终保证是最新版本。如果发现问题可以提 [Issues][issues-new]。\r\n\r\n---\r\n\r\n[get-credential](https://nemo2011.github.io/bilibili-api/#/ts/get-credential)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNemo2011%2Fbilibili-api-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNemo2011%2Fbilibili-api-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNemo2011%2Fbilibili-api-ts/lists"}