I have a function for getting no watermarked video url from TikTok, but it don't work anymore.
How to get TikTok nowatermark video url, if I have video id?
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
Also, make sure you request
nonwatermark_url
without any User agent header, else you will get empty result. Better off if you can make head request to the url and determine thefinal url
which can be passed directly to the browser to play or download.