Python: 解析腾讯视频, 下载腾讯视频, 腾讯视频下载解析器, Tencent-Video-Download-Parser

 

腾讯视频下载解析器

这是一个简单的腾讯视频解析器。它支持解析1080p,720p,480p和270p的下载链接。它仅用于研究目的。我不保证将来它仍能正常运作。

 

用法

python tencent-parse.py vid

或者直接用视频地址,格式如: https://v.qq.com/x/cover/[.*]/[vid].html

python tencent-parse.py https://v.qq.com/x/cover/v9nkw4p13uo8xzf/l0870su6p95.html

 

如何获得视频

https://v.qq.com/x/cover/[.*]/[vid].html

vid位置如上所示。(没有括号)

 

如何下载VIP专享视频/电影

您需要在代码中添加cookie。您可以找到添加Cookie字符串的位置的注释。

 

代码

import requests
import json
import sys
import os

if len(sys.argv) != 2:
    print('You must enter only 1 argument (vid)!')
    exit()

vid = sys.argv[1]
vid = os.path.basename(vid).replace('.html', '')

for definition in ('fhd', 'shd', 'hd', 'sd'):
    params = {
        'isHLS': False,
        'charge': 1,
        'vid': vid,
        'defn': definition,
        'defnpayver': 1,
        'otype': 'json',
        'platform': 10901,
        'sdtfrom': 'v1010',
        'host': 'v.qq.com',
        'fhdswitch': 0,
        'show1080p': 1,
    }
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
        'cookie': '', # to download vip-only videos, you must add cookies here after login in the browers.
    }
    r = requests.get('http://h5vv.video.qq.com/getinfo', params=params, headers=headers)
    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, headers=headers)
            data = json.loads(r.content[len('QZOutputJson='):-1])
            try:
                url = '%s/%s?sdtfrom=v1010&vkey=%s' % (url_prefix, filename, data['key'])
            except:
                url = '[ERROR]'
            urls.append(url)
 
        print('stream:' + stream['name'])
        for url in urls:
            print(url)

 

效果图

 

本文:Python: 解析腾讯视频, 下载腾讯视频, Tencent-Video-Download-Parser

One Comment

Leave a Reply