我一直在尝试下载tiktok视频,一切都很好,除了我试图通过代码获取下载链接时,它在生成时就过期了,浏览器没问题并继续播放
从浏览器视频元素:https://v16-web.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/27121794ac454914bcdc35d74e708f40/?a=1988&br=678&bt=339&cd=0%7C0%7C1&ch=0&cr=0&cs=0&cv=1&dr=0&ds=3&er=&expire=1627815238&ft=Q9BExEX-_4ka&l=2021080104534801019018913735EEFDDF&lr=tiktok_m&mime_type=video_mp4&net=0&pl=0&policy=2&qs=0&rc=MzQ3amk6Zjw5NzMzODczNEApMzo0NjwzZmRnN2c4O2RnNWczZS4ucjRfYS1gLS1kMS1zc2BeMWIzMGMtXjUxM2NhYi86Yw%3D%3D&signature=6e1a952f38106a6c65131eac83eaa091&tk=tt_webid_v2&vl=&vr=
从代码:https://v16-web.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/e43c935ede5441338713a7c2868a3d6a/?a=1988&br=1838&bt=919&cd=0%7C0%7C1&ch=0&cr=0&cs=0&cv=1&dr=0&ds=3&er=&expire=1627814858&ft=Q9BExEX-_4ka&l=2021080104472801018907313747EA3DCD&lr=tiktok_m&mime_type=video_mp4&net=0&pl=0&policy=2&qs=0&rc=M3RvdjY6ZnY0NzMzODczNEApOzU2NTw8NDwzNzo6ZWU4O2dhbGJecjQwNC9gLS1kMS1zczQ2M2MxMi9fYTQwXi5jNS46Yw%3D%3D&signature=776e560c4d70e9b2eb749d8c3e774c3a&tk=tt_webid_v2&vl=&vr=
从代码中它返回 403 禁止,但浏览器链接工作正常,我尝试更改 l、签名、视频 id (??) 参数,但这些都不起作用。
我想知道如何在不立即过期的情况下生成下载链接。
代码:
public string GetUrl()
{
string src = getsrc();
Regex re = new(@"__NEXT_DATA__"" type=""application/json"" nonce=""(.*?)"" crossorigin=\""anonymous\"">(.*?)</script>");
if (!re.IsMatch(src)) throw new Exception("Ссылка не найдена");
string innerurl = re.Match(src).Groups[2].Value;
var doc = JsonDocument.Parse(innerurl);
var x = doc.RootElement
.GetProperty("props").GetProperty("pageProps").GetProperty("itemInfo")
.GetProperty("itemStruct").GetProperty("video").GetProperty("playAddr").GetString();
string outp = Encoding.ASCII.GetString(
Encoding.Convert(Encoding.UTF8, Encoding.ASCII, Encoding.UTF8.GetBytes(x))
);
return outp;
}