火山短视频无水印最新API

火山无疑在各大短视频里面最稳定的,但是以前的已经失效。

这个玩意也是困惑了自身很久,毕竟自己也接触API这类玩意也不是很久,算是菜鸟一枚。

经过几个小时的研究和折腾,终于让我成功了,毕竟API这玩意一旦公布出来很快就凉了。

最终分享出来让大家互相学习交流,顺带记录一下。

注:加入了短连接,这也算是奇思妙想吧。

完整API

<?php 
/**
 * Name:火山短视频 
 * Author:蓝优 
 */
header('Access-Control-Allow-Origin:*');
header('Content-Type:text/json;charset=utf8');
//请求
$url = @$_GET['url'];
if (strstr($url,"huoshan.com")) {
//获取301跳转真实地址	
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;}};
$url = getrealurl($url);
//模拟苹果手机访问
$UserAgent = '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';
// 截取ID
function GetBetween($content,$start,$end) {
$r = explode($start, $content);
if (isset($r[1])) {
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
//一次获取ID
$b = '?item_id=';
$c = '&tag=0';
$id = GetBetween($url,$b,$c);
$json = myCurl('https://share.huoshan.com/api/item/info?item_id='.$id);
$Array = json_decode($json,true);
$video = $Array["data"]["item_info"]["url"];
$image = $Array["data"]["item_info"]["cover"];
//二次获取ID
$d = '?video_id=';
$e = '&line=0';
$video_id = GetBetween($video,$d,$e);
$videourl = myCurl('https://api-hl.huoshan.com/hotsoon/item/video/_playback/?video_id='.$video_id);
$d = 'href="';
$e = '">';
$vip = GetBetween($videourl,$d,$e);
//状态码判断
if($vip==""){
	$status = 202;
}else{
	$status= 200;
}
//腾讯短网址
$tx = myCurl('http://sa.sogou.com/gettiny?url='.$vip);
//数组
$api = array('code'=>$status,'video'=>$tx,'image'=>$image);
//数组输出
echo json_encode($api,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
}
//curl模拟get请求
function myCurl($one, $two = '', $three = ''){
	$ch = curl_init();
	$ip = mt_rand(11, 191) . "." . mt_rand(0, 240) . "." . mt_rand(1, 240) . "." . mt_rand(1, 240);
	$UserAgent='User-agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11';
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //构造IP 
	curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent); // UA
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // 超时时间:30s
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
	curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
	if (!empty($three)) {
		curl_setopt($ch, CURLOPT_REFERER, $three);
	}
	if (!empty($two)) {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $two);
	}
	curl_setopt($ch, CURLOPT_URL, $one);
	curl_setopt($ch, CURLOPT_ENCODING, "gzip");
	$content = curl_exec($ch);
	curl_close($ch);
	return $content;
}
?>