-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path解析抖音视频.py
27 lines (22 loc) · 987 Bytes
/
解析抖音视频.py
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
import requests
from fake_headers import Headers
import re
import json
def get_video(video_url):
headers = Headers(os="mac", headers=True).generate()
req = requests.get(video_url, headers=headers, allow_redirects=True)
# print(req.url) https://www.iesdouyin.com/share/video/6967539188438813983
video_id = re.findall('video\/(\d+)\/', req.url)[0]
data_json = requests.get(f'https://www.iesdouyin.com/web/api/'
f'v2/aweme/iteminfo/?item_ids={video_id}').content
video_addr = json.loads(data_json)['item_list'][0]['video']['play_addr']['url_list'][0]
video_addr = video_addr.replace('playwm', 'play') #去水印
path = f'{video_id}.mp4'
r = requests.get(video_addr, headers=headers, stream=True)
with open(path, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
return path
print("输入需要解析的抖音网址:")
get_video(input())