小程序播放优酷和腾讯视频

发布: 2019-07-30 22:26:55 标签: 小程序

小程序播放优酷和腾讯视频

解析出播放地址,直接通过video进行播放

解析优酷视频方法

01// const url = 'https://v.youku.com/v_show/id_XNDI2OTM5MTExNg==.html'
02
03export function getYoukuVideoSrc(url) {
04 let key = url.split('.html')[0]
05 if (!key) return Promise.reject('解析失败')
06 key = key[key.length - 1].split('_')[1]
07
08 return new Promise(resolve => {
09 const apiUrl = `https://ups.youku.com/ups/get.json?vid=${key}&ccode=0405&client_ip=192.168.1.1&utid=7wNNESOeQS4CAXzP1pKImliK&client_ts=1499075140&r=bBLxVq7VfU4hVT%2BCjmrY20kogZckZZr%2FWdDwtoNBVjuXY5QTXYJPD7OxqmUWFe1c`
10 wx.request({
11 url: apiUrl,
12 success(res) {
13 const { data } = res.data
14 resolve({
15 src: data.stream[0].segs[0].cdn_url,
16 poster: data.video.logo
17 })
18 }
19 })
20 })
21}
22
复制代码

解析腾讯视频方法

01// const url = 'https://v.qq.com/x/page/t09052dfpvm.html' //腾讯视频地址 请替换
02
03export function getQQVideoSrc(url) {
04 if (!url.includes('v.qq.com')) return ''
05 const key = url.match(/http(s?):\/\/(.+?)\/(\w+?).html/)
06 if (!(key && key[3])) return ''
07
08 return new Promise(resolve => {
09 wx.request({
10 url: `https://h5vv.video.qq.com/getinfo?otype=json&platform=11001&sphttps=1&vid=${
11 key[3]
12 }`,
13 success({ data }) {
14 const ret = JSON.parse(data.slice(13, data.length - 1))
15 resolve({
16 src: `${ret.vl.vi[0].ul.ui[0].url}${ret.vl.vi[0].fn}?vkey=${
17 ret.vl.vi[0].fvkey
18 }`,
19 poster: `https://puui.qpic.cn/qqvideo_ori/0/${key[3]}_496_280/0`
20 })
21 }
22 })
23 })
24}
25
复制代码