菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

解析下载抖音去水印视频的Python方法

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:python教程 抖音去水印 无水印解析 水印去除 python解析 抖音解析

要使用Python下载抖音去水印视频,可以使用第三方库`pydouyin`。首先安装该库:`pip install pydouyin`。然后,编写以下代码: ```python from pydouyin import Douyin def download_video(url, save_path): dy = Douyin() video_info = dy.aweme.get_video_info(url) if video_info: video_id = video_info['item_list'][0]['video']['vid'] dy.aweme.download_video(video_id, save_path) print(f"视频已保存到 {save_path}") else: print("无法解析视频信息") if __name__ == "__main__": douyin_url = input("请

importreimporttimeimportrequeststemp_data={'headers':{'User-Agent':'Mozilla/5.0(Linux;Android10;ONEPLUSA6000Build/QKQ1.190716.003;wv)AppleWebKit/537.36(KHTML,likeGecko)Version/4.0Chrome/81.0.4044.138MobileSafari/537.36aweme_170401JsSdk/1.0NetType/WIFIChannel/updateAppName/awemeapp_version/17.4.0ByteLocale/zh-CNRegion/CNAppTheme/lightSystemFontScale/1.0BytedanceWebview/d8a21c6'}}#取视频IDdefGetVideo(Str_url):#正则取文本内网址patt=re.compile(r'(((https?|ftp|file)://|)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])',re.S)data=patt.findall(Str_url)[3][0]if'v.douyin.com'indata:try:res=requests.get(data,headers=temp_data['headers'],allow_redirects=False)exceptNone:temp_data['GetVideo']=Falseelse:Location=res.headers['Location']if'www.douyin.com/404'inLocation:temp_data['GetVideo']=Falseelse:#取视频IDvideo_id=re.search('d{19}/',Location)[0].replace("/","")temp_data['GetVideo']=video_idelse:temp_data['GetVideo']=False#获取无水印视频地址defanalysis_url(video_id):try:res=requests.get('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/',headers=temp_data['headers'],params={'item_ids':video_id}).json()exceptNone:temp_data['analysis_url']=Falseelse:ifres['status_code']==0:play_url=res['item_list'][0]['video']['vid']temp_data['analysis_url']='https://aweme.snssdk.com/aweme/v1/play/?video_id={video_id}&ratio=1080p&line=0'.format(video_id=play_url)else:temp_data['analysis_url']=False#下载无水印视频defdown_video(video_url):try:res=requests.get(video_url,headers=temp_data['headers']).contentexceptNone:temp_data['down_video']=Falseelse:withopen('{time}.mp4'.format(time=int(time.time())),'wb')asf:f.write(res)temp_data['down_video']=Trueif__name__=='__main__':share_url='6.92OxF:/好TMD真实https://v.douyin.com/dBVkpXo/复制此链接,打开Dou音搜索,直接观看视频!'#获取视频IDGetVideo(share_url)ifnottemp_data['GetVideo']:print("解析视频ID失败")else:#解析无水印视频地址analysis_url(temp_data['GetVideo'])ifnottemp_data['analysis_url']:print('获取视频地址失败')else:#下载视频down_video(temp_data['analysis_url'])ifnottemp_data['down_video']:print('下载视频失败')else:print('视频下载成功!')


相关专题

相关文章

    无相关信息
评论
建站知识
建站知识
使用技巧
调试安装
运营推广