抖音去水印下载python源码+工具
python源码:
import requests import re import json import os 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) print('%s 下载完成!' % name_vidObj['file_name']) 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 = input('输入抖音url短链: ') if url != '': break getVideo.url = url try: getVideo.down_video(getVideo.get_video_info()) print('\n') except: print('错误的分享链接,或该接口失效\n') input('按任意键重试\n') os.system('cls')
打开之后按提示输入抖音视频的url短链,格式为 https://v.douyin.com/XXXXXXX/
短链在APP端点分享,里面有链接分享,那个分享链接就是抖音短链
按回车即可下载到当前目录下。文件名按照抖音视频名命名:
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载无数据或打开不了?
- 有可能是因为百度网盘受到风控有敏感内容被删除了 ,如遇到此类问题请及时联系站长!
- 找不到素材资源介绍文章里的示例图片?
- 对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。