<?phpheader("Content-Type:text/json;charset=utf-8");
error_reporting(0);
$url = @$_GET['url'];//抖音视频地址
$isFormat = @$_GET['isFormat'];//是否格式化数据,默认true
$old = @$_GET['old'];//是否使用旧版数据格式,默认false
class Douyin
{private $UA = "Mozilla/5.0 (Linux; Android 8.0.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36";private function getSubstr($str, $leftStr, $rightStr){$left = strpos($str, $leftStr);$right = strpos($str, $rightStr, $left);if ($left < 0 or $right < $left) return '';return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));}private function getAwemeId($link, $UA){$link = ltrim($link);//移除左侧空白字符if (strstr($link, 'http://v.douyin.com/')) {$context = stream_context_create(array('http' => array('header' => 'User-Agent:' . $UA)));$html_text = file_get_contents($link, 0, $context);$str = $this->getSubstr($html_text, "itemId: \"", "\",");if (!strstr($html_text, "itemId: ")) {return false;}return $str;}//短链接支持if (strstr($link, "https://www.iesdouyin.com")) {//长链接$str = $this->getSubstr($link, "video/", "/?");return $str;}//长链接支持return false;}private function getOutPutForError($errorMes, $old){if ($old) {$error = ['status' => false,'message' => $errorMes];return json_encode($error);} else {$error = ['status' => false,'errorMes' => $errorMes];return json_encode($error);}}private function getFormatVideoData($data){$detail = @$data;$info = @$detail['share_info'];//视频分享信息$aweme_id = @$detail['aweme_id'];$user_name = @$detail['author']['nickname'];//作者昵称$shortId = @$detail['author']['short_id'];//作者抖音号$user_headImg = @$detail['author']['avatar_medium']['url_list'][0];//作者头像$image = @$detail['video']['origin_cover']['url_list'][0];//封面图片$urls = @$detail['video']['play_addr']['url_list'];//无水印地址$music_urls = @$detail['music']['play_url']['url_list'];//音乐地址$userId = @$detail['author_user_id'];//用户userId$dynamic_cover = @$detail['video']['dynamic_cover']['url_list'][0];//封面动态图地址$longVideo = @$detail['long_video'][0]['video']['bit_rate'];//长视频if (!$longVideo) {$longVideo = [];}$videoData = ['nickname' => $user_name,'shortId' => $shortId,'userId' => $userId,'awemeId' => $aweme_id,'headImage' => $user_headImg,'image' => $image,'dynamic_cover' => $dynamic_cover,'urls' => $urls,'long_video' => $longVideo,'music_urls' => $music_urls,'info' => $info,];return $videoData;}private function getDevices(){return explode("\n", str_replace("\r", "", file_get_contents("./douyinDevice.txt")));//去除回车\r}private function getVersions(){return ['680' => '6.8.0','251' => '2.5.1','140' => '1.4.0'];}private function getApis($deviceInfos, $api_n, &$api_positions){$versions = $this->getVersions();//$base_api="https://aweme.snssdk.com/aweme/v1/aweme/detail/?origin_type=link&retry_type=no_retry&{device_info}&ac=wifi&channel=update&aid=1128&app_name=aweme&version_code={version_code}&version_name={version_name}&device_platform=android&ssmix=a&device_type=MI+8&device_brand=xiaomi&language=zh&os_api=22&os_version=5.1.1&uuid=865166029463703&openudid=ec6d541a2f7350cd&manifest_version_code=251&resolution=1080*1920&dpi=480&update_version_code=2512&ts=1561136204&as=a1e500706c54fd8c8d&cp=004ad55fc8d60ac4e1&aweme_id=";$apis = [];$rand_devices = [];//随机设备信息$devices_size = sizeof($deviceInfos);//实际设备信息条数$real_size = $devices_size < $api_n ? $devices_size : $api_n;//最终获取的设备信息数量//获取随机设备信息for ($i = 0; $i < $real_size;) {try {$rand = random_int(0, sizeof($deviceInfos) - 1);$rand_device = $deviceInfos[$rand];if (key_exists($rand_device, $rand_devices)) {continue;} else {$rand_devices[] = $rand_device;$i++;}} catch (Exception $e) {exit($this->getOutPutForError("PHP随机数错误"));}if($rand_device!=""){$api_positions[]=$rand;}else{$api_positions[]=999;}}//生成APIforeach ($versions as $version_code => $version_name) {$version_apis = [];foreach ($rand_devices as $device) {$version_apis[] = "https://aweme.snssdk.com/aweme/v1/aweme/detail/?origin_type=link&retry_type=no_retry&$device&ac=wifi&channel=update&aid=1128&app_name=aweme&version_code=$version_code&version_name=$version_name&device_platform=android&ssmix=a&device_type=MI+8&device_brand=xiaomi&language=zh&os_api=22&os_version=5.1.1&uuid=865166029463703&openudid=ec6d541a2f7350cd&manifest_version_code=$version_code&resolution=1080*1920&dpi=480&update_version_code=2512&ts=1561136204&as=a1e500706c54fd8c8d&cp=004ad55fc8d60ac4e1&aweme_id=";}$apis[$version_code] = $version_apis;}return $apis;}/*** @param $url* @param $isFormat* @param $old* @return false|string*/private function parseVideoByLink($url, $isFormat, $old){$awemeId = $this->getAwemeId($url, $this->UA);$api_positions = [];//记录device位置$api_positions_error = [];//记录哪一个出错$api_version = '';//记录使用哪一个版本API$api_n = 4;//控制每次取得的设备信息数量$deviceInfos = $this->getDevices();$versions_apis = $this->getApis($deviceInfos, $api_n, $api_positions);if(!$versions_apis) return $this->getOutPutForError("设备信息缺失",$old);$header = array("Accept-Encoding: utf-8","User-Agent: okhttp/3.10.0.1");$context = stream_context_create(array("http" => array("header" => $header)));if ($awemeId) {$isSuccess = false;foreach ($versions_apis as $version_code => $apis) {$count = -1;$api_version = $version_code;$api_positions_error_version = [];//记录每个版本出错APIforeach ($apis as $api) {$count++;$api_position = $api_positions[$count];$data = json_decode(file_get_contents($api . $awemeId, 0, $context), true);$detail = @$data['aweme_detail'];$forward_item=@$detail['forward_item'];if($detail&&$forward_item){//用户动态的分享链接$detail=$forward_item;}$short_id=@$detail['author']['short_id'];if ($detail && $short_id) {$isSuccess = true;break;}$api_positions_error_version[] = $api_position;}$api_positions_error[$version_code] = $api_positions_error_version;if ($isSuccess) {break;}}$str_position = null;//储存失败接口位置foreach ($api_positions_error as $version_code => $eps) {if (!empty($eps))$str_position .= '{' . $version_code . ':';foreach ($eps as $ep) {$str_position .= "[$ep]";}if (!empty($eps))$str_position .= '}';}if (!$isSuccess) {return $this->getOutPutForError("抖音接口调用失败$str_position", $old);}if($old){if($isFormat) {$out = $this->getFormatVideoData($detail);}else{$out['data']=$detail;}$out['status']=true;$out['message']=$url;$out['api_position']=$api_position;$out['error_api']=$str_position;$out['api_version']=$api_version;$out['dataType_new']=!$old;return json_encode($out);}else{$out=['status'=>true,'message'=>$url,'data'=>null,'api_position'=>$api_position,'api_version'=>$api_version,'dataType_new'=>!$old,'error_api'=>$str_position];if($isFormat) {$out['data'] = $this->getFormatVideoData($detail);}else{$out['data']=$detail;}return json_encode($out);}}return $this->getOutPutForError('链接不正确', $old);}private function checkParams($url, &$isFormat, &$old){if (empty($url)) return false;if ($isFormat == null) $isFormat = true;if ($old == null) $old = false;return true;}function get($url, $isFormat, $old){$pass = $this->checkParams($url, $isFormat, $old);if (!$pass)return $this->getOutPutForError("地址无效", $old);elsereturn $this->parseVideoByLink($url, $isFormat, $old);}
}
$douyin = new Douyin();
echo $douyin->get($url, $isFormat, $old);

