-
不需要登录,理论上bilibili上不登陆能看的视频都能下载
-
支持个人视频(bv)、番剧(ep)、电视剧(ss)
-
音视频合并,无需合成
-
仅供学习使用
git clone https://gitee.com/imzusheng/bilibili-download.git
cd ./bilibili-download
npm i
node app
浏览器中打开http://localhost:3000
- 下载普通视频
- 下载番剧视频
- 下载剧集视频
- 下载切换剧集
- 下载电影(额外付费除外)
- 基本视频信息
- 热门评论
- 下载封面
- 下载字幕
- 离线下载
- 代理静态资源
在页面中直接调用B站API,浏览器自动往请求头加上Referer
,B站服务器就拦截掉不符合要求的请求,
需要通过nodejs代理伪造请求头。假设我要获取一张图片,地址是http://i0.hdslb.com/bfs/archive/4d1d7bde55218c1971dde8aee51864b5ccfc1f04.jpg
前端请求
const url = encodeURIComponent('http://i0.hdslb.com/bfs/archive/4d1d7bde55218c1971dde8aee51864b5ccfc1f04.jpg')
fetch(`http://localhost:3000/proxy?url=${url}`).then(res => {
// ...
})
nodejs代理(koa2)
router.get('/proxy', async ctx => {
const {url, headers = {}} = ctx.query
function get() {
return new Promise(resolve => {
https.get(url, {
headers: Object.assign(headers, {
'Referer': 'https://www.bilibili.com/'
})
}, response => {
// response.setEncoding('utf-8')
// 如果设置了编码为'utf-8'时请求JSON,html等文件时正常,图片异常
// 不设置setEncoding时默认为Buffer,不编码直接转发到前端
ctx.set(response.headers)
let chunks = Buffer.alloc(0)
response.on('data', data => {
// 拼接buffer
chunks = Buffer.concat([chunks, data])
})
response.on('end', () => {
resolve(chunks)
})
})
})
}
ctx.body = await get()
})
- Nodejs上解码Bilibili Protobuf弹幕
v0.0.1 2022-03-24
https://demo.zusheng.club/bili_download/
后续整理用到的API