MENU

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

• May 4, 2020 • Read: 1705 • 经验分享,原创作品

前言:

之前发过一篇类似的文章,发现已经失效了于是来更新一波!只提供解析原理,要做接口的自行封装一下。

代码:

<?php
/**
 * 作者:教书先生
 * 抖音短视频解析
 * 时间:2020年5月4日00:13:41
 * 博客:blog.oioweb.cn
 */
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;
    }
}

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

Archives QR Code Tip
QR Code for this page
Tipping QR Code
Leave a Comment

11 Comments
  1. 感谢分享,但getrelurl函数似乎有问题,并不能每次都能成功返回跳转链接,我使用curl修复了它,谢谢)@(真棒)
    https://temp.atssr.com/?url=https://v.douyin.com/KYB4EW/

    1. @幸运柒又或者是
      https://temp.atssr.com/?type=text&url=https://v.douyin.com/KYB4EW/
      再弄个直接播放就更好了!太晚了,睡觉。

    2. @幸运柒我测试getrealurl是没有问题的

    3. @教书先生但我机器上测试不能保证每次都能获取到跳转,所以换成了curl ,可能是兼容问题吧

    4. @教书先生location的首字母大小写问题

  2. 哈哈 哈哈

    建议改成api

    1. @哈哈只提供解析原理,api自行封装

  3. 看看就好 就不整了 反正整也不会

    1. @图样图森破演示的视频链接都放上了啊

  4. 图床登录状态失效,SSL失效

    1. @官仁有话说可以了