很多时候你在douyin里看到了一个短视频,想复制下来自己编辑文字来发布,可是视频里的水印却是原者的。这个时候你想把水印去掉,你要如何做呢?这里提供PHP实现去除水印的主要方法,其实很简单。
在php后加上 ?url= 抖音的url 。
点击跳转后的网页一个是标题 一个是视频无水印的链接。
<?php
header("Content-Type: text/json;charset=utf-8");
$url=$_GET["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); //获取 preg_match('/<p class="desc">(?<desc>[^<>]*)<\/p>/i', $data, $name);
preg_match('/playAddr: "(?<url>[^"]+)"/i', $data, $url); //正则匹配 if (empty($url['url'])) {
echo '请输入正确网址,格式为:https://xxx.com/douyin.php?url=视频地址';
}else{
$array = ['name' => $name['desc'],'url' => $url['url'],];
$json = json_encode($array,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
echo $json;
}
效果截图如下,url就是原视频链接,不带水印。
<?php
header("Content-type: text/html; charset=utf-8");
$url_g=@$_GET['url'];//抖音视频地址 $api="https://api-hl.amemv.com/aweme/v1/aweme/detail/?retry_type=no_retry&iid=43619087057&device_id=57318346369&ac=wifi&channel=update&aid=1128&app_name=aweme&version_code=251&version_name=2.5.1&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&_rticket=1559206461097&ts=1559206460&as=a115996edcf39c7adf4355&cp=9038c058c7f6e4ace1IcQg&mas=01af833c02eb8913ecc7909389749e6d89acaccc2c662686ecc69c&aweme_id=";//6691388713936653576 $cookie="##";//header请求头和cookie,请自己获取(涉及个人隐私,故不放出来),我可以帮你抓取.你也可以直接使用我的接口 [url=https://api.isoyu.com/ckplayer/douyin.jsp?url=]https://api.isoyu.com/ckplayer/douyin.jsp?url=[/url] $user_agent="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"; function getLinkFromDouyinShareText($shareOrUrl){
$url="http".explode("http",$shareOrUrl)[1];
$url=explode("复制此链接,",$url)[0];
return $url;
} function getAwemeId($link,$UA){
$context=stream_context_create(array('http'=>array('header'=>'User-Agent:'.$UA)));
$html_text= file_get_contents($link,0,$context);
$str=explode("itemId: \"",$html_text)[1];
$str=explode("\",",$str)[0];
return $str;
} function doCurlGetRequest($url,$headers,$timeout = 5){
if($url == '' || $timeout <=0){
return false;
}
$con = curl_init((string)$url);
curl_setopt($con, CURLOPT_HEADER, false);
curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
curl_setopt($con,CURLOPT_HTTPHEADER,$headers);
curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout);
return curl_exec($con);
} function getVideoData($api,$cookie,$awemeId){
$header=array("Accept-Encoding: utf-8",
"Cookie: ".$cookie,
"Host: api-hl.amemv.com",
"Connection: Keep-Alive",
"User-Agent: okhttp/3.10.0.1");
$data=json_decode(doCurlGetRequest($api.$awemeId,$header),true);
$info=$data['aweme_detail']['share_info'];//视频描述 $user_name=$data['aweme_detail']['author']['nickname'];//作者昵称 $user_headImg=$data['aweme_detail']['author']['avatar_medium']['url_list'][0];//作者头像 $image=$data['aweme_detail']['video']['origin_cover']['url_list'][0];//封面图片 $urls=$data['aweme_detail']['video']['play_addr']['url_list'];//无水印地址 $music_urls=$data['aweme_detail']['music']['play_url']['url_list'];//音乐地址 $douyin=[
'status'=>true,
'nickname'=>$user_name,
'awemeId'=>$awemeId,
'headImage'=>$user_headImg,
'image'=>$image,
'videoUrl'=>$urls,
'music_urls'=>$music_urls,
'info'=>$info,
'time'=>time()
];
return json_encode($douyin);
} if(strstr($url_g,'http://v.douyin.com/')) {
$url_g = getLinkFromDouyinShareText($url_g);
$awemeId=getAwemeId($url_g,$user_agent);
echo getVideoData($api,$cookie,$awemeId);
}else{
echo json_encode(["status"=>false,"message"=>"地址无效"]);
}
例子:https://api.isoyu.com/ckplayer/douyin.php?url=http://v.douyin.com/rYs9HU
返回:
{ "status":true, "nickname":"陳奕迅所長", "awemeId":"6629588912228535555", "headImage":"https://p9-dy.byteimg.com/aweme/720x720/c7a50016c177b8d83b6e.jpeg", "image":"http://p1-dy.byteimg.com/large/129e100017985e14f90e6.jpeg", "videoUrl":[ "http://v6-dy.ixigua.com/1bfeb00063e024eb6b0a1c5c1ccf461f/5cf72e65/video/m/220f880b47b03d54a789c8caed4897ab5f711610bbb50000474b6680d20e/?rc=anRmbjxrNGxqajMzO2kzM0ApQHRAb0ZHNDUzMzczNDQ1PDg5PDNAKXUpQGczdSlAZjN2KUBmaHV5cTFmc2hoZGY7NEBgY2hnbl5sYy1fLS1fLS9zcy1vI28jMTMwLjEuLy0tLjItLS0uL2k6Yi5wIzphLXEjOmAtbyNwYmZyaF4ranQ6Iy8uXg==", "http://v9-dy.ixigua.com/8a340ec9e22bbe529f779171175d0852/5cf72e65/video/m/220f880b47b03d54a789c8caed4897ab5f711610bbb50000474b6680d20e/", "https://aweme-hl.snssdk.com/aweme/v1/play/?video_id=v0200fb80000bg0gfio1ahq9jkkcfqcg&line=0&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0", "https://api-hl.amemv.com/aweme/v1/play/?video_id=v0200fb80000bg0gfio1ahq9jkkcfqcg&line=1&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0" ], "music_urls":[ "http://p3-dy.byteimg.com/obj/a02a0001f6153c8784e3" ], "info":{ "share_weibo_desc":"#在抖音,记录美好生活##明日之后明日之后 游戏人生,钢琴", "share_desc":"在抖音,记录美好生活", "share_title":"#明日之后明日之后 游戏人生,钢琴", "bool_persist":0, "share_title_myself":"", "share_title_other":"", "share_link_desc":"#在抖音,记录美好生活##明日之后明日之后 游戏人生,钢琴 %s 复制此链接,打开【抖音短视频】,直接观看视频!", "share_url":"https://www.iesdouyin.com/share/video/6629588912228535555/?region=CN&mid=6582505245845392141&u_code=gj49fkd1&titleType=title", "share_quote":"", "share_signature_desc":"TikTok: Make Every Second Count", "share_signature_url":"https://tiktokv.com/" }, "time":1559699531 }
扫码二维码 获取免费视频学习资料
- 本文固定链接: http://phpxs.com/post/6480/
- 转载请注明:转载必须在正文中标注并保留原文链接
- 扫码: 扫上方二维码获取免费视频资料
查 看2022高级编程视频教程免费获取