抖音短视频无水印解析原理及源码,附接口
访问 https://love1314.xin/code/douyin/jiexi.php?url=https://v.douyin.com/ehyU6Jd/
正常返回:
{
"code": 0,
"share_title": "我们反诈小分队的第二期来啦!持续更新中... @王橘长?#攀枝花反诈宣传 #全民反诈 #我在岗位上",
"music": "https://sf6-cdn-tos.douyinstatic.com/obj/ies-music/6953436383121820429.mp3",
"nickname": "大白说反诈",
"unique_id": "1baibo1",
"uid": "101409543226",
"signature": "四川攀枝花市公安局民警\n负责反电信网络诈骗宣传\n不贪,不怕,不轻信,不转账\n能有效保护你财产安全。"
}
php 的代码如下:
<?php
header("Content-type:text/html;charset='utf-8'");
$url = $_GET['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// 不需要页面内容
curl_setopt($ch, CURLOPT_NOBODY, 1);
// 不直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 返回最后的Location
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);
$info = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
curl_close($ch);
//正则匹配item_ids
$item_ids = preg_match_all('/[1-9]\d*/', $info, $matches,);
// 组装重定向地址
$url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$matches[0][0];
$ch = curl_init($url); //初始化
curl_setopt($ch, CURLOPT_HEADER, 0); // 不返回header部分
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回字符串,而非直接输出
curl_setopt($ch, CURLOPT_USERAGENT, "Dalvik/1.6.0 (Linux; U; Android 4.1.2; DROID RAZR HD Build/9.8.1Q-62_VQW_MR-2)");
curl_setopt($ch, CURLOPT_REFERER, "-");
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
$url = $result['item_list'][0]['video']['play_addr']['url_list'][0];
$url = str_replace('playwm','play', $url);
$ch = curl_init($url); //初始化
curl_setopt($ch, CURLOPT_HEADER, 0); // 不返回header部分
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回字符串,而非直接输出
curl_setopt($ch, CURLOPT_USERAGENT, "Dalvik/1.6.0 (Linux; U; Android 4.1.2; DROID RAZR HD Build/9.8.1Q-62_VQW_MR-2)");
curl_setopt($ch, CURLOPT_REFERER, "-");
$response = curl_exec($ch);
curl_close($ch);
$response = explode('"',$response);
// 在页面上输出视频
//var_dump($response[1]);
$data['code']=0;
$data['video_url']=$response[1];
$data['share_title']=$result['item_list'][0]['share_info']['share_title'];
$data['music']=$result['item_list'][0]['music']['play_url']['uri'];
$data['nickname']=$result['item_list'][0]['author']['nickname'];
$data['unique_id']=$result['item_list'][0]['author']['unique_id'];
$data['uid']=$result['item_list'][0]['author']['uid'];
$data['signature']=$result['item_list'][0]['author']['signature'];
echo json_encode($data);