Skip to content

Commit 62ca318

Browse files
authored
Create douyin.py
1 parent 0896740 commit 62ca318

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

moumoubaimifan/douyin/douyin.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import requests
2+
import json
3+
import os
4+
import time
5+
import re
6+
7+
headers = {
8+
"user-agent": "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Mobile Safari/537.36"
9+
}
10+
11+
share = input('分享的链接:')
12+
13+
url = re.findall('(https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]+)', share)[0]
14+
15+
16+
resp = requests.get(url=url, headers=headers, allow_redirects=False)
17+
18+
location = resp.headers['location']
19+
20+
temp = location.split('&')
21+
22+
sec_uid = temp[4].split('=')[1]
23+
24+
url = "https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid={}".format(sec_uid)
25+
resp = requests.get(url, headers=headers)
26+
userinfo = json.loads(resp.text)
27+
28+
name = userinfo['user_info']['nickname']
29+
30+
if os.path.exists(name) == False:
31+
os.mkdir(name)
32+
os.chdir(name)
33+
34+
35+
year = [2020,2021,2022]
36+
cursor = []
37+
for y in year:
38+
for i in range(1,13):
39+
calc = str(y) + '-'+ str(i) + '-' + '01 00:00:00'
40+
timeArray = time.strptime(calc, "%Y-%m-%d %H:%M:%S")
41+
timeStamp = int(time.mktime(timeArray)) * 1000
42+
cursor.append(timeStamp)
43+
44+
for i in range(len(cursor) - 1):
45+
params = {
46+
"sec_uid": sec_uid,
47+
"count": 200,
48+
"min_cursor": cursor[i],
49+
"max_cursor": cursor[i+1],
50+
"_signature": "Sq1xlgAAK2.rxFYl7oQq7EqtcY"
51+
}
52+
53+
url = 'https://www.iesdouyin.com/web/api/v2/aweme/post/?'
54+
55+
resp = requests.get(url=url, params=params, headers=headers)
56+
data = json.loads(resp.text)
57+
awemenum = data['aweme_list']
58+
for item in awemenum:
59+
title = re.sub('[\/:*?"<>|]','-',item['desc'])
60+
url = item['video']['play_addr']['url_list'][0]
61+
62+
with open(title + ".mp4", 'wb') as f:
63+
f.write(requests.get(url, headers=headers).content)
64+
print(title + "------------------下载完成")

0 commit comments

Comments
 (0)