[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
"""
<获取腾讯视频播放列表>:<get_video_list>
<根据播放地址中的id,再拼接接口地址,批量获取该视频播放列表url(非视频源url)>
:copyright: (c) 2020 by debris.
:license: GPLv3, see LICENSE File for more details.
"""
import json
import requests
# http://s.video.qq.com/get_playsource?id=mzc00200db1ddbp&plat=2&type=1&data_type=2&video_type=3&plname=&otype=json&num_mod_cnt=20&callback=_jsonp_0_6914&_t=1474533056089
# 1)先获取视频vid集:
# API: https://access.video.qq.com/fcgi/PlayVidListReq?raw=1&vappid=17174171&vsecret=a06edbd9da3f08db096edab821b3acf3c27ee46e6d57c2fa&page_size=100&type=4&cid=[cid]
# 使用示例:https://access.video.qq.com/fcgi/PlayVidListReq?raw=1&vappid=17174171&vsecret=a06edbd9da3f08db096edab821b3acf3c27ee46e6d57c2fa&page_size=100&type=4&cid=mzc00200064yp7j
#
# 参数 必选填 示例 备注
# raw 必填 1 不可改
# vappid 必填 17174171 不可改
# vsecret 必填 a06edbd9da3f08db096edab821b3acf3c27ee46e6d57c2fa 浏览器获取
# page_size 必填 100 最高100
# type 必填 4 1,3,4
# cid 必填 mzc00200064yp7j
# 2)根据1)获取的vid集请求具体信息:
# API: https://union.video.qq.com/fcgi-bin/data?otype=json&tid=682&appid=20001238&appkey=6c03bbe9658448a4&union_platform=1&idlist=[请求的vid数组,以逗号隔开]&callback=jQuery1910506375746774991_1594126070664&_=1594126070672
# 使用示例:https://union.video.qq.com/fcgi-bin/data?otype=json&tid=682&appid=20001238&appkey=6c03bbe9658448a4&union_platform=1&idlist=n0034g18ry0,b0034rwc2bq,p0034580q2o,z003445xj4x&callback=jQuery1910506375746774991_1594126070664&_=1594126070672
#
# 参数 必选填 示例 备注
# otype 必填 json
# tid 必填 682
# appid 必填 20001238
# appkey 必填 6c03bbe9658448a4
# union_platform 必填 1
# idlist 必填 n0034g18ry0,b0034rwc2bq,p0034580q2o,z003445xj4x
# callback 选填 jQuery1910506375746774991_1594126070664
# _ 必填 1594126070672
video_id = input('请输入腾讯视频ID:')
# video_id = 'mzc00200db1ddbp'
video_api_url = 'http://s.video.qq.com/get_playsource?id='+video_id+'&plat=2&type=1&data_type=2&video_type=3&plname=&otype=json&num_mod_cnt=20&_t=1474533056089'
print(video_api_url)
HEADERS = {
"Content-Type": "application/json ;charset=utf-8 "
}
req = requests.get(video_api_url,headers=HEADERS)
url_code = req.text
#对内容进行切分
url_code = url_code[len("QZOutputJson="):len(url_code)-1]
# print(type(url_code))
doc = json.loads(url_code)
videoPlayList = doc["playlist"][0]["videoPlayList"]
#方法一
for playInfo in videoPlayList:
# #免费观看列表
# if playInfo["markLabelList"] == []:
# print('第%s集' % (playInfo["episode_number"]) + '$' + playInfo["playUrl"])
# #vip观看列表
# for labelist in playInfo["markLabelList"]:
# if labelist['primeText'] == '预告':
# break
# print('第%s集' % (playInfo["episode_number"]) + '$' + playInfo["playUrl"])
markLabel=playInfo["markLabelList"]
# # 如果markLabelList不是一个空的列表,那么获取第一个列表元素中的primeText的值和"预告"做对比,如果相同,那么跳过此次循环`
if len(markLabel) > 0 and markLabel[0]["primeText"]=="预告":
continue
print('第%s集' % (playInfo["episode_number"]) + '$' + playInfo["playUrl"]+ "#")
# #方法二
# playlist=[]
# for playInfo in videoPlayList:
# # 如果markLabelList不是一个空的列表,那么获取第一个列表元素中的primeText的值和"预告"做对比,如果相同,那么跳过此次循环
# markLabel=playInfo["markLabelList"]
# if len(markLabel)>0 and markLabel[0]["primeText"]=="预告":
# continue
# result = {}
# result["episode_number"] = playInfo["episode_number"]
# result["playUrl"] = playInfo["playUrl"]
# playlist.append(result)
# print(playlist)
|