腾讯视频的地址解析下载
以腾讯视频播放页地址http://v.qq.com/x/cover/rz4mhb6494f12co.html为例,说说如何解析得到视频的真实地址。
提取视频ID
在播放页源码中,可以找到如下视频信息:
var VIDEO_INFO = {
title: "咱们相爱吧 第1集",
duration: "2746",
vid: "y00221a60w7",
piantou:"0",
pianwei:"0",
showMark:"1",
showBullet:true,
showImageBullet:false,
openBulletDefault:true,
isNeedPay: false,
isTrailer: 0,
singlePrice: "undefined",
vipPrice: "undefined",
tryTime: "1306029",
isTrailer : 0,
type: "2"
};
其中,vid的值y00221a60w7
即为视频ID.
请求getinfo接口
使用Chrome浏览器的开发者工具监控网络请求,发现getinfo接口的请求地址如下:
http://h5vv.video.qq.com/getinfo?callback=txplayerJsonpCallBack_getinfo_591513&isHLS=false&charge=0&vid=y00221a60w7&defn=hd&defnpayver=1&otype=json&guid=29a06bf3852fbe2ea6eb53829c3878fa&platform=10901&sdtfrom=v1010&host=v.qq.com&_rnd=1479010822&fhdswitch=0&show1080p=1&_qv_rmt=sNk0sWZTA17002uQa%3D&_qv_rmt2=0Qs65I9%2B149182HOQ%3D&_=1479010820769
我们尝试构造各个请求参数,然后看看请求结果是什么样子的。
params = {
'isHLS': False,
'charge': 0,
'vid': 'y00221a60w7',
'defn': 'shd',
'defnpayver': 1,
'otype': 'json',
'platform': 10901,
'sdtfrom': 'v1010',
'host': 'v.qq.com',
'fhdswitch': 0,
'show1080p': 1,
}
参数中的defn为清晰度标识,可选值有sd(标清)、hd(高清)、shd(超清)、fhd(1080P)。请求结果如下:
{
"dltype": 1,
"exem": 0,
"fl": {
"cnt": 4,
"fi": [
{
"br": 20000,
"cname": "高清;(480P)",
"fs": 239935872,
"id": 10412,
"lmt": 0,
"name": "hd",
"sb": 1,
"sl": 0
},
{
"br": 500000,
"cname": "蓝光;(1080P)",
"fs": 1064110139,
"id": 10409,
"lmt": 1,
"name": "fhd",
"sb": 1,
"sl": 0
},
{
"br": 64,
"cname": "标清;(270P)",
"fs": 114567499,
"id": 10403,
"lmt": 0,
"name": "sd",
"sb": 1,
"sl": 0
},
{
"br": 500000,
"cname": "超清;(720P)",
"fs": 468471925,
"id": 10401,
"lmt": 0,
"name": "shd",
"sb": 1,
"sl": 1
}
]
},
"hs": 0,
"ls": 0,
"preview": 2746,
"s": "o",
"sfl": {
"cnt": 0
},
"tm": 1479014650,
"vl": {
"cnt": 1,
"vi": [
{
"br": 166,
"ch": 0,
"cl": {
"ci": [
{
"cd": "300.032",
"cmd5": "285464ac33c56b14caa63c466d4b4ed3",
"cs": 56516869,
"idx": 1,
"keyid": "y00221a60w7.10401.1"
},
{
"cd": "299.988",
"cmd5": "6a9b0dedeb2ed7c73e5ad31418a9a6bc",
"cs": 56364414,
"idx": 2,
"keyid": "y00221a60w7.10401.2"
},
{
"cd": "299.988",
"cmd5": "2181237427075dc219de8bdaa37ae64d",
"cs": 50213590,
"idx": 3,
"keyid": "y00221a60w7.10401.3"
},
{
"cd": "299.988",
"cmd5": "ac17519a98640a1926f54bc48f5637fb",
"cs": 37593039,
"idx": 4,
"keyid": "y00221a60w7.10401.4"
},
{
"cd": "300.032",
"cmd5": "546963ed0dcb3544373e8642eb2bb166",
"cs": 54082931,
"idx": 5,
"keyid": "y00221a60w7.10401.5"
},
{
"cd": "299.988",
"cmd5": "f33ed88e9b94d4cb1c9c0fb5d3730f76",
"cs": 43686678,
"idx": 6,
"keyid": "y00221a60w7.10401.6"
},
{
"cd": "299.988",
"cmd5": "a6a298f6122de6c09080ae78639c139c",
"cs": 40800986,
"idx": 7,
"keyid": "y00221a60w7.10401.7"
},
{
"cd": "299.988",
"cmd5": "9454b637e3c913ebd1c880ac5e6cf973",
"cs": 62436368,
"idx": 8,
"keyid": "y00221a60w7.10401.8"
},
{
"cd": "346.837",
"cmd5": "0fe50a2165b1ef7860627dbaf672d493",
"cs": 68478324,
"idx": 9,
"keyid": "y00221a60w7.10401.9"
}
],
"fc": 9
},
"ct": 21600,
"drm": 0,
"dsb": 0,
"fclip": 1,
"fmd5": "18f937a9790f22a843e618fb5fd02583",
"fn": "y00221a60w7.p401.mp4",
"fs": 468471925,
"fst": 5,
"fvkey": "88980E6001844B3B7D98195D7077A1EA62310E41BD70C43F57AC6E80AFEB8E9EFD71201CBBB054F2CBFEC5EA8269BB141DB6933322FAA43AD3BB6AA62AD9FE2C2B2A321A639497AA6DF23492CF3B622E41A1C5C75F2DDEC7",
"hevc": 0,
"iflag": 0,
"level": 0,
"lnk": "y00221a60w7",
"logo": 1,
"pl": [
{
"cnt": 2,
"pd": [
{
"c": 10,
"cd": 10,
"fmt": 40001,
"fn": "q1",
"h": 45,
"r": 10,
"url": "http://video.qpic.cn/video_caps/0/",
"w": 80
},
{
"c": 5,
"cd": 10,
"fmt": 40002,
"fn": "q2",
"h": 90,
"r": 5,
"url": "http://video.qpic.cn/video_caps/0/",
"w": 160
}
]
}
],
"share": 1,
"sp": 0,
"st": 2,
"td": "2746.84",
"ti": "咱们相爱吧_01",
"type": 1136,
"ul": {
"ui": [
{
"dt": 2,
"dtc": 10,
"url": "http://124.193.165.208/vlive.qqvideo.tc.qq.com/",
"vt": 203
},
{
"dt": 2,
"dtc": 10,
"url": "http://124.193.165.209/vlive.qqvideo.tc.qq.com/",
"vt": 203
},
{
"dt": 2,
"dtc": 10,
"url": "http://124.193.165.210/vlive.qqvideo.tc.qq.com/",
"vt": 203
},
{
"dt": 2,
"dtc": 10,
"url": "http://video.dispatch.tc.qq.com/27099043/",
"vt": 0
}
]
},
"vh": 720,
"vid": "y00221a60w7",
"videotype": 2,
"vst": 2,
"vw": 1280
}
]
}
}
我们感兴趣的有三个列表:fi列表、ci列表、ui列表。
- ui列表中的url是视频真实地址的前缀,选择ui列表第一个元素中的url即可。
- fi列表列出了各个视频码流,每一项中的id是码流的编号,这个参数在后面会用到。
- ci列表列出了各个分段的相关信息,各个分段信息中的keyid在后面会用到。
请求getkey接口
同样,在网络请求监测中发现getkey接口的请求是这样的:
http://h5vv.video.qq.com/getkey?callback=txplayerJsonpCallBack_getkey_931033&&otype=json&vid=y00221a60w7&format=10401&filename=y00221a60w7.p401.4.mp4&platform=10901&vt=203&charge=0&_rnd=1479015483148&_=1479015476641
构造参数如下:
params = {
'otype': 'json',
'vid': 'y00221a60w7',
'format': 10401,
'filename': 'y00221a60w7.p401.4.mp4',
'platform': 10901,
'vt': 217,
'charge': 0,
}
参数中的vid为视频ID,format为码流的编号,filename根据分段信息中的keyid得来。以第四个分段为例,说说如何构造filename参数。第四个分段信息中的keyid为y00221a60w7.10401.4
,我们将keyid中间的.10
替换为.p
,然后在末尾加上.mp4
即可。
getkey接口的请求结果示例如下:
{
"br": 125315.14,
"ct": 21600,
"filename": "y00221a60w7.p401.mp4",
"key": "AE6DC4B022C2A29C59D1A8E942787A2A54F64A5ABFCA7C99B51BD6539703D4F745DD2D77C3433ACAF1961BBFB6D84C1C717D23BEDCAF4DABC0D8BA2229F6C3464F59F0A10C5ED4CC25E355D9171DC65D411D6834BCA2DECD",
"keyid": "y00221a60w7.10401.4",
"level": 0,
"levelvalid": 1,
"s": "o",
"sp": 0,
"sr": 0
}
看!key粗来了。
构造视频真实地址
通过网络监测发现视频真实地址是像这样的:
http://60.206.195.15/vlive.qqvideo.tc.qq.com/y00221a60w7.p401.4.mp4?sdtfrom=v1010&guid=29a06bf3852fbe2ea6eb53829c3878fa&vkey=6C5D63159598E6D217BA73F6F3335C0B80CECE2A4E889AFCDD8A391DB9C648059731AE9AD47BDA03B016F76E8B59D9DF0C2373CA32A4ADB935AEE0FE73ECE1C460DC01F6B733A5F38035AC289C44721F606C1ADF5AED4267
分析该地址的构造,不难发现,地址前缀在前面的ui列表中已经得到了,filename也计算出来了,vkey参数就是上面得到的key.
Python代码示例
import requests
import json
vid = 'y00221a60w7' # replace with your vid
for definition in ('shd', 'hd', 'sd'):
params = {
'isHLS': False,
'charge': 0,
'vid': vid,
'defn': definition,
'defnpayver': 1,
'otype': 'json',
'platform': 10901,
'sdtfrom': 'v1010',
'host': 'v.qq.com',
'fhdswitch': 0,
'show1080p': 1,
}
r = requests.get('http://h5vv.video.qq.com/getinfo', params=params)
data = json.loads(r.content[len('QZOutputJson='):-1])
url_prefix = data['vl']['vi'][0]['ul']['ui'][0]['url']
for stream in data['fl']['fi']:
if stream['name'] != definition:
continue
stream_id = stream['id']
urls = []
for d in data['vl']['vi'][0]['cl']['ci']:
keyid = d['keyid']
filename = keyid.replace('.10', '.p', 1) + '.mp4'
params = {
'otype': 'json',
'vid': vid,
'format': stream_id,
'filename': filename,
'platform': 10901,
'vt': 217,
'charge': 0,
}
r = requests.get('http://h5vv.video.qq.com/getkey', params=params)
data = json.loads(r.content[len('QZOutputJson='):-1])
url = '%s/%s?sdtfrom=v1010&vkey=%s' % (url_prefix, filename, data['key'])
urls.append(url)
print 'stream:', stream['name']
for url in urls:
print url
运行输出如下:
stream: shd
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.1.mp4?sdtfrom=v1010&vkey=539A9C083D166365C28AFDD0A858C40FC53B82044321F0DC3117D11CDAEAB12FABC79042408ED04502D2EB26C2CFDBB6B3B550888DC2E6F92A4B7897CBE3430BDF4E753BF67D27972208A1FDFD15486D612AB3A9E985F0D3
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.2.mp4?sdtfrom=v1010&vkey=D9041825DC880EE7665E7EEBD0731093A2393590172810A3DA8473126E7E02779ED07F608107B5E49F08580DA6CE63BF2FBF38E737C0F651BCB6FA5929E70D14E86EDC36B9CB1109553D57C1CD3E1282CF62C0DE0BD0B3B8
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.3.mp4?sdtfrom=v1010&vkey=E4FD79F9EF72E97BD2263DC7E7BF2FE6EC8C64560E691680C7474E5820730BD679D01E36E03AE7758AADAE900DDDA6CE8CAB0E6334913297FD7E47A28AC6EECA64BBB843652AAE6BB7CEC0E9B27F3EAF00423E2171C9C805
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.4.mp4?sdtfrom=v1010&vkey=EBEC5493738D777E1F0CC301DE464B3C86A9A8F795C6B9EC16D11E37C4C4858D00A5C50F7B93F6FFFAD11E33393525B41F7E637FAFC1E0466426A2ED83312D8B7BF32AFAAABFA80A306EDA1052FC8916C05D715B97BDB7B3
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.5.mp4?sdtfrom=v1010&vkey=86B99347160E24D4CE9602F0C7BE2413873CF07C9404BF7D543630F2AB52626B5E2F320989EB394F242613749F6BB605507DFBC781880D2455121B038FE83345484393E03A93C6974F22EED1461219AD5D2BA2E53E10E203
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.6.mp4?sdtfrom=v1010&vkey=C36989A32739197FE18F3DECE39A2D0F602D84AB5024FD822DFE184FDC26C18F086AA8BB195C670BBE2616C54ABB24DEB3B2AFB7D7EF8D50ACA77220750EEEB1C4AEF151098E1AAA5E903982F2F097A0B63BDF382E213243
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.7.mp4?sdtfrom=v1010&vkey=2A87824E55E660ACAE20802CFAB9D54A5C4A244EDC194B3424D5DEF7D391F0D9E50DD0D741A3DFA169CA533436F99E9817394FE66E12ADD64AE3B18F75069C3F3B2C6D83CB2E32B4A545DBEDF139DE23A0F03A1B1606B2D2
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.8.mp4?sdtfrom=v1010&vkey=7A02829EF2FC539EB3B448108665A100FD2F55920CCD51751FF125CA5E390FE36BDD0FE6256C774E18020A038F1CA35FE1E5BF06CBCB93E9E57E39EC486300E590E804868355AC77265AE057FFDB8DC799AE2453EC588844
http://124.193.165.208/vlive.qqvideo.tc.qq.com//y00221a60w7.p401.9.mp4?sdtfrom=v1010&vkey=91AAB3F5A6C93BCA628FCBE710280F032591DE6C85DB069582C2AB6ABA1F30096A3B4EAEC750C8807B422D1FCC1FC8B18C98B056A1F4B9FCD5371DEA4F47130530D902FE95647FEE70F98C9D86AE89E96AB6688DB5200226
stream: hd
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.1.mp4?sdtfrom=v1010&vkey=E27946F5763CD1A7B3BFDDE1DC17EBF9F65CC6767D70E1E7D57E34556C2558A8ABCE6D9FD16F812CEEC46D788474F6C820421D9B97C0EC2D689439991AA314990FE50C1648E5419CF38FAA11FC71460EA669EABB347B77EC
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.2.mp4?sdtfrom=v1010&vkey=A937071AAD7AEF30C86817F88A12699C26921D3058329069CEC4D10F91669BAE9246DC60DC7A8DBD159AA7C1EDABF3DCC47113BC25AF38200A9D2636D2782F4399319BFAAC152C0081AAEC11594D58153F4B33ADA4F810F5
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.3.mp4?sdtfrom=v1010&vkey=ECF097D838E75DF1D85FF40F037022BD54C53515F31C45F36076DAA2951D2002E367577015171E29D3B012B0F6355673871AC1902A849F43B56FA0C5154CF871B454EEC46830700126654B7F3CC3955B27F5180D1028984F
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.4.mp4?sdtfrom=v1010&vkey=1F222CC2857D9D0B6B259B4A657FBCE278E87DAEC79AE15C9A78A84093D68DD68172C2AEED25C23F54C373A44B6CB0003F97ADAA4591CA556839348C5135975F3B7C223346384AE476392D373FBA66BD4026C1F76D7D6BDD
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.5.mp4?sdtfrom=v1010&vkey=35CFC97BBA528A56B63B868C1E0FDBF63DA80DEFB2E82DE5F9ECD723BA2900379565E1A25AB52F8079C9392B6FCE1C4C05A385066857AB03B08B1502818CECBCF919890CD64C96B0260E0E441BBE73F643AD7DF51523A30C
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.6.mp4?sdtfrom=v1010&vkey=4C66C574DE904ADC8C348540CDEAC961A0EBE6E63759E8AD8E6F9BAC6F57A2CB7E66161376C70AAF7A44ECCFE1849EB485E0F3151B814F86B7FDC6E2146954F066EE2DB1CA9916C84CF2C033358DFC2F7437373697C161D3
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.7.mp4?sdtfrom=v1010&vkey=68D340AD704C1E8D1DB969F5CBB37448D918CEDBAD774147E0AF3E46168707FF37FDC4F8245259BF8B2DF70DBBEEE717CC161A06867B0C45C51D638C6034046DF9DA71842507CDECCDDBF13B949DFE984DA8EFF818470BF5
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.8.mp4?sdtfrom=v1010&vkey=71AE0C8C193091ECC938ABE73325C50C3A415025DCA213797C73371A68947DA7BCD9F76CBEE1098FBD328A352C32BE80F0BCED45869A908AAF51DA780AEE9523B29BAF0CAB388AF194EA72C69D6BAA679DB0EF2385A1E17D
http://124.193.230.15/vlive.qqvideo.tc.qq.com//y00221a60w7.p412.9.mp4?sdtfrom=v1010&vkey=393D1585DFAEEF8259EE5408C864AD9022FCFB33A8A937013E614F53129AEF12D46162893DC7804CBBB38558E90FD72D0914D08450C08536D15637DD143BD054CF002766A80C989AE583B2CFC39BC308DC54D9C0E9D66F10
stream: sd
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.1.mp4?sdtfrom=v1010&vkey=56E9F7C96D6FFD3394017519AF0C09B560536F3918B19BFB2B94FBDDBBA07D2ED14185908C5D459AC1F722A52AC35193B5FB8D1ECDC2663DE03EF106F8AD2B37332361A10E5F3CDCF4EA3A8018A08ACF59E230DEFACF7864
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.2.mp4?sdtfrom=v1010&vkey=72EEDB6A0631AFC0F8439FDD31BECA0AEBC2EF496F7B5F5D32693C2F1F6F8768468CDD1A434181552CAD6276205A3C2C0ACBEA1B13A5A1C9CB7A9986170E402D77219A271C86797F3704155B9426D6BEF1134445BC9F02B6
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.3.mp4?sdtfrom=v1010&vkey=7FD8C0EEC450673A18F72E2616D1F9EEB120F384A1E392FBDFBDA6E60A82F9B5292A77D6C3325C596A6058FE145E11A37E244150A4884F491627D50826A55E432BCC49CAC8B75350C4FADEDB7613CE66DF0628ADB0EBDED5
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.4.mp4?sdtfrom=v1010&vkey=8F677851AF4261295A84C69478D961816CC5C92E9B42495D8E0BDBF35B96C7F0D2AA688B6956011E5ED6A933764F9130A0B73215A23FBA083433123F161AEF447400E1BD8D450665E7278561D3284BE2EB0819D9C47DDAB3
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.5.mp4?sdtfrom=v1010&vkey=17FC7F5BF0D3B66E2C6F99C17617EBBE79ADE0B94C89BAF2FE06EE086829669D89D6A31EBB094FB4F8CA731C5E5B55823948F565B815AB2E37D9CDE294812687B76922A0DACBFA2DCA94D6EE6D6E64BE188F605537918FCF
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.6.mp4?sdtfrom=v1010&vkey=73CD3396A1FD375A1E03D11662A28EEF160B48FE45CCBB21F730C3CCC46D7FC4EA1EF02C784D30BBCAFD68453841A55CCC318FEBB55E555F2ADE1F093997ED256B2F68E1BF81A4AA35F63EDF330E733552899D868C02D960
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.7.mp4?sdtfrom=v1010&vkey=3CABA633B9235147A6B12D48AB97E23CA279B9DE1ED3F56D2D1408333A09AF2691BE540E5CA844D819045A7FCE44988692C9D8E330C718C904500B09390F90E6939C789544A3592361A1E756981892D27459065377FFA8B1
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.8.mp4?sdtfrom=v1010&vkey=097BB6E06309CED825B05AAFA361B16888D351D8C4EFE75BABA25D216F3271464447C5C54B378DC25A0AFD7B15740F2A071E03310647D7EB8744EE6DF99DCFB736CCB086E3F7D52E87FB0DF0A73EFF74C8D22947CB9476D7
http://124.193.230.156/vlive.qqvideo.tc.qq.com//y00221a60w7.p403.9.mp4?sdtfrom=v1010&vkey=1E1174EEF8848D4C1B5823C41357D8DB822AF848E74DDA112546D59BAD71AF7B9D10AB2127A90F0CD76FCA1FE5E6011E087CC3DF9D996552DDBE29EB08903639DF94F2ED8B52C8807B6FA3521E4D7CC96B2A6A7A7782C052
作者:Maslino
链接:https://www.jianshu.com/p/eae2b7077e04
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。