1. Background
Because video playback was required at that time, it was unrealistic to store video files in the background. So, I made a small program that can parse the Tencent video address and play the video.
2. Introduction
The code for parsing Tencent video address in the applet is written with reference to an open source project you-get , and the python code downloaded by Tencent video is written as JS code.
3. Where to get Tencent Video ID
1. Generally, when playing a Tencent video, the playback address is https://v.qq.com/x/page/w0647n5294g.html
. The string between the .html
last one is the Tencent Video id. /
For example https://v.qq.com/x/page/w0647n5294g.html
, the id is w0647n5294g
.
4. Get the real playback address of Tencent Video
Divided into the following two steps
- 1 Get video information
and pass Tencent Video ID to the following function
getVideoInfo: function (vid) { var that = this; var urlString = 'https://vv.video.qq.com/getinfo?otype=json&appver=3.2.19.333&platform=11&defnpayver=1&vid=' + vid; wx.request({ url: urlString, success: function (res) { var dataJson = res.data.replace(/QZOutputJson=/, '') + "qwe"; var dataJson1 = dataJson.replace(/;qwe/, ''); var data = JSON.parse(dataJson1); var fn_pre = data.vl.vi[0].lnk host = data ['vl'] ['vi'] [0] ['ul'] ['ui'] [0] ['url' ] var streams = data ['fl'] ['fi' ] var seg_cnt = data ['vl'] ['vi'] [0] ['cl'] ['fc' ] if (parseInt (seg_cnt) == 0 ) { seg_cnt = 1 } var best_quality = streams[streams.length - 1]['name'] var part_format_id = streams[streams.length - 1]['id'] for (var i = 1; i < (seg_cnt + 1); i++) { var filename = fn_pre + '.p' + (part_format_id % 10000) + '.' + i + '.mp4'; console.log(filename); pageArr.push(i); that.requestVideoUrls(part_format_id, vid, filename, 'index' + i); } } }) },
- 2 Parse the real playback address of the video according to the video information
requestVideoUrls: function (part_format_id, vid, fileName, index) { var keyApi = "https://vv.video.qq.com/getkey?otype=json&platform=11&format=" + part_format_id + "&vid=" + vid + "&filename=" + fileName + "&appver=3.2.19.333" var that = this; wx.request({ url: keyApi, success: function (res) { var dataJson = res.data.replace(/QZOutputJson=/, '') + "qwe"; var dataJson1 = dataJson.replace(/;qwe/, ''); var data = JSON.parse(dataJson1); if (data.key != undefined) { var vkey = data['key'] var url = host + fileName + '?vkey=' + vkey; part_urls[index] = String(url) that.setData({ videoUrl: part_urls.index1 }); } } }) },
Inside this function is part_urls.index1
the real address of Tencent Video. Put this address in the video component of the applet src
to play the video on Tencent.
Finally put the demo: weChatVideoPlay