找回密码
 立即注册
PHP编程 2023-01-06 123 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
<?php
/*
Author    举个栗子网
DateTime  2019-12-26
*/
function GetVideos($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function GetUrl($url)
{
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
//URL
$url = $_GET['url'];
if (empty($url)) {
echo json_encode(['code' => 0, 'msg' => '请输入正确视频网址,格式为:douyin.php?url=视频地址']);
}else{
$data = GetUrl($url);
//获取
preg_match('/playAddr: "(?<url>[^"]+)"/i', $data, $url);
preg_match('/<p class="desc">(?<desc>[^<>]*)<\/p>/i', $data, $name);
$name = $name['desc'];
$url = $url['url'];
if(empty($url))
{
echo json_encode(['code' => 0, 'msg' => '解析错误']);
exit;
}
preg_match('/s_vid=(.*?)&/', $url, $id);
$url = 'https://aweme.snssdk.com/aweme/v1/play/?s_vid=' . $id[1] . '&line=0';
$data_new = GetVideos($url);
preg_match('/<a href=\"http:\/\/(.*?)\">/', $data_new, $link);
if (empty($link[1])) {
echo json_encode(['code' => 0, 'msg' => '解析错误']);
exit;
}
$link = 'http://' . $link[1];
echo json_encode(['code' => 1, 'name' => $name, 'url' => $link]);
}

(<?php
/*
Author Give a chestnut net
DateTime 2019-12-26
*/
function GetVideos($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function GetUrl($url)
{
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
//URL
$url = $_GET['url'];
if (empty($url)) {
echo json_encode(['code' => 0, 'msg' => 'Please enter the correct video URL, the format is: douyin.php?url=video URL']);
}else{
$data = GetUrl($url);
//Obtain
preg_match('/playAddr: "(?<url>[^"]+)"/i', $data, $url);
preg_match('/<p class="desc">(?<desc>[^<>]*)<\/p>/i', $data, $name);
$name = $name['desc'];
$url = $url['url'];
if(empty($url))
{
echo json_encode(['code' => 0, 'msg' => 'parsing error']);
exit;
}
preg_match('/s_vid=(.*?)&amp;/', $url, $id);
$url = 'https://aweme.snssdk.com/aweme/v1/play/?s_vid=' . $id[1] . '&amp;line=0';
$data_new = GetVideos($url);
preg_match('/<a href=\"http:\/\/(.*?)\">/', $data_new, $link);
if (empty($link[1])) {
echo json_encode(['code' => 0, 'msg' => 'parsing error']);
exit;
}
$link = 'http://' . $link[1];
echo json_encode(['code' => 1, 'name' => $name, 'url' => $link]);
})





上一篇:PHP实现第四方QQ微信扫码登录,无需接入QQ互联网和微信开发者平台
下一篇:轻巧、简单、漂亮的 WordPress 主题 - Argon Free Theme