[学习记录] 抖音去水印[根据分享链接解析] :https://www.52pojie.cn/thread-1694573-1-1.html
实现代码
"""
* @创建时间: 2022/12/15 16:46
* @软件版本: V1.0
* @脚本用途: python抖音无水印视频解析下载
* @思路来源:https://www.52pojie.cn/thread-1694573-1-1.html
"""
import requests
import re
def get_url(url):
header = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
}
response = requests.get(url=url, headers=header)
response.encoding = "utf-8"
video_id = re.search(r"\d+", response.request.url).group()
video_json = f"https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={video_id}"
response_json = requests.get(url=video_json, headers=header)
dic = response_json.json()
item_list = dic['item_list']
for item in item_list:
# 获取视频无水印链接方法1:提取vid直接拼接法
# vid = item['video']['vid']
# desc = item['desc']
# music_uri = item['music']['play_url']['uri']
# video_url = f"https://aweme.snssdk.com/aweme/v1/play/?video_id={vid}"
# 获取视频无水印链接方法2:提取链接替换法
desc = item['desc']
music_uri = item['music']['play_url']['uri']
video_url = ''.join(item['video']['play_addr']['url_list']).replace("playwm/", "play/")
response_download_mp3 = requests.get(music_uri, headers=header)
response_download_mp4 = requests.get(video_url, headers=header)
with open(desc + ".mp3", mode="wb") as f:
f.write(response_download_mp3.content)
print("音乐写出成功!")
with open(desc + ".mp4", mode="wb") as f:
f.write(response_download_mp4.content)
print("视频写出成功!")
response.close()
print("全部写出成功!")
if __name__ == '__main__':
get_url(input("请输入要下载的抖音视频链接:"))