最新抖音无水印解析源码(仅供学习参考)

2022-01-17 11:09:30 浏览数 (1)

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

直接上源码

代码语言:javascript复制
<?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;
    }
}

示例截图

0 人点赞