原文地址:
https://github.com/zbfzn/douyin-clear-php/blob/master/parseByLink.php

PHP之抖音无水印解析源码相关推荐

  1. php 记事本源代码_抖音无水印解析PHP源码

    抖音无水印解析PHP源码 仅限学习使用 输出为标准的格式化json数据 ajax直接调用即可 原生的ajax的调用方法看底部 $url = @$_GET['url']; if (strstr($url ...

  2. 最新抖音无水印解析PHP源码

    源码介绍: 最新抖音无水印解析PHP源码 网盘下载地址: http://www.bytepan.com/hQuJxMu7aaG 图片:

  3. 怎么在腾讯云函数抖音无水印解析接口部署

    使用腾讯云函数(SCF)部署抖音无水印接口调用代码,无需服务器,稳定安全可靠! 示例接口返回数据请求: https://service-eu6l8yx0-1256101469.gz.apigw.ten ...

  4. python 抖音评论_新手python抖音无水印解析带详细注释

    资源来源网络,如果需要授权,请大家更换源码,模块仅供学习,如需商用请购买正版授权,本栏目不提供技术服务,积分不够请签到,或者会员中心投稿源码 注释都很详细,可以看看注释!友情提醒,仅供学习使用,请勿用 ...

  5. flutter 抖音无水印解析视频

    声明:这是学flutter的第一个应用,垃圾堆中的代码, 然后,大神请无视,如果作为flutter初学者,可以尝试看看 dependencies:flutter:sdk: flutterdio: ^3 ...

  6. php抖音跳转地址,PHP抖音无水印解析api

    输出标准的格式化了的json格式,ajax直接调用,调用地址/url=抖音地址 主要内容都输出了,status为1输出成功. ps:要网站输出视频必须支持https $url = @$_GET['ur ...

  7. PHP抖音无水印解析api

    输出标准的格式化了的json格式,ajax直接调用,调用地址/url=抖音地址 主要内容都输出了,status为1输出成功. ps:要网站输出视频必须支持https <?php $url = @ ...

  8. 百度SEO抖音无水印解析网站源码

    上传到主机解压 不用安装,直接打开域名就可以了 下载地址: http://www.bytepan.com/ekNSvXgncyt

  9. 抖音无水印解析网站精美源码-无需数据库 安装

    介绍: 上传到主机解压 不用安装,直接打开域名就可以了 网盘下载地址: https://zijiewangpan.com/Gch7wb8f8uP 图片:

  10. Java 抖音无水印解析

    1.直接导入第三方jar <dependency><groupId>commons-httpclient</groupId><artifactId>co ...

最新文章

  1. oracle在日期区间分页查询,Oracle 日期分页
  2. C# Regex(2)
  3. git提交过滤target文件 idea_找不到或无法加载主类(IDEA中启动spring boot项目)
  4. 合并html文件工具,整合 DevTools 和 Chrome
  5. Paper:《Graph Neural Networks: A Review of Methods and Applications》翻译与解读
  6. hdoj-1715-大菲波数(大斐波那契数列)
  7. 技术玩法大升级,网易MCtalk揭秘社交产品背后的秘密
  8. 【vue】安装新版本vue-cli:@vue/cli
  9. Api文档生成工具与Api文档的传播(pdf)
  10. Tomcat 8 安装和配置、优化
  11. python网站模板下载_Python画图模板大全:从此画图不用愁
  12. MySQL入门之扩展匹配符、order by、limit、union、group by、having子句
  13. aspx 修改了样式但是在点击按钮后被刷新_产品经理教程-Axure RP 9 基础操作(元件、布局、草图、样式)...
  14. Golang 并发编程之Context
  15. oracle blob update,Oracle数据库中对BLOB数据的操作问题
  16. 手把手教你用WPE“修改”各种魔兽SF
  17. 关于配置移动硬盘上的Eclipse+mingw+qt4.5.3的问题解决!
  18. 支付宝第三方应用代调用API关系说明
  19. 数字冰雹-智慧监所可视化分析决策系统
  20. 使用QT5书写的护眼程序

热门文章

  1. 小米盒子升级android tv后不能安装第三方软件下载,小米电视,小米盒子无法安装第三方应用,怎么办?...
  2. php发微信模板消息,PHP超简单发送微信模板消息
  3. 动态服务器值 回放报错 没有关联到_LR之关联
  4. 期货反向跟单这个模式、大家目前都耳熟能详,操作原理也算是人尽皆知了!
  5. C# WPF 一个设计界面
  6. 芒果TV广告投放的展现样式!芒果TV广告投放如何收费?
  7. 华为网络篇 传输文件-08
  8. smartsvn.license
  9. Android系统架构
  10. 学校多媒体讲台计算机怎么开,学校教室多媒体使用说明.PPT