解析并下载抖音无水印视频

Python
技之树 2021-9-16

2240 1

图示

img

代码

# 抖音无水印下载
# 这里用到的API本来是可以直接下载的,但由于接口修改,从2021年7朋26日起已经不能使用,我作了简单处理,仍能获得下载地址

import re, json, requests
from tqdm import tqdm # 打印进度条的库
from urllib.request import urlopen
import urllib

#已经修改改为直接输入抖音带文字的分享链接即可。
inp0 = input('请输入复制的抖音分享链接:')  # 如:https://v.douyin.com/JVFp8r5/,当然,抖音分享出来的带有文字的也直接复制进来就行的。
inp = re.findall('https://v.douyin.com/.*?/', inp0)[0]  # 链接解析
# inp = 'https://v.douyin.com/' + inp +'/'
# inp = 'https://v.douyin.com/ewGMnvH/'
print('短视频实际地址是:' + inp +'。现在开始解析。')
# exit()
url = re.findall('https://v.douyin.com/.*?/', inp)[0]  # 链接解析
res = requests.get(url)
res = res.url
# print(res)
# exit()
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(url=res, headers=headers)
website = urlopen(req,timeout = 90)
html = website.read().decode('utf-8')
vid = re.findall('"https://www.douyin.com/video/(.*?)"/', html)[0]
# print(vid)
# exit()
# [0]  # vid解析,vid就是视频id,是我自己定义的
api = f'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={vid}' # 调用api
print('api接口地址是:' + api)
# exit()
# res = requests.get(api).json()
# print(res)
# exit()
print('正在解析视频下载地址,请稍候......')
req = urllib.request.Request(url=api, headers=headers)
website = urlopen(req,timeout = 90)
html = website.read().decode('utf-8')
# print(type(html))
# print(html)
res=json.loads(html)

# exit()

url = res['item_list'][0]['video']['play_addr']['url_list'][0]  # 视频下载链接解析
url = url.replace('/playwm/', '/play/')  # 去水印
res = requests.get(url, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{vid}.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):\
         f.write(chunk)
     print('下载完成。')

素材来源:吾爱破解

这家伙太懒了,什么也没留下。
最新回复 (1)
  • 筑基入门 小生不才
    0 2
    感谢分享
    这家伙太懒了,什么也没留下。
    2021-12-3 回复
    • YiOVE论坛
      3
         
返回