php 抖音无水印下载地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 抖音无水印下载地址相关的知识,希望对你有一定的参考价值。
<?php
/**
* Created by PhpStorm.
* User: aric
* Date: 18/7/10 上午9:34
*/
//获取重定向最终网址
function get_redirect_final_target($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect
curl_exec($ch);
$target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
if ($target)
return $target;
return false;
}
//获取网址内容
function getContent($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = "Dnt: 1";
$headers[] = "Accept-Encoding: gzip, deflate, br";
$headers[] = "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7";
$headers[] = "Upgrade-Insecure-Requests: 1";
$headers[] = "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1";
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
$headers[] = "Cache-Control: max-age=0";
$headers[] = "Authority: www.douyin.com";
$headers[] = "Cookie: _ba=BA0.2-20180329-5199e-75UkuMgxUNaTYzfSeMOP; tt_webid=6547574875133314573";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close($ch);
return $result;
}
//获取视频ID
function getVID($data)
{
$re = '/https:\/\/aweme\.snssdk\.com\/aweme\/v1\/playwm\/\?video_id=(.*)&line=0/m';
$match = [];
preg_match($re, $data, $match);
if(empty($match)) {
return false;
}
$vid = $match[1];
return $vid;
}
//获取无水印下载地址 url为抖音分享的网址
function getDOUYIN($url)
{
$data = getContent($url);
if(!$data) {
echo "获取不到页面内容额";
return false;
}
$vid = getVID($data);
if(!$vid) {
echo "无法获取VID";
return false;
}
$v_url = "https://api.amemv.com/aweme/v1/play/?video_id=" . $vid . "&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0";
return get_redirect_final_target($v_url);
}
echo getDOUYIN("https://www.iesdouyin.com/share/video/6574757891381660936/?region=CN&mid=6563901515533290244&titleType=title×tamp=1531186272&utm_campaign=client_share&app=aweme&utm_medium=ios&tt_from=copy&iid=32073908798&utm_source=copy");
以上是关于php 抖音无水印下载地址的主要内容,如果未能解决你的问题,请参考以下文章