我有一个从 TikTok 获取无水印视频网址的功能,但它不再起作用了。
如果我有视频 ID,如何获取 TikTok 无水印视频网址?
def get_tiktok_video_nowatermark(url):
headers = {
"method": "GET",
"accept-encoding": "utf-8",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
}
req = requests.get(url, headers=headers).text
video_data = json.loads(re.findall(u"<script id=\"__NEXT_DATA__\" type=\"application/json\" crossorigin=\"anonymous\">(.*?)</script><script crossorigin=\"anonymous\" nomodule=", req)[0])
watermark_url = video_data["props"]["pageProps"]["videoData"]["itemInfos"]["video"]["urls"][0]
watermark_video = str(requests.get(watermark_url, headers=headers).content)
position = int(re.search(r"vid:", watermark_video).start())
nowatermark_url = "https://api2.musical.ly/aweme/v1/playwm/?video_id=" + watermark_video[position+4:position+36]
return nowatermark_url