NiceLeeのBlog 用爱发电 bilibili~

Acfun接口(二) - 番剧单集下载

2019-07-28
nIceLee

阅读:


做个笔记,A站bangumi应该如何下载(๑•̀ㅂ•́)و✧

要做的事情

  • 已知网址如何获取下载链接
  • 指定清晰度该如何处理

已知网址如何获取下载链接

网址示例

https://www.acfun.cn/bangumi/ab5020013_29129_230273

访问网址,得出视频对应的videoId

由正则抠出json,获取videoId

Pattern pABVideoInfo = Pattern.compile("window.bangumiData ?= ?(.*?});");

json包含有很多信息,其中重要的是json.videoId = 1993966

发起API请求,得到m3u8链接

https://www.acfun.cn/rest/pc-direct/play/playInfo/m3u8Auto?videoId={videoId}

结果示例:

{
	"result": 0,
	"playInfo": {
		"streams": [{
			"format": 0,
			"quality": 1000,
			"size": 0,
			"width": 0,
			"height": 0,
			"fps": 0,
			"cdnUrls": [{
				"url": "https://www.acfun.cn/rest/pc-direct/play/hls/masterPlayList.m3u8?videoId=1993966&playToken=9zi2Xts5aQsAilkkJdOrnbN1M3TC6q2T7IFmZ%2FwscE3xoVQIV2WG7FGXMrw%2BG5%2Fv4AsDgxZOaKhErUf%2FX5Aiu81cZAH7cwmJQzIIMgOAHNCsHcxNGb1LeLXbGdqHEGILYmb30hShE5dlVGWYeVOIZzWHtfJqOLtOgN2yLKogNKeklLvaSNl58Ky86YemC1WhvvHToY6uVMdIOaehue7AiEgX4pAaLXQeabF%2BZS8mFVq%2FwEWcuifgekz9AkF8GTAB",
				"freeTrafficCdn": false
			}],
			"playUrls": ["https://www.acfun.cn/rest/pc-direct/play/hls/masterPlayList.m3u8?videoId=1993966&playToken=9zi2Xts5aQsAilkkJdOrnbN1M3TC6q2T7IFmZ%2FwscE3xoVQIV2WG7FGXMrw%2BG5%2Fv4AsDgxZOaKhErUf%2FX5Aiu81cZAH7cwmJQzIIMgOAHNCsHcxNGb1LeLXbGdqHEGILYmb30hShE5dlVGWYeVOIZzWHtfJqOLtOgN2yLKogNKeklLvaSNl58Ky86YemC1WhvvHToY6uVMdIOaehue7AiEgX4pAaLXQeabF%2BZS8mFVq%2FwEWcuifgekz9AkF8GTAB"]
		}],
		"duration": 451444
	},
	"host-name": "hb2-acfun-kcs036.aliyun"
}

最后得到结果:

json.playInfo.streams[0].playUrls[0]

指定清晰度该如何处理

上述得到的m3u8链接包含了能提供的各种清晰度,举例如下:

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-STREAM-INF:RESOLUTION=640x360,BANDWIDTH=400000,PROGRAM-ID=1,
https://video.acfun.cn/50cf5b9ba366430693c3624dec1bf42c/9b331055918d44a9b77cd81f09a53cef-5f3a4caeaa6e346b15db81e84538593c-fd.m3u8?auth_key=1566797748-10106955784624d21c380a07b1b683e10eabbbfd666fac0212101p87p143pd96ab50f0ea68a4-acfun-147dc822b41538a290b609698ae493b5
#EXT-X-STREAM-INF:RESOLUTION=960x540,BANDWIDTH=900000,PROGRAM-ID=1,
https://video.acfun.cn/50cf5b9ba366430693c3624dec1bf42c/9b331055918d44a9b77cd81f09a53cef-02313bf0f0899fd3dcd11a124ad60245-ld.m3u8?auth_key=1566797748-10106955784624d21c380a07b1b683e10eabbbfd666fac0212101p87p143pd96ab50f0ea68a4-acfun-3fb9e3dfab7c033df50da4f68c083665
#EXT-X-STREAM-INF:RESOLUTION=1920x1080,BANDWIDTH=3000000,PROGRAM-ID=1,
https://video.acfun.cn/50cf5b9ba366430693c3624dec1bf42c/9b331055918d44a9b77cd81f09a53cef-af7d81d7b3bd2577563638e0fa5cc367-hd.m3u8?auth_key=1566797748-10106955784624d21c380a07b1b683e10eabbbfd666fac0212101p87p143pd96ab50f0ea68a4-acfun-3cd0ef0955403303dcd1294ef1f1f8ec

可以根据需要选取对应清晰度的视频


内容
隐藏