以下是Python抖音视频去水印的方法:
```python
import requests
import re
import json
import os
import sys
import time
import tkinter as tk
from tkinter import filedialog
def get_video_url(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
res = requests.get(url, headers=headers)
if res.status_code == 200:
playwm_url = re.findall(r'playAddr: "(.*?)"', res.text)
if playwm_url:
video_url = playwm_url[0].encode('utf-8').decode('unicode_escape')
return video_url
def download_video(url, file_path):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
res = requests.get(url, headers=headers, stream=True)
total_size = int(res.headers['Content-Length'])
if res.status_code == 200:
label.config(text='文件大小:' + str(round(total_size / 1024 / 1024, 2)) + 'MB')
with open(file_path, 'wb') as f:
for chunk in res.iter_content(chunk_size=1024):
f.write(chunk)
f.flush()
progress['value'] += len(chunk)
root.update()
else:
label.config(text='下载失败')
def get_video_info(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
res = requests.get(url, headers=headers)
if res.status_code == 200:
video_info = re.findall(r'<script>tac=(.*?)</script>', res.text)
if video_info:
tac = video_info[0]
video_info_url = 'http://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' + re.findall(r'itemId: "(.*?)"', tac)[0]
res = requests.get(video_info_url, headers=headers)
if res.status_code == 200:
video_info = json.loads(res.text)
return video_info['item_list'][0]['desc']
def download():
url = entry.get()
video_url = get_video_url(url)
if video_url:
file_name = get_video_info(url) + '.mp4'
file_path = os.path.join(path, file_name)
download_video(video_url, file_path)
label.config(text='下载完成')
else:
label.config(text='解析失败')
def select_path():
global path
path = filedialog.askdirectory()
path_label.config(text=path)
root = tk.Tk()
root.title('抖音去水印')
root.geometry('400x200')
label = tk.Label(root, text='请输入抖音视频链接', font=('微软雅黑', 12))
label.pack(pady=10)
entry = tk.Entry(root, font=('微软雅黑', 12))
entry.pack(pady=10)
button = tk.Button(root, text='下载', font=('微软雅黑', 12), command=download)
button.pack(pady=10)
path_button = tk.Button(root, text='选择保存路径', font=('微软雅黑', 12), command=select_path)
path_button.pack(pady=10)
path_label = tk.Label(root, text='请选择保存路径', font=('微软雅黑', 12))
path_label.pack(pady=10)
progress = tk.ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=10)
root.mainloop()
```