tiktok无水印解析PHP版

视频地址V3开头才能播放出现V26开头播放不了
重新访问下http://localhost/?url=https://v.douyin.com/ihWf6mpq/就好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

//抖音无水印PHP版
//调用示例 http://localhost/?url=https://v.douyin.com/ihWf6mpq/
error_reporting(0);
$headers = get_redirect_url($_GET["url"]);
preg_match('|video/(.*?)/|',$headers, $a);
$targetUrl = 'https://www.douyin.com/user/self?modal_id='.$a[1].'&showTab=like';
$customUserAgent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36';
$result = fetchDataWithCustomUA($targetUrl, $customUserAgent);
preg_match('|<script id="RENDER_DATA" type="application/json">(.*?)</script>|',$result, $matches);
$middle_text = $matches[1];
$m =json_decode(Urldecode($middle_text));
$arr = array('名字' => $m->app->videoDetail->shareInfo->shareLinkDesc, '封面' =>"https:".$m->app->videoDetail->video->originCover, '视频' =>"https:".$m->app->videoDetail->video->playAddr[0]->src, 'MP3' =>$m->app->videoDetail->music->playUrl->uri);
echo stripslashes(json_encode($arr,JSON_UNESCAPED_UNICODE));

function fetchDataWithCustomUA($url, $customUA) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $customUA);
curl_setopt ($ch, CURLOPT_COOKIE , 'ttwid=1%7CP3XfP8WLdGrhhniqvZgITdxee4ylTHNIAFxiA8uiudk%7C1692861969%7Ccbc1e8cb639b9f2537017019cf2e16034eb5e02f91317cf02da669c3d9035225; douyin.com; device_web_cpu_core=8; device_web_memory_size=8; webcast_local_quality=null; strategyABtestKey=%221692861971.054%22; passport_csrf_token=52d1b9f0bdc601061b35649f820990a7; passport_csrf_token_default=52d1b9f0bdc601061b35649f820990a7; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; s_v_web_id=verify_lloub543_MIbxaeCL_vWX9_4eQ5_B6rZ_XiLUd8TiC2z5; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; csrf_session_id=b3e96aad3d33a588099da1957c61412b; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCR1QzbVlJN1JlQ1pHYjRyMUxyREJMNWVqVHA5SWJxdjFPZHdsK08rNWFsRFY2dzFFSWZTVEpUbGppeE9GMW9ZK05ubFExbzIwU1Y4UWtUd3gxYUo3aUE9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ==; ttcid=6e2c49249e684b31adc93ec9d811921d35; pwa2=%220%7C0%7C2%7C0%22; __ac_nonce=064e715db00dce12044ad; __ac_signature=_02B4Z6wo00f01JFEgwQAAIDBX8zLRARkI5yRZIeAAEC64rwojdCoEppcamcP.zNDFFTvK-IdW9t65-J9QZ6AQspB6MmaGXcO2csLGYi13EYeG3xUA6EfUKHORVbG8tX9TWqmvF-XXQJq1BC37e; tt_scid=0RB0BQpAJZCtDUGQEfvGfovmjxWL4NUYr7faECJEqAxGXeNJ7oGESHkuMx8zXBOuf02f; download_guide=%223%2F20230824%2F0%22; IsDouyinActive=true; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1920%2C%5C%22screen_height%5C%22%3A1080%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A5.95%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A50%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1693470886177%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; msToken=phFAWMM1fxkFc4oj6QE8_DMbU57I87HDv_NnoZ9uVNGkx1j9HDT-ddGbno81zAHZuXDF4OKjA1mHIchWdQYixYfFkSCi1Kb-1dKKjmHw_yz-YTa2wQ==; msToken=f_v0fvPvEDKoOBgIkJwOciMoWbigmQ0oZzhY2RgQfO2Otc1zIwtEkRE_kmn8FYYdXDQjAa0tfamm7kXHYD_1M3VrLvLvfQaIP2XtKctXHG4WNcKRyw==; xgplayer_user_id=180566107648');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function get_redirect_url($url){
$header = get_headers($url, 1);
if (strpos($header[0], '301') !== false || strpos($header[0], '302') !== false) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}
?>