源码说明
抖音快手去水印解析API源码,目前支持抖音和快手,数据都是从原服务器取来的,没有从html结果抓,应该算是比较稳定一点, 其他平台的函数有空写完再补
一共五个函数
1、analyzing 平台解析
2、douyin 抖音视频处理
3、kuaishou 快手视频处理
4、httpRequest curl封装函数
5、result 返回处理
调用示例:
require 'CWaterMask.php'; echo getUrl(); function getUrl() { $data = CWaterMask::analyzing($_GET['url']); return $data; }
代码贴上
<?php class CWaterMask { static public function analyzing($url) { preg_match('/([w-]+.)+w+(:d{2,6})?/', $url, $domain); switch ($domain[0]) { case '': return self::result(500, '请传入解析url参数,例:http://www.123.com/?url=https://v.douyin.com/ehHpu7V/'); break; case 'v.douyin.com': return self::douyin($url); break; case 'v.kuaishou.com': return self::kuaishou($url); break; default: return self::result(500, '抱歉,此url暂不支持!'); } } static public function douyin($url) { $url = self::httpRequest($url, 'GET'); preg_match('/(?<=video/)d*(?=/?region)/', $url['location'], $matches); $item_ids = $matches[0]; $vidoUrl = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $item_ids; $result = self::httpRequest($vidoUrl, 'GET'); $vid = $result['response']['item_list'][0]['video']['play_addr']['uri']; if (isset($vid)) { $video_url = 'https://aweme.snssdk.com/aweme/v1/play/?video_id=' . $vid . '&ratio=720p&line=0'; $music = $result['response']['item_list'][0]['music']['play_url']['uri']; $nickname = $result['response']['item_list'][0]['author']['nickname']; $return = array('nickname' => $nickname, 'video_url' => $video_url, 'music' => $music); return self::result(200, $return); } else { return self::result(500, '解析出错!'); } } static public function kuaishou($url) { $vurl = self::httpRequest($url, 'GET'); preg_match('/(?<=video/)w*(?=?fid)/', $vurl['location'], $matches); $str_qury1 = 'query visionVideoDetail($photoId: String, $type: String, $page: String, $webPageArea: String)'; $str_qury2 = '(photoId: $photoId, type: $type, page: $page, webPageArea: $webPageArea)'; $query = array("operationName" => "visionVideoDetail", "variables" => array('photoId' => $matches[0], "page" => "detail"), "query" => $str_qury1 . "{n visionVideoDetail" . $str_qury2 . "{n photo {n idn durationn captionn likeCountn realLikeCountn coverUrln photoUrln }n}n}n",); $query = json_encode($query, 320); $headers = array('content-type: application/json', 'Referer:' . $vurl['location']); $result = self::httpRequest('https://video.kuaishou.com/graphql', 'POST', $query, $headers); if (isset($result['response']['data']['visionVideoDetail']['photo']['photoUrl'])) { return self::result(200, $result['response']['data']['visionVideoDetail']['photo']); } else { return self::result(500, '解析出错!'); } } static public function httpRequest($url, $method = 'POST', $postfields = null, $headers = array()) { $method = strtoupper($method); $ci = curl_init(); curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ci, CURLOPT_TIMEOUT, 30); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1); switch ($method) { case "POST": curl_setopt($ci, CURLOPT_POST, true); if (!empty($postfields)) { $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields; curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr); } break; default: curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method); break; } $ssl = preg_match('/^/i', $url) ? TRUE : FALSE; curl_setopt($ci, CURLOPT_URL, $url); if ($ssl) { curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); } curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ci, CURLOPT_MAXREDIRS, 2); curl_setopt($ci, CURLOPT_HTTPHEADER, $headers); curl_setopt($ci, CURLINFO_HEADER_OUT, true); $response = json_decode(curl_exec($ci), true); $requestinfo = curl_getinfo($ci); $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); $location = curl_getinfo($ci, CURLINFO_EFFECTIVE_URL); curl_close($ci); return array('location' => $location, 'response' => $response, 'requestinfo' => $requestinfo); } static public function result($errno = 0, $data = '') { header("Content-type: application/json;charset=utf-8"); $errno = intval($errno); $result = array('code' => $errno, 'message' => $data); return json_encode($result, 320); } }
说下小白直接运行的问题
1、复制代码保存为CWaterMask.php
2、复制调用示例里面的代码 保存为index.php
3、放在同一个目录,假设目录为shuiyin
4、丢在服务器,域名访问 域名/shuiyin/?url=抖音或快手短链接
或者下载下面的包,解压,文件丢在服务器,按照4操作