修复短视频解析工具
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\imghosting\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\imghosting\api;
|
||||
use think\helper\Str;
|
||||
|
||||
class pngcm implements api
|
||||
{
|
||||
public function upload($filepath, $filename){
|
||||
$url = 'https://img.wnflb2023.com/application/upload.php';
|
||||
$file = new \CURLFile($filepath);
|
||||
$file->setPostFilename($filename);
|
||||
$param = [
|
||||
'name' => $filename,
|
||||
'uuid' => 'o_'.Str::random(27),
|
||||
'sign' => time(),
|
||||
'file' => $file,
|
||||
];
|
||||
$data = get_curl($url,$param,'https://img.wnflb2023.com/');
|
||||
$arr = json_decode($data,true);
|
||||
if(isset($arr['code']) && $arr['code']==200){
|
||||
return ['url'=>$arr['url']];
|
||||
}elseif(isset($arr['message'])){
|
||||
throw new Exception('上传失败请重试('.$arr['message'].')');
|
||||
}else{
|
||||
throw new Exception('上传失败!接口错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,10 @@ textarea.form-control{min-height: auto;}
|
||||
title: '百度文库',
|
||||
key: 'baidu'
|
||||
},
|
||||
{
|
||||
title: 'fuliba',
|
||||
key: 'pngcm'
|
||||
},
|
||||
{
|
||||
title: 'IMGDD',
|
||||
key: 'imgdd'
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class acfun implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(preg_match('!/ac(\d+)!', $url, $match)){ //UGC视频
|
||||
$id = $match[1];
|
||||
|
||||
$requrl = 'https://www.acfun.cn/player/ac' . $id;
|
||||
$res = get_curl($requrl);
|
||||
if(preg_match('/window.videoInfo = (.*?);\n/', $res, $match)){
|
||||
//echo $match[1];exit;
|
||||
$arr = json_decode(trim($match[1]), true);
|
||||
$videoinfo = json_decode($arr['currentVideoInfo']['ksPlayJson'], true);
|
||||
if($videoinfo){
|
||||
$video_list = $videoinfo['adaptationSet'][0]['representation'];
|
||||
if(empty($video_list))throw new Exception('视频列表解析失败');
|
||||
$url = $video_list[0]['url'];
|
||||
return [
|
||||
'title' => $arr['title'],
|
||||
'cover' => $arr['coverUrl'],
|
||||
'url' => $url,
|
||||
'time' => date('Y-m-d H:i:s', $arr['createTimeMillis']/1000),
|
||||
'like' => $arr['likeCount'],
|
||||
'author' => $arr['user']['name'],
|
||||
'avatar' => $arr['user']['headUrl'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('视频信息解析失败');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('视频页面解析失败');
|
||||
}
|
||||
}elseif(preg_match('!/aa([0-9\_]+)!', $url, $match)){ //番剧
|
||||
$id = $match[1];
|
||||
|
||||
$requrl = 'https://www.acfun.cn/bangumi/aa' . $id;
|
||||
$res = get_curl($requrl);
|
||||
if(preg_match('/window.bangumiData = (.*?);\n/', $res, $match)){
|
||||
//echo $match[1];exit;
|
||||
$arr = json_decode(trim($match[1]), true);
|
||||
$videoinfo = json_decode($arr['currentVideoInfo']['ksPlayJson'], true);
|
||||
if($videoinfo){
|
||||
$video_list = $videoinfo['adaptationSet'][0]['representation'];
|
||||
if(empty($video_list))throw new Exception('视频列表解析失败');
|
||||
$url = $video_list[0]['url'];
|
||||
return [
|
||||
'title' => $arr['showTitle'],
|
||||
'cover' => $arr['bangumiCoverImageH'],
|
||||
'url' => $url,
|
||||
'time' => date('Y-m-d H:i:s', $arr['onlineTime']/1000),
|
||||
'like' => $arr['bangumiLikeCount'],
|
||||
'author' => $arr['bangumiTitle'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('视频信息解析失败');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('视频页面解析失败');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('视频id获取失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class douyin implements api
|
||||
{
|
||||
public function parse($url){
|
||||
$url = 'https://api.makuo.cc/api/get.video.douyin?url='.urlencode($url);
|
||||
$header = ['Authorization: '.config_get('yapi_token')];
|
||||
$data = get_curl($url, 0, 0, 0, 0, 0, 0, $header);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['code']) && $arr['code']==200){
|
||||
if(isset($arr['data']['video_url'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'time' => date('Y-m-d H:i:s', $arr['data']['time']),
|
||||
'cover' => $arr['data']['cover'],
|
||||
'url' => $arr['data']['video_url'],
|
||||
];
|
||||
}elseif(isset($arr['data']['images'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'time' => date('Y-m-d H:i:s', $arr['data']['time']),
|
||||
'cover' => $arr['data']['cover'],
|
||||
'images' => $arr['data']['images'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('解析url返回异常');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('视频解析失败,'.$arr['msg']);
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class douyu implements api
|
||||
{
|
||||
private static $version = '220320250920';
|
||||
|
||||
public function parse($url){
|
||||
if(preg_match('!\/show\/([a-zA-Z0-9]+)!', $url, $match)){
|
||||
$vid = $match[1];
|
||||
$requrl = 'https://v.douyu.com/show/' . $vid;
|
||||
$res = get_curl($requrl);
|
||||
if(preg_match('/DATA:\{content: (.*?),videoTag:/', $res, $match)){
|
||||
$arr = json_decode($match[1], true);
|
||||
if(isset($arr['point_id'])){
|
||||
$result = [
|
||||
'title' => $arr['title'],
|
||||
'desc' => $arr['contents'],
|
||||
'cover' => $arr['video_pic'],
|
||||
'time' => date('Y-m-d H:i:s', $arr['create_time']),
|
||||
'author' => $arr['author'],
|
||||
'avatar' => $arr['authorIcon']
|
||||
];
|
||||
$requrl = 'https://v.douyu.com/wgapi/vodnc/front/stream/getStreamUrlWeb';
|
||||
$dy_did = md5(microtime(true).rand(1000,9999));
|
||||
$time = time();
|
||||
$sign = $this->getsign($arr['point_id'], $dy_did, $time);
|
||||
$data = [
|
||||
'v' => self::$version,
|
||||
'did' => $dy_did,
|
||||
'tt' => $time,
|
||||
'sign' => $sign,
|
||||
'vid' => $arr['hash_id']
|
||||
];
|
||||
$cookie = 'dy_did='.$dy_did.';';
|
||||
$res = get_curl($requrl, http_build_query($data), $url, $cookie);
|
||||
$arr = json_decode($res, true);
|
||||
if(isset($arr['error']) && $arr['error'] == 0 && isset($arr['data']['thumb_video'])){
|
||||
if(isset($arr['data']['thumb_video']['super'])) $info = $arr['data']['thumb_video']['super'];
|
||||
elseif(isset($arr['data']['thumb_video']['high'])) $info = $arr['data']['thumb_video']['high'];
|
||||
elseif(isset($arr['data']['thumb_video']['normal'])) $info = $arr['data']['thumb_video']['normal'];
|
||||
else throw new Exception('视频解析失败,无可用视频地址');
|
||||
$result['url'] = $info['url'];
|
||||
return $result;
|
||||
}else{
|
||||
throw new Exception('视频解析失败,'.($arr['msg'] ?? ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception('视频解析失败');
|
||||
}else{
|
||||
throw new Exception('视频id获取失败');
|
||||
}
|
||||
}
|
||||
|
||||
private function getsign($xx0, $xx1, $xx2)
|
||||
{
|
||||
$k2 = [0x551983fb, 0x63c94be2, 0x0054dfe2, 0x3ba6bd08];
|
||||
$MASK = 0xFFFFFFFF;
|
||||
|
||||
$add = fn(int $a, int $b) => ($a + $b) & $MASK;
|
||||
$rotr = fn(int $x, int $n) => ((($x & $MASK) >> ($n & 31)) | (($x << (32 - ($n & 31))) & $MASK)) & $MASK;
|
||||
$rotl = fn(int $x, int $n) => (((($x << ($n & 31)) & $MASK) | (($x & $MASK) >> (32 - ($n & 31))))) & $MASK;
|
||||
|
||||
$cb = $xx0 . $xx1 . $xx2 . self::$version;
|
||||
$md = hash('md5', $cb, true);
|
||||
$re = array_values(unpack('V4', $md));
|
||||
|
||||
for ($I = 0; $I < 2; $I++) {
|
||||
$v0 = $re[$I * 2]; $v1 = $re[$I * 2 + 1];
|
||||
$sum = 0; $delta = 0x9e3779b9;
|
||||
for ($i = 0; $i < 32; $i++) {
|
||||
$sum = $add($sum, $delta);
|
||||
$v0 = $add($v0, ((($v1 << 4) + $k2[0]) ^ ($v1 + $sum) ^ (((($v1) & $MASK) >> 5) + $k2[1])) & $MASK);
|
||||
$v1 = $add($v1, ((($v0 << 4) + $k2[2]) ^ ($v0 + $sum) ^ (((($v0) & $MASK) >> 5) + $k2[3])) & $MASK);
|
||||
}
|
||||
$re[$I * 2] = $v0 & $MASK;
|
||||
$re[$I * 2 + 1] = $v1 & $MASK;
|
||||
}
|
||||
|
||||
$re[0] = $rotr($re[0], $k2[0] % 16);
|
||||
$re[0] = $rotl($re[0], $k2[2] % 16);
|
||||
$re[0] = $rotl($re[0], $k2[0] % 16);
|
||||
$re[0] = $rotr($re[0], $k2[2] % 16);
|
||||
$re[0] = $rotl($re[0], $k2[2] % 16);
|
||||
|
||||
$re[1] = ($re[1] ^ $k2[1]) & $MASK;
|
||||
$re[1] = $add($re[1], $k2[3]);
|
||||
$re[1] = $add($re[1], $k2[1]);
|
||||
$re[1] = ($re[1] ^ $k2[3]) & $MASK;
|
||||
$re[1] = ($re[1] ^ $k2[3]) & $MASK;
|
||||
|
||||
$re[2] = $add($re[2], $k2[0]);
|
||||
$re[2] = ($re[2] - $k2[2]) & $MASK;
|
||||
$re[2] = ($re[2] - $k2[0]) & $MASK;
|
||||
$re[2] = $add($re[2], $k2[2]);
|
||||
$re[2] = $rotl($re[2], $k2[2] % 16);
|
||||
|
||||
$re[3] = $rotl($re[3], $k2[1] % 16);
|
||||
$re[3] = $rotr($re[3], $k2[3] % 16);
|
||||
$re[3] = $rotr($re[3], $k2[1] % 16);
|
||||
$re[3] = ($re[3] - $k2[3]) & $MASK;
|
||||
|
||||
$re[0] = $add($re[0], $k2[0]);
|
||||
$re[0] = $add($re[0], $k2[2]);
|
||||
$re[0] = $rotl($re[0], $k2[2] % 16);
|
||||
|
||||
$re[1] = $rotr($re[1], $k2[1] % 16);
|
||||
$re[1] = $rotl($re[1], $k2[3] % 16);
|
||||
$re[1] = ($re[1] ^ $k2[3]) & $MASK;
|
||||
|
||||
$re[2] = $add($re[2], $k2[0]);
|
||||
$re[2] = ($re[2] - $k2[2]) & $MASK;
|
||||
$re[2] = $add($re[2], $k2[2]);
|
||||
$re[2] = $rotr($re[2], $k2[2] % 16);
|
||||
|
||||
$re[3] = $rotl($re[3], $k2[1] % 16);
|
||||
$re[3] = ($re[3] - $k2[3]) & $MASK;
|
||||
$re[3] = $rotl($re[3], $k2[3] % 16);
|
||||
|
||||
$sign = bin2hex(pack('V*', $re[0], $re[1], $re[2], $re[3]));
|
||||
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class huya implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(!preg_match('/\/(\d+).html/', $url, $match)) throw new Exception('视频id获取失败');
|
||||
$id = $match[1];
|
||||
$requrl = 'https://liveapi.huya.com/moment/getMomentContent?videoId=' . $id;
|
||||
$res = get_curl($requrl, 0, 'https://v.huya.com/');
|
||||
$arr = json_decode($res, true);
|
||||
if(isset($arr['status']) && $arr['status'] == 200){
|
||||
$url = $arr["data"]["moment"]["videoInfo"]["definitions"][0]["url"];
|
||||
$cover = $arr["data"]["moment"]["videoInfo"]["videoCover"];
|
||||
$title = $arr["data"]["moment"]["videoInfo"]["videoTitle"];
|
||||
$avatarUrl = $arr["data"]["moment"]["videoInfo"]["avatarUrl"];
|
||||
$author = $arr["data"]["moment"]["videoInfo"]["nickName"];
|
||||
$time = date('Y-m-d H:i:s', $arr["data"]["moment"]["cTime"]);
|
||||
$like = $arr["data"]["moment"]["favorCount"];
|
||||
return [
|
||||
'title' => $title,
|
||||
'cover' => $cover,
|
||||
'url' => $url,
|
||||
'time' => $time,
|
||||
'like' => $like,
|
||||
'author' => $author,
|
||||
'avatar' => $avatarUrl
|
||||
];
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class kuaishou implements api
|
||||
{
|
||||
public function parse($url){
|
||||
$url = 'https://api.makuo.cc/api/get.video.kuaishou?url='.urlencode($url);
|
||||
$header = ['Authorization: '.config_get('yapi_token')];
|
||||
$data = get_curl($url, 0, 0, 0, 0, 0, 0, $header);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['code']) && $arr['code']==200){
|
||||
if(isset($arr['data']['url'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'avatar' => $arr['data']['avatar'],
|
||||
'time' => date('Y-m-d H:i:s', intval($arr['data']['timestamp']/1000)),
|
||||
'cover' => $arr['data']['cover'],
|
||||
'url' => $arr['data']['url'],
|
||||
];
|
||||
}elseif(isset($arr['data']['images'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'avatar' => $arr['data']['avatar'],
|
||||
'time' => date('Y-m-d H:i:s', intval($arr['data']['timestamp']/1000)),
|
||||
'cover' => $arr['data']['cover'],
|
||||
'images' => $arr['data']['images'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('解析url返回异常');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('视频解析失败,'.$arr['msg']);
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class pipixia implements api
|
||||
{
|
||||
public function parse($url){
|
||||
$url = 'https://api.makuo.cc/api/get.video.pipixia?url='.urlencode($url);
|
||||
$header = ['Authorization: '.config_get('yapi_token')];
|
||||
$data = get_curl($url, 0, 0, 0, 0, 0, 0, $header);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['code']) && $arr['code']==200){
|
||||
if(isset($arr['data']['url'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'avatar' => $arr['data']['avatar'],
|
||||
'cover' => $arr['data']['cover'],
|
||||
'url' => $arr['data']['url'],
|
||||
];
|
||||
}elseif(isset($arr['data']['imgurl'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'avatar' => $arr['data']['avatar'],
|
||||
'cover' => $arr['data']['cover'],
|
||||
'images' => $arr['data']['imgurl'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('解析url返回异常');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('视频解析失败,'.$arr['msg']);
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class qmkg implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(!preg_match('/\?s=(.*)/', $url, $match)) throw new Exception('视频id获取失败');
|
||||
$id = $match[1];
|
||||
$requrl = 'https://kg.qq.com/node/play?s=' . $id;
|
||||
$text = get_curl($requrl);
|
||||
preg_match('/<title>(.*?)-(.*?)-/', $text, $video_title);
|
||||
preg_match('/cover\":\"(.*?)\"/', $text, $video_cover);
|
||||
preg_match('/playurl_video\":\"(.*?)\"/', $text, $video_url);
|
||||
if(!isset($video_url[1]))preg_match('/playurl\":\"(.*?)\"/', $text, $video_url);
|
||||
preg_match('/{\"activity_id\":0\,\"avatar\":\"(.*?)\"/', $text, $video_avatar);
|
||||
preg_match('/<p class=\"singer_more__time\">(.*?)<\/p>/', $text, $video_time);
|
||||
if (isset($video_url[1])) {
|
||||
return [
|
||||
'title' => $video_title[2],
|
||||
'cover' => $video_cover[1],
|
||||
'url' => $video_url[1],
|
||||
'author' => $video_title[1],
|
||||
'avatar' => $video_avatar[1],
|
||||
'time' => $video_time[1],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class toutiao implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(preg_match('!/video\/(\d+)\/!', $url, $match)){
|
||||
$id = $match[1];
|
||||
$requrl = 'https://m.toutiao.com/video/' . $id . '/';
|
||||
$ua = 'Mozilla/5.0 (Linux; Android 12; M2011K2C Build/SKQ1.211006.001) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.74 Mobile Safari/537.36';
|
||||
$res = get_curl($requrl, 0, 0, 0, 0, $ua);
|
||||
if(preg_match('/<script id="RENDER_DATA" type="application\/json">(.*?)<\/script>/', $res, $match)){
|
||||
$json = rawurldecode($match[1]);
|
||||
$arr = json_decode($json, true);
|
||||
if(isset($arr['articleInfo']['playAuthTokenV2'])){
|
||||
$result = [
|
||||
'title' => $arr['articleInfo']['title'],
|
||||
'author' => $arr['articleInfo']['mediaUser']['screenName'],
|
||||
'avatar' => $arr['articleInfo']['mediaUser']['avatarUrl'],
|
||||
'time' => date('Y-m-d H:i:s', $arr['articleInfo']['publishTime']),
|
||||
'cover' => $arr['articleInfo']['posterUrl'],
|
||||
];
|
||||
$playinfo = base64_decode($arr['articleInfo']['playAuthTokenV2']);
|
||||
$playinfo = json_decode($playinfo, true);
|
||||
if(isset($playinfo['GetPlayInfoToken'])){
|
||||
$requrl = 'https://vod.bytedanceapi.com/?'.$playinfo['GetPlayInfoToken'];
|
||||
$res = get_curl($requrl, 0, $url, 0, 0, $ua);
|
||||
$arr = json_decode($res, true);
|
||||
if(isset($arr['Result']['Data']['PlayInfoList']) && !empty($arr['Result']['Data']['PlayInfoList'])){
|
||||
$playinfolist = $arr['Result']['Data']['PlayInfoList'];
|
||||
array_multisort(array_column($playinfolist, 'Bitrate'), SORT_DESC, $playinfolist);
|
||||
$result['url'] = $playinfolist[0]['MainPlayUrl'];
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception('视频解析失败');
|
||||
}else{
|
||||
throw new Exception('视频id获取失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class weibo implements api
|
||||
{
|
||||
public function parse($url, $retry = 0){
|
||||
if(preg_match('/tv\/show\/([0-9:]+)/', $url, $matches) || preg_match('/fid=([0-9:]+)/', $url, $matches)){
|
||||
$oid = $matches[1];
|
||||
$page = '/tv/show/'.$oid;
|
||||
$url = 'https://weibo.com/tv/api/component?page='.urlencode($page);
|
||||
$post = 'data={"Component_Play_Playinfo":{"oid":"'.$oid.'"}}';
|
||||
$referer = 'https://weibo.com/tv/show/'.$oid;
|
||||
$cookie = cache('weibo_cookie');
|
||||
if(!$cookie) $cookie = $this->genvisitor();
|
||||
$data = get_curl($url, $post, $referer, $cookie);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['code']) && $arr['code']=='100000'){
|
||||
if(isset($arr['data']['Component_Play_Playinfo'])){
|
||||
$info = $arr['data']['Component_Play_Playinfo'];
|
||||
if(!empty($info['urls'])){
|
||||
$hd_keys = ['超清 4K', '超清 2K', '高清 1080P', '高清 720P', '高清 480P'];
|
||||
$play_url = null;
|
||||
foreach($hd_keys as $key){
|
||||
if(isset($info['urls'][$key])){
|
||||
$play_url = $info['urls'][$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$play_url) $play_url = $info['urls'][array_key_first($info['urls'])];
|
||||
$result = ['title'=>$info['title'], 'author'=>$info['author'], 'avatar'=>$info['avatar'], 'url'=>$play_url, 'cover'=>$info['cover_image'], 'time'=>date('Y-m-d H:i:s', $info['real_date']), 'duration'=>$info['duration']];
|
||||
return $result;
|
||||
}else{
|
||||
throw new Exception('解析视频失败:视频地址不存在');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('解析视频失败:视频不存在');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('解析视频失败:'.$arr['msg']);
|
||||
}elseif(empty($data) && $retry = 0){
|
||||
$this->genvisitor();
|
||||
return $this->parse($url, 1);
|
||||
}else{
|
||||
throw new Exception('解析视频失败:接口请求失败');
|
||||
}
|
||||
}else{
|
||||
throw new Exception('视频id获取失败');
|
||||
}
|
||||
}
|
||||
|
||||
private function genvisitor(){
|
||||
$url = 'https://passport.weibo.com/visitor/genvisitor2';
|
||||
$post = 'cb=visitor_gray_callback&tid=&from=weibo';
|
||||
$referer = 'https://passport.weibo.com/visitor/visitor';
|
||||
$data = get_curl($url, $post, $referer);
|
||||
if(preg_match('/visitor_gray_callback\((.*?)\)/', $data, $matches)){
|
||||
$arr = json_decode($matches[1], true);
|
||||
if(isset($arr['retcode']) && $arr['retcode'] == 20000000){
|
||||
$cookie = 'SUB='.$arr['data']['sub'].'; SUBP='.$arr['data']['subp'].';';
|
||||
cache('weibo_cookie', $cookie);
|
||||
return $cookie;
|
||||
}
|
||||
}
|
||||
throw new Exception('生成访客cookie失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class weishi implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(strpos($url,'feed/')){
|
||||
$id = getSubstr($url,'feed/','/');
|
||||
}else{
|
||||
$id = getSubstr($url,'id=','&');
|
||||
}
|
||||
if(!$id) throw new Exception('视频id获取失败');
|
||||
|
||||
$requrl = 'https://h5.weishi.qq.com/webapp/json/weishi/WSH5GetPlayPage?feedid=' . $id;
|
||||
$res = get_curl($requrl);
|
||||
$arr = json_decode($res, true);
|
||||
|
||||
if(isset($arr['ret']) && $arr['ret'] == 0){
|
||||
if(isset($arr['data']['feeds'][0]['video_url'])){
|
||||
return [
|
||||
'author' => $arr['data']['feeds'][0]['poster']['nick'],
|
||||
'avatar' => $arr['data']['feeds'][0]['poster']['avatar'],
|
||||
'time' => date('Y-m-d H:i:s', $arr['data']['feeds'][0]['poster']['createtime']),
|
||||
'title' => $arr['data']['feeds'][0]['feed_desc_withat'],
|
||||
'cover' => $arr['data']['feeds'][0]['images'][0]['url'],
|
||||
'url' => $arr['data']['feeds'][0]['video_url']
|
||||
];
|
||||
}else{
|
||||
throw new Exception('视频解析失败(地址获取失败)');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('视频解析失败('.$arr['msg'].')');
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use think\helper\Str;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class xiaohongshu implements api
|
||||
{
|
||||
public function parse($url){
|
||||
if(strpos($url, 'xhslink.com/')){
|
||||
$url = get_location_url($url);
|
||||
if(!$url || !strpos($url, 'xiaohongshu.com/')){
|
||||
throw new Exception('短链接解析失败');
|
||||
}
|
||||
}
|
||||
$data = get_curl($url);
|
||||
if(preg_match('/window\.__INITIAL_STATE__=(.*?)<\/script>/', $data, $matches)){
|
||||
$data = str_replace('undefined', 'null', $matches[1]);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['note']['noteDetailMap']) && !empty($arr['note']['noteDetailMap'])){
|
||||
$id = array_key_first($arr['note']['noteDetailMap']);
|
||||
$info = $arr['note']['noteDetailMap'][$id]['note'];
|
||||
$result = [
|
||||
'type' => $info['type'],
|
||||
'title' => $info['title'],
|
||||
'desc' => $info['desc'],
|
||||
'time' => date('Y-m-d H:i:s', intval($info['time']/1000)),
|
||||
'author' => $info['user']['nickname'],
|
||||
'avatar' => $info['user']['avatar'],
|
||||
];
|
||||
if($info['type'] == 'video'){
|
||||
$result['cover'] = !empty($info['imageList']) ? $info['imageList'][0]['urlDefault'] : '';
|
||||
$result['url'] = !empty($info['video']['media']['stream']['h264']) ? $info['video']['media']['stream']['h264'][0]['masterUrl'] : '';
|
||||
}elseif($info['type'] == 'normal'){
|
||||
$images = [];
|
||||
foreach($info['imageList'] as $img){
|
||||
$images[] = $img['urlDefault'];
|
||||
}
|
||||
$result['images'] = $images;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\utility\videoparse\api;
|
||||
|
||||
use Exception;
|
||||
use plugin\utility\videoparse\api;
|
||||
|
||||
class zuiyou implements api
|
||||
{
|
||||
public function parse($url){
|
||||
$url = 'https://api.makuo.cc/api/get.video.zuiyou?url='.urlencode($url);
|
||||
$header = ['Authorization: '.config_get('yapi_token')];
|
||||
$data = get_curl($url, 0, 0, 0, 0, 0, 0, $header);
|
||||
$arr = json_decode($data, true);
|
||||
if(isset($arr['code']) && $arr['code']==200){
|
||||
if(isset($arr['data']['url'])){
|
||||
return [
|
||||
'title' => $arr['data']['title'],
|
||||
'author' => $arr['data']['author'],
|
||||
'avatar' => $arr['data']['avatar'],
|
||||
'cover' => $arr['data']['cover'],
|
||||
'url' => $arr['data']['url'],
|
||||
];
|
||||
}else{
|
||||
throw new Exception('解析url返回异常');
|
||||
}
|
||||
}elseif(isset($arr['msg'])){
|
||||
throw new Exception('视频解析失败,'.$arr['msg']);
|
||||
}else{
|
||||
throw new Exception('视频解析失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user