直接上代码
import requests
import json
import easygui
from tkinter import messagebox
from tkinter import *
top = Tk()
top.withdraw()
class douyin_video():
def __init__(self):
self.headers = {
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8,
Accept-Encoding: gzip, deflate, sdch, br,
Accept-Language: zh-CN,zh;q=0.8,
Connection: keep-alive,
Upgrade-Insecure-Requests: 1,
user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Mobile Safari/537.36
}
self.url =
def get_video_info(self):
video_id = re.search(video/.*?/, get_local_url(headers=self.headers, url=self.url)).group().replace(video/,
).replace(
/, )
url = https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids= + video_id
res = requests.get(url=url)
data = json.loads(res.content)[item_list][0]
return {
file_name: validateTitle(data[desc]),
vid: data[video][vid]
}
def down_video(self, name_vidObj):
url = https://aweme.snssdk.com/aweme/v1/play/?video_id=%s&ratio=720p&line=0 % name_vidObj[vid]
video_url = get_local_url(url=url, headers=self.headers)
res = requests.get(url=video_url)
with open(name_vidObj[file_name] + .mp4, wb) as f:
f.write(res.content)
messagebox.showinfo("提示", "下载完成")
def get_local_url(url, headers):
html = requests.get(url, headers=headers, allow_redirects=False)
return html.headers[Location]
def validateTitle(title):
rstr = r"[/\:*?"<>|]" # / : * ? " < > |
new_title = re.sub(rstr, "_", title) # 替换为下划线
return new_title
if __name__ == __main__:
getVideo = douyin_video()
# while True:
while True:
url = str(easygui.multenterbox(抖音水印去除, 一蓑烟雨任平生,
fields=[这里输入抖音视频地址链接(抖音中分享链接获取)],
values=[])[0])
if url != :
break
getVideo.url = url
try:
getVideo.down_video(getVideo.get_video_info())
print(
)
except:
messagebox.showwarning("提示", "错误的分享链接,或该接口失效")
效果
完事