巧了!昨天分析了 “好看视频” 的视频下载链接,想着楼主提到的 “视频链接” 应该就在那里,一测试果然如此!
先附上对上述链接 https://haokan.baidu.com/v?vid=15131088464706533363
的下载信息提取结果:
{
"id": "15131088464706533363",
"title": "韶光CG韶光CG",
"poster": "https://f7.baidu.com/it/u=2463298423,3521856661&fm=222&app=106&f=JPEG@s_0,w_800,h_1000,q_80,f_auto",
"playcnt": 0,
"fmplaycnt": "0次播放",
"publish_time": 1696259719,
"date": "发布时间:2023年10月2日",
"time_length": "00:50",
"duration": 50,
// 要找的那个 6s 链接就在这里
"6s_play_url": "http://highlight-video.cdn.bcebos.com/video/6s/8bfee134-6136-11ee-82ff-7cd30a651110.mp4?v_from_s=hkapp-haokan-nanjing",
"playurl": "https://vd2.bdstatic.com/mda-pj1mjtg4zerq8bdj/360p/h264/1696259672888371046/mda-pj1mjtg4zerq8bdj.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1696436710-0-0-28509d9ad20a5f975e4bef5ed6bb0e41&bcevod_channel=searchbox_feed&cr=0&cd=0&pd=1&pt=3&logid=1510669976&vid=15131088464706533363",
"clarityUrl": [{
"key": "sd",
"rank": 0,
"title": "标清",
"url": "https://vd2.bdstatic.com/mda-pj1mjtg4zerq8bdj/360p/h264/1696259672888371046/mda-pj1mjtg4zerq8bdj.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1696436710-0-0-28509d9ad20a5f975e4bef5ed6bb0e41&bcevod_channel=searchbox_feed&cr=0&cd=0&pd=1&pt=3&logid=1510669976&vid=15131088464706533363",
"videoBps": 892,
"vodVideoHW": "360$$640",
"videoSize": 5.4,
"vodMoovSize": 24462
}, {
"key": "hd",
"rank": 1,
"title": "高清",
"url": "https://vd2.bdstatic.com/mda-pj1mjtg4zerq8bdj/576p/h264/1696259672992418671/mda-pj1mjtg4zerq8bdj.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1696436710-0-0-b89fe5c83e71f1fe86e6f72c6f954859&bcevod_channel=searchbox_feed&cr=1&cd=0&pd=1&pt=3&logid=1510669976&vid=15131088464706533363",
"videoBps": 1046,
"vodVideoHW": "576$$1024",
"videoSize": 6.4,
"vodMoovSize": 24455
}, {
"key": "sc",
"rank": 2,
"title": "超清",
"url": "https://vd2.bdstatic.com/mda-pj1mjtg4zerq8bdj/720p/h264/1696259672838829719/mda-pj1mjtg4zerq8bdj.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1696436710-0-0-53d6410573ec8bee78d34a2ad4d5d77a&bcevod_channel=searchbox_feed&cr=2&cd=0&pd=1&pt=3&logid=1510669976&vid=15131088464706533363",
"videoBps": 1968,
"vodVideoHW": "720$$1280",
"videoSize": 12,
"vodMoovSize": 24356
}, {
"key": "1080p",
"rank": 3,
"title": "蓝光",
"url": "https://vd2.bdstatic.com/mda-pj1mjtg4zerq8bdj/1080p/cae_h264/1696259834645003756/mda-pj1mjtg4zerq8bdj.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1696436710-0-0-4a2702cc91ebdfe16aa3e369fb1a017c&bcevod_channel=searchbox_feed&cr=3&cd=0&pd=1&pt=3&logid=1510669976&vid=15131088464706533363",
"videoBps": 3880,
"vodVideoHW": "1080$$1920",
"videoSize": 23.7,
"vodMoovSize": 24626,
"transType": "cae",
"gopAlign": True
}],
"video_status": 1,
"video_rejectType": "1",
"is_like": 0,
"is_collection": None,
"like": 0,
"is_pay_column": 0,
"scenes": False,
"voteDisableCtrl": "0",
"fmlike_num": "0次播放",
"comment": 0,
"fmcomment_num": "0次播放",
"column_info": [],
"previewUrlHttp": "http://highlight-video.cdn.bcebos.com/video/6s/8bfee134-6136-11ee-82ff-7cd30a651110.mp4?v_from_s=hkapp-haokan-nanjing",
"isLongVideo": False,
"frame_sprites": {
"image_urls": ["http://gips3.baidu.com/it/u=940858878,1264808804&fm=3021&app=3021&f=JPEG?w=2610&h=1470"],
"interval": 1,
"x_len": 10,
"x_size": 261,
"y_len": 10,
"y_size": 147
},
"is_forbidden_share": 0,
"shareInfo": {
"type": "url"
},
"collection_info": []
}
下面是 Python
代码可以根据 “好看视频” 的播放页链接快速提取视频的下载链接,也可以按照这个逻辑改为油猴脚本,主要过程是:
- 提取出 HTML 中的
encrptedVideoMeta
值
- 对该值进行解密即可,解密算法的分析涉及到
js
,由于悬赏区不能上传附件(图片),所以省略了。
import httpx
import re
import json
import base64
from io import BytesIO
from pprint import pprint
def get_video_info(html: str):
# 用正则表达式取出 encrptedVideoMeta
meta = re.search(r'"encrptedVideoMeta":\s*"(.*?)"', html).group(1)
# 以下进行解密
a = b"guanghui456"
b = base64.b64decode(meta)
c = BytesIO()
for i in range(len(b)):
c.write(bytes([b[i] ^ a[i % len(a)]]))
pprint(json.loads(c.getvalue()))
if __name__ == "__main__":
url = input("URL: ")
headers = {"User-Agent": "Mozilla/5.0"}
html = httpx.get(url, headers=headers).text
get_video_info(html)