抖音无水印解析

很早之前就开始写抖音无水印解析,但是抖音更新了很多版本,导致之前的解析方法都失效了,目前这个2020-09-08测试还能用
demo

代码

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
error_reporting(0);
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4'
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, False);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5000);
$result = curl_exec($ch);
return $result;
}
function curlGetVideoAddr($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4'
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, False);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, URLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5000);
$result = curl_exec($ch);
$str = '/((http:\/\/|https:\/\/)\S+)\s/';
preg_match_all($str,$result,$arr);
if(isset($arr[0][0])){
return $arr[0][0];
}else{
return null;
}

}
function getItemInfo($url){
$str_r= '/(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/';
preg_match_all($str_r,$url,$arr);
$share_url=$arr[0][0];

$found = curl($share_url);

preg_match('/href="(.*?)">Found/', $found, $matches);
$url_302 = $matches[1];

$str_r= '/\/video\/(\d+?)\//';
preg_match_all($str_r,$url_302,$arr);

$info_url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$arr[1][0];
$info = curl($info_url);
return json_decode($info,true);
}

$url = $_POST['url'];

$item_info = getItemInfo($url);

$play_addr = str_replace('playwm','play',$item_info['item_list'][0]['video']['play_addr']['url_list'][0]);

$play_addr = curlGetVideoAddr($play_addr);

$data = array(
'desc' => $item_info['item_list'][0]['desc'],
'video_url' => $play_addr,
'music_url' => $item_info['item_list'][0]['music']['play_url']['uri']
);

echo json_encode($data);