可以通过一个抖音作品分享地址一键下载无水印分享视频,代码不复杂很容易看懂import requests
import json
import emoji
requests.packages.urllib3.disable_warnings()
HEADERS3 = {'accept-encoding': 'gzip, deflate, br','accept-language': 'zh-CN,zh;q=0.9','pragma': 'no-cache','cache-control': 'no-cache','upgrade-insecure-requests': '1','user-agent': "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36"}
def getRealPlayAddress(url):
res = requests.get(url, headers=HEADERS3, allow_redirects=False)
if res.status_code == 302:
long_url = res.headers['Location']
return long_url
return None
def praseDouyinLong_v4(url):
try:
url = getRealPlayAddress(url)
webResponse = requests.get(url, headers=HEADERS3,verify=False).text
dytk = webResponse.split('dytk: "')[1].split('" });')[0]
item_id = url.split('/')[5]
webResponse = requests.get('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=%s&dytk=%s'%(item_id, dytk), headers=HEADERS3,verify=False).text
mJson = json.loads(webResponse)
video_title = mJson['item_list'][0]['desc'].replace("@","-").replace("~","-").replace("*","-").replace(",","-").replace(":","-").replace(":","-").replace("#","-").replace(",","-").replace("。","-").replace(".","-").replace("&","-").replace("%","-").replace("$","-").replace("¥","-").replace("!","-").replace("!","-").replace(" ","-").replace("\n","").replace('"','‘').replace("'","‘").replace("?","?")
video_title = emoji.demojize(video_title).replace(":",":").replace(" ","")
if video_title == '':
video_title = '无标题' item_id
videoUrl = mJson['item_list'][0]['video']['play_addr']['url_list'][0]
videoUrl = getRealPlayAddress(videoUrl)
return '{"video_title":"%s","video_url":"%s"}'%(video_title,videoUrl)
except:
return '{"msg":"视频可能已被删除"}'
评论