前言:
网上流传了好多抖音视频无水印的解析接口,但源码很少,能用的源码更是寥寥,在此,博主分享一篇博主用的感觉还不错的源码分享一下,下面是PHP源码 - 只提供解析原理,要做接口的自行封装一下。

直接上源码

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
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* 时间:2020年7月20日15:23:41
*/
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
$url = "https://v.douyin.com/KYB4EW/";
$ids = explode('/', parse_url(getrealurl($url))['path'])[3];
$json = json_decode(get_curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$ids))->item_list[0];
$play = get_curl(str_ireplace('playwm','play',$json->video->play_addr->url_list[0]),['ua'=>'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36']);
preg_match_all("/<a[^<>]+href *= *[\"']?(http\:\/\/[^ '\"]+)/i", $play, $body_links, PREG_SET_ORDER);
$data = [
"title"=>$json->desc,
"nickname"=>$json->author->nickname,
"music"=>$json->music->play_url->uri,
"play"=>$body_links[0][1]
];
echo json_encode($data,320);
function get_curl($url, $paras = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if ($paras['httpheader']) { // 请求头
$httpheader=$paras['httpheader'];
}else{
$httpheader[] = "Accept:*/*";
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($paras['ctime']) { // 连接超时
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $paras['ctime']);
}
if ($paras['rtime']) { // 读取超时
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $paras['rtime']);
}
if ($paras['post']) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
}
if ($paras['header']) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($paras['cookie']) {
curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
}
if ($paras['refer']) {
if ($paras['refer'] == 1) {
curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
} else {
curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
}
}
if ($paras['ua']) {
curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
}
if ($paras['nobody']) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function getrealurl($url){
@$header = get_headers($url,1);
if (strpos($header[0],'301') || strpos($header[0],'302')) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}

示例截图

最新抖音无水印解析源码