PHP解析抖音无水印视频后端代码

使用方法 http://www.yoursite.com/api.php?url=抖音视频链接

在线工具 http://tool.liumingye.cn/douyin/

QQ截图20190329052258.png

20190329052336.png

<?php
/*
    author 刘明野
    site www.liumingye.cn
*/
function curl_request($url, $location = 1) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Mobile Safari/537.36');
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $location);
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    curl_setopt($curl, CURLOPT_REFERER, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    if (curl_errno($curl)) {
        return curl_error($curl);
    }
    curl_close($curl);
    return $data;
}
function GetBetween($content, $start, $end) {
    $r = explode($start, $content);
    if (isset($r[1])) {
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}
$parm_url = @$_GET['url'];
$str = curl_request($parm_url);
$vid = GetBetween($str, "v1/playwm/?video_id=", "&");
$url = curl_request("https://aweme.snssdk.com/aweme/v1/play/?video_id=" . $vid . "&line=0", 0);
$url = GetBetween($url, "href=\"", "\"");
echo $url;