-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathno_waterMark_video.py
61 lines (47 loc) · 1.75 KB
/
no_waterMark_video.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
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
53
54
55
56
57
58
59
60
61
import requests
import configparser
import os
from requests.packages import urllib3
urllib3.disable_warnings()
def getHeaders( filename, key ):
conf = configparser.ConfigParser()
conf.read( filename );
confDict = dict(conf._sections);
headers = dict(confDict[key]);
return headers;
def parseUrl( url, headers ):
res = requests.get( url, headers=headers, verify=False );
res.encoding = 'utf-8'
data = res.text
cover = data.split("cover: \"")[1].split("\"")[0]
playAddr = data.split("playAddr: \"")[1].split("\",")[0]
videoId = playAddr.split("video_id=")[1].split("&")[0]
videoAddr = playAddr.replace("/playwm/","/play/");
print (videoAddr)
return
return {
"cover": cover,
"playAddr": playAddr,
"addr": videoAddr,
"id": videoId
}
def downVideo( parseDouyin, headers ):
videoBin = requests.get( parseDouyin['addr'], headers=headers, verify=False );
_filename = parseDouyin['id'] + ".mp4";
with open( _filename, "wb") as f:
f.write(videoBin.content)
f.close()
return _filename;
#主函数
if __name__ == '__main__':
print("点击转发抖音视频时,可通过选择复制链接来获取视频链接\n")
url = input("请输入抖音视频url:");
headers = getHeaders( "config.ini", "headers" );
arduinoHeaders = getHeaders( "config.ini", "arduino-headers" );
parseUrl( url, headers);
parseData = parseUrl( url, headers);
print( "视频源地址为:" + parseData['addr'] );
#下载视频
filename = downVideo( parseData, arduinoHeaders );
print( "视频下载完成,", "视频Id为:",parseData['id'], "\n" );
print( "视频保存在当前同级目录下,格式为mp4\n" );