视频下载
POST
/api/bilibili/video_download/下载说明
此接口下载需要更改下载文件后缀,下载后的视频和音频格式都为m4s格式,下载后直接改为mp4或mp3即可。
python下载示例
import requests
from tqdm import tqdm
def download_file(url,request_headers, save_path):
response = requests.get(url, stream=True, headers=request_headers)
total_size = int(response.headers.get('content-length', 0))
block_size = 1024 # 1 KB
progress_bar = tqdm(total=total_size, unit='B', unit_scale=True)
with open(save_path, 'wb') as file:
for data in response.iter_content(block_size):
progress_bar.update(len(data))
file.write(data)
progress_bar.close()
if total_size != 0 and progress_bar.n != total_size:
print("下载失败,请重试!")
else:
print("下载完成!")
if __name__ == "__main__":
file_url = "解析的下载"
request_headers = {
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.69",
"Referer":"https://www.bilibili.com/video/视频ID/",
}
save_path = "local_file.mp4"
download_file(file_url,request_headers, save_path)
请求参数
Header 参数
Cookie
string
必需
Cookie 参数
buvid3
string
必需
SESSDATA
string
必需
bili_jct
string
必需
Body 参数application/json
bvid
string
视频BVID
avid
string
必需
cid
string
必需
示例
{
"bvid": "BV11F411K7DB",
"avid": "301141892",
"cid": "778842376"
}
示例代码
返回响应
成功(200)
HTTP 状态码: 200
内容格式: JSONapplication/json
数据结构
code
integer
必需
msg
string
必需
data
object
必需
message
string
必需
video_url
string
必需
示例
成功示例
{
"code": 200,
"msg": "请求成功",
"data": {
"message": "MP4 流下载,可直接更改格式",
"video_url": "https://xy163x142x85x189xy.mcdn.bilivideo.cn:8082/v1/resource/794811452-1-100026.m4s?agrr=0&build=0&buvid=931081E9D-AE3E-9F5F-9109F-6E1521591018836102infoc&bvc=vod&bw=151729&deadline=1693629741&e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M%3D&f=u_0_0&gen=playurlv2&logo=A0000002&mcdnid=2003416&mid=3493144259726260&nbs=1&nettype=0&oi=1919203006&orderid=0%2C3&os=mcdn&platform=pc&sign=3cbb19&traceid=trQPKwjTJokssj_0_e_N&uipk=5&uparams=e%2Cuipk%2Cnbs%2Cdeadline%2Cgen%2Cos%2Coi%2Ctrid%2Cmid%2Cplatform&upsig=c04465bd2bed881f2b0feb2929a8f099",
"audio_url": "https://xy115x58x253x121xy.mcdn.bilivideo.cn:8082/v1/resource/794811452_nb3-1-30280.m4s?agrr=0&build=0&buvid=931081E9D-AE3E-9F5F-9109F-6E1521591018836102infoc&bvc=vod&bw=29102&deadline=1693629741&e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M%3D&f=u_0_0&gen=playurlv2&logo=A0000002&mcdnid=2003416&mid=3493144259726260&nbs=1&nettype=0&oi=1919203006&orderid=0%2C3&os=mcdn&platform=pc&sign=f77249&traceid=trtRfBtuFNuoEM_0_e_N&uipk=5&uparams=e%2Cuipk%2Cnbs%2Cdeadline%2Cgen%2Cos%2Coi%2Ctrid%2Cmid%2Cplatform&upsig=2e8b065dd34c89fb3e6324f973d3bd10"
}
}
最后修改时间: 20 天前