抖音无水印解析

用py2写的,接口是用http://douyin.qlike.cn/这个网址。

运行效果图:

01

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#coding:utf-8
import requests
import re
from time import sleep
from tqdm import tqdm

def getTrueUrl(url):
headers = {'Content-Length': '242', 'Accept': 'text/html, */*; q=0.01', 'Origin': 'http://douyin.qlike.cn', 'X-Requested-With': 'XMLHttpRequest', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Referer': 'http://douyin.qlike.cn/', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Cookie': '__cfduid=d5e13bae704ad51cb1ab12cba713149631530322436; UM_distinctid=1644e5d4eef294-0da158094412e7-47e1039-144000-1644e5d4ef0253; CNZZDATA1270963628=592940400-1530322553-%7C1530322553; yjs_id=6e020e2353ad5dedae7da59567920371; ctrl_time=1', 'Connection': 'close', }
data = {'url': url}
res = requests.post("http://douyin.qlike.cn/parse.php?app=douyin", data=data, headers=headers)
if "点击下载720P无水印视频".decode('utf-8') in res.text:
p = r'class="btn btn-success btn-sm" href="([^"]+)'
trueUrl = re.findall(p, res.text)
print("解析成功,真实地址为:".decode('utf-8') + trueUrl[0])
Title = getTitle(res.text)
downVideo(Title, trueUrl[0])
else:
print(res.text)

def getTitle(res):
p = r'<span class="label label-primary">(.+)</span>'
title = re.findall(p, res)
return title[1]

def downVideo(Title, trueUrl):
print("正在下载".decode('utf-8') + Title +",骚等".decode('utf-8'))
res = requests.get(trueUrl)
with open(Title+'.mp4', 'wb') as f:
f.write(res.content)
for i in tqdm(range(1, 300)):
sleep(0.01)
print(Title + "下载完成".decode('utf-8'))

if __name__ == '__main__':
text = '''
____ _ _ _
| _ \ _ (_) | | | |
| |_) | _ _ (_) _ ___ ___ | |__| |
| _ < | | | | | | / __|/ _ \| __ |
| |_) || |_| | _ | || (__| __/| | | |
|____/ \__, |(_)|_| \___|\___||_| |_|
__/ |
|___/

'''
print('*' * 50)
print(text + '\033[0m\n')
print('*' * 50)

url = raw_input('input douyin url: ')

getTrueUrl(url)
-------------本文结束感谢您的阅读-------------